diff --git a/libzork/libzork/src/story/story.cc b/libzork/libzork/src/story/story.cc index f39b3b4..1dca863 100644 --- a/libzork/libzork/src/story/story.cc +++ b/libzork/libzork/src/story/story.cc @@ -1,12 +1,9 @@ #include #include #include -#include -#include #include #include "exceptions.hh" -#include "libzork/story/node.hh" #include "story/node_impl.hh" #include "story/story_impl.hh" @@ -16,20 +13,17 @@ namespace libzork::story std::unique_ptr make_story(const fs::path& path) { YAML::Node story_node = YAML::LoadFile(path); - if (!story_node) - throw std::runtime_error("Coult not load YAML file"); // Check fields if (!story_node["title"] || !story_node["scripts-path"] || !story_node["story"]) - throw std::runtime_error("Missing fields in YAML file"); + return nullptr; const std::string title = story_node["title"].as(); const std::string scripts_path = story_node["scripts-path"].as(); - // Stories (get nodes) - std::unordered_map> nodes; + // Stories auto stories = story_node["story"]; for (auto story : stories) { @@ -37,21 +31,11 @@ namespace libzork::story if (!story["name"] || story["script"] || story["choices"]) continue; - // Get values const std::string story_name = story["name"].as(); const std::string story_script_path = scripts_path + story["script"].as(); - // Create node - auto n = make_node(story_name, story_script_path); - nodes.emplace(story_name, std::move(n)); - } - - // Stories (get choices) - for (auto story : stories) - { - // Get values - const std::string story_name = story["name"].as(); + // Choices auto story_choices = story["choices"]; auto choices_list = std::list>(); @@ -64,16 +48,12 @@ namespace libzork::story std::make_pair(choice["text"].as(), choice["target"].as())); } - - // TODO add choices - auto it = nodes.find(story_name); - if (it == nodes.end()) - throw std::runtime_error( - "Could not find the story back to add choices"); - NodeImpl n = it.second; } + // auto res = StoryImpl{ title, nullptr, nullptr }; + // return std::unique_ptr(); return std::make_unique(title, nullptr, nullptr); + // return nullptr; } } // namespace libzork::story diff --git a/libzork/libzork/src/story/story_impl.cc b/libzork/libzork/src/story/story_impl.cc index eca972a..ce785b5 100644 --- a/libzork/libzork/src/story/story_impl.cc +++ b/libzork/libzork/src/story/story_impl.cc @@ -5,7 +5,7 @@ namespace libzork::story { StoryImpl::StoryImpl(const std::string& title, const Node* current_node, - store::Store* store) + const store::Store* store) : title_{ title } , current_{ current_node } , store_{ store } @@ -18,12 +18,12 @@ namespace libzork::story const Node* StoryImpl::get_current() const { - return store_->get_active_node(); + return current_; } void StoryImpl::set_current(const Node* node) { - store_->set_active_node(node); + current_ = node; } const store::Store* StoryImpl::get_store() const diff --git a/libzork/libzork/src/story/story_impl.hh b/libzork/libzork/src/story/story_impl.hh index 9007994..e3067f6 100644 --- a/libzork/libzork/src/story/story_impl.hh +++ b/libzork/libzork/src/story/story_impl.hh @@ -2,7 +2,6 @@ #define STORY_IMPL_HH #include -#include namespace libzork::story { @@ -12,7 +11,7 @@ namespace libzork::story public: StoryImpl() = default; StoryImpl(const std::string& title, const Node* current_node, - store::Store* store); + const store::Store* store); ~StoryImpl() override = default; const std::string& get_title() const override; @@ -23,9 +22,8 @@ namespace libzork::story private: const std::string title_; - const std::vector nodes_; const Node* current_; - store::Store* store_; + const store::Store* store_; }; const StoryImpl& to_impl(const Story& story);