diff --git a/libzork/libzork/src/story/choice.cc b/libzork/libzork/src/story/choice.cc index 766e9d3..5d50c2a 100644 --- a/libzork/libzork/src/story/choice.cc +++ b/libzork/libzork/src/story/choice.cc @@ -1,4 +1,25 @@ #include "story/choice.hh" namespace libzork::story -{} // namespace libzork::story +{ + + Choice::Choice(Node* node, std::string& text, + std::vector>& conditions, + std::vector>& actions) + : node_{ node } + , text_{ text } + { + (void)conditions; + (void)actions; + } + + std::string& Choice::get_text() + { + return text_; + } + Node* Choice::get_node() + { + return node_; + } + +} // namespace libzork::story diff --git a/libzork/libzork/src/story/choice.hh b/libzork/libzork/src/story/choice.hh index 5bf502d..30dd9cd 100644 --- a/libzork/libzork/src/story/choice.hh +++ b/libzork/libzork/src/story/choice.hh @@ -1,11 +1,33 @@ #ifndef CHOICE_HH #define CHOICE_HH +#include +#include +#include +#include + namespace libzork::story { class Choice - {}; + { + public: + Choice() = default; + Choice(Node* node, std::string& text, + std::vector>& conditions, + std::vector>& actions); + ~Choice() = default; + + std::string& get_text(); + Node* get_node(); + + private: + Node* node_; + std::string text_; + std::vector> conditions_; + std::vector> actions_; + }; } // namespace libzork::story + #endif // !CHOICE_HH diff --git a/libzork/libzork/src/story/node_impl.cc b/libzork/libzork/src/story/node_impl.cc index 391871b..e216ff3 100644 --- a/libzork/libzork/src/story/node_impl.cc +++ b/libzork/libzork/src/story/node_impl.cc @@ -1,6 +1,7 @@ #include "story/node_impl.hh" #include +#include #include #include "exceptions.hh" @@ -24,7 +25,7 @@ namespace libzork::story // TODO handle check_conditions - return choices_.at(index); + return choices_.at(index)->get_node(); } std::vector NodeImpl::list_choices(bool check_conditions) const @@ -47,9 +48,8 @@ namespace libzork::story std::vector> conditions, std::vector> actions) { - // TODO handle conditions and actions - (void)conditions; - (void)actions; + choices_.push_back( + std::make_shared(other, text, conditions, actions)); } const NodeImpl& to_impl(const Node& node) diff --git a/libzork/libzork/src/story/node_impl.hh b/libzork/libzork/src/story/node_impl.hh index 46d3496..de94ae6 100644 --- a/libzork/libzork/src/story/node_impl.hh +++ b/libzork/libzork/src/story/node_impl.hh @@ -2,9 +2,12 @@ #define NODE_IMPL_HH #include +#include #include #include +#include "choice.hh" + namespace libzork::story { @@ -28,7 +31,7 @@ namespace libzork::story private: std::string name_; std::string text_; - std::vector choices_; // TODO + std::vector> choices_; }; const NodeImpl& to_impl(const Node& node);