yuh
This commit is contained in:
parent
b129bd0039
commit
57db392019
7 changed files with 45 additions and 10 deletions
|
|
@ -12,7 +12,6 @@ namespace libzork::story
|
|||
class Choice
|
||||
{
|
||||
public:
|
||||
Choice() = default;
|
||||
Choice(const Node* node, const std::string& text,
|
||||
const std::vector<std::unique_ptr<vars::Condition>>& conditions,
|
||||
const std::vector<std::unique_ptr<vars::Action>>& actions);
|
||||
|
|
|
|||
|
|
@ -1,17 +1,36 @@
|
|||
#include <fstream>
|
||||
#include <libzork/story/node.hh>
|
||||
#include <memory>
|
||||
#include <stdexcept>
|
||||
|
||||
#include "exceptions.hh"
|
||||
#include "story/node_impl.hh"
|
||||
|
||||
std::string readFile(const std::string& path)
|
||||
{
|
||||
std::ifstream in(path, std::ios::binary);
|
||||
if (!in)
|
||||
throw std::runtime_error("cannot open file");
|
||||
return std::string(std::istreambuf_iterator<char>(in),
|
||||
std::istreambuf_iterator<char>());
|
||||
}
|
||||
|
||||
namespace libzork::story
|
||||
{
|
||||
|
||||
std::unique_ptr<Node> make_node(const std::string& name,
|
||||
const fs::path& script_path)
|
||||
{
|
||||
(void)name;
|
||||
(void)script_path;
|
||||
throw NotImplemented();
|
||||
std::ifstream a;
|
||||
a.open(script_path);
|
||||
if (!a.is_open())
|
||||
throw std::runtime_error(
|
||||
std::string("Could not open script: ").append(script_path));
|
||||
|
||||
std::string text = std::string(std::istreambuf_iterator<char>(a),
|
||||
std::istreambuf_iterator<char>());
|
||||
|
||||
return std::make_unique<NodeImpl>(NodeImpl{ name, text });
|
||||
}
|
||||
|
||||
} // namespace libzork::story
|
||||
|
|
|
|||
|
|
@ -8,6 +8,11 @@
|
|||
|
||||
namespace libzork::story
|
||||
{
|
||||
NodeImpl::NodeImpl(const std::string& name, const std::string& text)
|
||||
: name_{ name }
|
||||
, text_{ text }
|
||||
{}
|
||||
|
||||
const std::string& NodeImpl::get_name() const
|
||||
{
|
||||
return name_;
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ namespace libzork::story
|
|||
{
|
||||
public:
|
||||
~NodeImpl() override = default;
|
||||
NodeImpl(const std::string& name, const std::string& text);
|
||||
|
||||
const std::string& get_name() const override;
|
||||
const std::string& get_text() const override;
|
||||
|
|
@ -29,8 +30,8 @@ namespace libzork::story
|
|||
std::vector<std::unique_ptr<vars::Action>> actions = {}) override;
|
||||
|
||||
private:
|
||||
std::string name_;
|
||||
std::string text_;
|
||||
const std::string name_;
|
||||
const std::string text_;
|
||||
std::vector<std::shared_ptr<Choice>> choices_;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
#include <libzork/story/story.hh>
|
||||
#include <list>
|
||||
#include <utility>
|
||||
#include <memory>
|
||||
#include <yaml-cpp/yaml.h>
|
||||
|
||||
#include "exceptions.hh"
|
||||
#include "story/node_impl.hh"
|
||||
#include "story/story_impl.hh"
|
||||
|
||||
namespace libzork::story
|
||||
|
|
@ -48,7 +49,11 @@ namespace libzork::story
|
|||
choice["target"].as<std::string>()));
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
|
||||
// auto res = StoryImpl{ title, nullptr, nullptr };
|
||||
// return std::unique_ptr<StoryImpl>();
|
||||
return std::make_unique<StoryImpl>(title, nullptr, nullptr);
|
||||
// return nullptr;
|
||||
}
|
||||
|
||||
} // namespace libzork::story
|
||||
|
|
|
|||
|
|
@ -4,6 +4,12 @@
|
|||
|
||||
namespace libzork::story
|
||||
{
|
||||
StoryImpl::StoryImpl(const std::string& title, const Node* current_node,
|
||||
const store::Store* store)
|
||||
: title_{ title }
|
||||
, current_{ current_node }
|
||||
, store_{ store }
|
||||
{}
|
||||
|
||||
const std::string& StoryImpl::get_title() const
|
||||
{
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ namespace libzork::story
|
|||
{
|
||||
public:
|
||||
StoryImpl() = default;
|
||||
StoryImpl(std::string& title, const Node* current_node,
|
||||
StoryImpl(const std::string& title, const Node* current_node,
|
||||
const store::Store* store);
|
||||
~StoryImpl() override = default;
|
||||
|
||||
|
|
@ -21,7 +21,7 @@ namespace libzork::story
|
|||
std::ostream& display(std::ostream& os) const override;
|
||||
|
||||
private:
|
||||
std::string title_;
|
||||
const std::string title_;
|
||||
const Node* current_;
|
||||
const store::Store* store_;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue