node impl
This commit is contained in:
parent
7505bf0f18
commit
50e3c41d27
4 changed files with 53 additions and 7 deletions
|
|
@ -1,4 +1,25 @@
|
||||||
#include "story/choice.hh"
|
#include "story/choice.hh"
|
||||||
|
|
||||||
namespace libzork::story
|
namespace libzork::story
|
||||||
{} // namespace libzork::story
|
{
|
||||||
|
|
||||||
|
Choice::Choice(Node* node, std::string& text,
|
||||||
|
std::vector<std::unique_ptr<vars::Condition>>& conditions,
|
||||||
|
std::vector<std::unique_ptr<vars::Action>>& 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
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,33 @@
|
||||||
#ifndef CHOICE_HH
|
#ifndef CHOICE_HH
|
||||||
#define CHOICE_HH
|
#define CHOICE_HH
|
||||||
|
|
||||||
|
#include <libzork/vars/action.hh>
|
||||||
|
#include <libzork/vars/condition.hh>
|
||||||
|
#include <memory>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
namespace libzork::story
|
namespace libzork::story
|
||||||
{
|
{
|
||||||
|
|
||||||
class Choice
|
class Choice
|
||||||
{};
|
{
|
||||||
|
public:
|
||||||
|
Choice() = default;
|
||||||
|
Choice(Node* node, std::string& text,
|
||||||
|
std::vector<std::unique_ptr<vars::Condition>>& conditions,
|
||||||
|
std::vector<std::unique_ptr<vars::Action>>& actions);
|
||||||
|
~Choice() = default;
|
||||||
|
|
||||||
|
std::string& get_text();
|
||||||
|
Node* get_node();
|
||||||
|
|
||||||
|
private:
|
||||||
|
Node* node_;
|
||||||
|
std::string text_;
|
||||||
|
std::vector<std::unique_ptr<vars::Condition>> conditions_;
|
||||||
|
std::vector<std::unique_ptr<vars::Action>> actions_;
|
||||||
|
};
|
||||||
|
|
||||||
} // namespace libzork::story
|
} // namespace libzork::story
|
||||||
|
|
||||||
#endif // !CHOICE_HH
|
#endif // !CHOICE_HH
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
#include "story/node_impl.hh"
|
#include "story/node_impl.hh"
|
||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "exceptions.hh"
|
#include "exceptions.hh"
|
||||||
|
|
@ -24,7 +25,7 @@ namespace libzork::story
|
||||||
|
|
||||||
// TODO handle check_conditions
|
// TODO handle check_conditions
|
||||||
|
|
||||||
return choices_.at(index);
|
return choices_.at(index)->get_node();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::string> NodeImpl::list_choices(bool check_conditions) const
|
std::vector<std::string> NodeImpl::list_choices(bool check_conditions) const
|
||||||
|
|
@ -47,9 +48,8 @@ namespace libzork::story
|
||||||
std::vector<std::unique_ptr<vars::Condition>> conditions,
|
std::vector<std::unique_ptr<vars::Condition>> conditions,
|
||||||
std::vector<std::unique_ptr<vars::Action>> actions)
|
std::vector<std::unique_ptr<vars::Action>> actions)
|
||||||
{
|
{
|
||||||
// TODO handle conditions and actions
|
choices_.push_back(
|
||||||
(void)conditions;
|
std::make_shared<Choice>(other, text, conditions, actions));
|
||||||
(void)actions;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const NodeImpl& to_impl(const Node& node)
|
const NodeImpl& to_impl(const Node& node)
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,12 @@
|
||||||
#define NODE_IMPL_HH
|
#define NODE_IMPL_HH
|
||||||
|
|
||||||
#include <libzork/story/node.hh>
|
#include <libzork/story/node.hh>
|
||||||
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include "choice.hh"
|
||||||
|
|
||||||
namespace libzork::story
|
namespace libzork::story
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
@ -28,7 +31,7 @@ namespace libzork::story
|
||||||
private:
|
private:
|
||||||
std::string name_;
|
std::string name_;
|
||||||
std::string text_;
|
std::string text_;
|
||||||
std::vector<Choice*> choices_; // TODO
|
std::vector<std::shared_ptr<Choice>> choices_;
|
||||||
};
|
};
|
||||||
|
|
||||||
const NodeImpl& to_impl(const Node& node);
|
const NodeImpl& to_impl(const Node& node);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue