From b129bd00395c14134a56763ea2a87e7ef0edd1e3 Mon Sep 17 00:00:00 2001 From: Guillem George Date: Sat, 28 Feb 2026 15:43:07 +0100 Subject: [PATCH] lebooubou --- libzork/libzork/CMakeLists.txt | 4 +-- libzork/libzork/src/story/story.cc | 43 +++++++++++++++++++++++-- libzork/libzork/src/story/story_impl.cc | 9 +++--- libzork/libzork/src/story/story_impl.hh | 8 +++++ 4 files changed, 55 insertions(+), 9 deletions(-) diff --git a/libzork/libzork/CMakeLists.txt b/libzork/libzork/CMakeLists.txt index 65f00a1..5b450c6 100644 --- a/libzork/libzork/CMakeLists.txt +++ b/libzork/libzork/CMakeLists.txt @@ -51,9 +51,9 @@ set(CMAKE_BINARY_DIR build/) # # target_link_libraries(zork PUBLIC yaml-cpp::yaml-cpp) -find_library(yaml-cpp yaml-cpp) +find_library(YAML_CPP yaml-cpp REQUIRED ) target_link_libraries(zork PUBLIC yaml-cpp) -target_link_options(zork PUBLIC -Wl,--no-undefined) +target_link_options(zork PUBLIC ${YAML_CPP} -Wl,--no-undefined) diff --git a/libzork/libzork/src/story/story.cc b/libzork/libzork/src/story/story.cc index 33b30b4..c96b02d 100644 --- a/libzork/libzork/src/story/story.cc +++ b/libzork/libzork/src/story/story.cc @@ -1,4 +1,7 @@ #include +#include +#include +#include #include "exceptions.hh" #include "story/story_impl.hh" @@ -8,8 +11,44 @@ namespace libzork::story std::unique_ptr make_story(const fs::path& path) { - (void)path; - throw NotImplemented(); + YAML::Node story_node = YAML::LoadFile(path); + + // Check fields + if (!story_node["title"] || !story_node["scripts-path"] + || !story_node["story"]) + return nullptr; + + const std::string title = story_node["title"].as(); + const std::string scripts_path = + story_node["scripts-path"].as(); + + // Stories + auto stories = story_node["story"]; + for (auto story : stories) + { + // Check fields + if (!story["name"] || story["script"] || story["choices"]) + continue; + + const std::string story_name = story["name"].as(); + const std::string story_script_path = + scripts_path + story["script"].as(); + + // Choices + auto story_choices = story["choices"]; + auto choices_list = + std::list>(); + for (auto choice : story_choices) + { + // Check fields + if (!choice["text"] || !choice["target"]) + continue; + choices_list.push_back( + std::make_pair(choice["text"].as(), + choice["target"].as())); + } + } + return nullptr; } } // namespace libzork::story diff --git a/libzork/libzork/src/story/story_impl.cc b/libzork/libzork/src/story/story_impl.cc index d991c20..1a036f7 100644 --- a/libzork/libzork/src/story/story_impl.cc +++ b/libzork/libzork/src/story/story_impl.cc @@ -7,23 +7,22 @@ namespace libzork::story const std::string& StoryImpl::get_title() const { - throw NotImplemented(); + return title_; } const Node* StoryImpl::get_current() const { - throw NotImplemented(); + return current_; } void StoryImpl::set_current(const Node* node) { - (void)node; - throw NotImplemented(); + current_ = node; } const store::Store* StoryImpl::get_store() const { - throw NotImplemented(); + return store_; } std::ostream& StoryImpl::display(std::ostream& os) const diff --git a/libzork/libzork/src/story/story_impl.hh b/libzork/libzork/src/story/story_impl.hh index 9107452..fda5a85 100644 --- a/libzork/libzork/src/story/story_impl.hh +++ b/libzork/libzork/src/story/story_impl.hh @@ -9,6 +9,9 @@ namespace libzork::story class StoryImpl : public Story { public: + StoryImpl() = default; + StoryImpl(std::string& title, const Node* current_node, + const store::Store* store); ~StoryImpl() override = default; const std::string& get_title() const override; @@ -16,6 +19,11 @@ namespace libzork::story void set_current(const Node* node) override; const store::Store* get_store() const override; std::ostream& display(std::ostream& os) const override; + + private: + std::string title_; + const Node* current_; + const store::Store* store_; }; const StoryImpl& to_impl(const Story& story);