From 3a0dddabc95fb7ff5fbb5af96b5416d53d0bf4a4 Mon Sep 17 00:00:00 2001 From: Guillem George Date: Sat, 28 Feb 2026 14:26:23 +0100 Subject: [PATCH 1/4] fix cmake pour mouli de con --- libzork/libzork/CMakeLists.txt | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/libzork/libzork/CMakeLists.txt b/libzork/libzork/CMakeLists.txt index b61e838..65f00a1 100644 --- a/libzork/libzork/CMakeLists.txt +++ b/libzork/libzork/CMakeLists.txt @@ -38,16 +38,22 @@ set(CMAKE_BINARY_DIR build/) # Import yaml-cpp -include(FetchContent) +# Bon la mouli casse les couilles ENCORE UNE FOIS donc ça ça marche pas +# +# include(FetchContent) -FetchContent_Declare( - yaml-cpp - GIT_REPOSITORY https://github.com/jbeder/yaml-cpp.git - # GIT_TAG -) -FetchContent_MakeAvailable(yaml-cpp) +# FetchContent_Declare( +# yaml-cpp +# GIT_REPOSITORY https://github.com/jbeder/yaml-cpp.git +# # GIT_TAG +# ) +# FetchContent_MakeAvailable(yaml-cpp) +# +# target_link_libraries(zork PUBLIC yaml-cpp::yaml-cpp) + +find_library(yaml-cpp yaml-cpp) +target_link_libraries(zork PUBLIC yaml-cpp) -target_link_libraries(zork PUBLIC yaml-cpp::yaml-cpp) target_link_options(zork PUBLIC -Wl,--no-undefined) From b129bd00395c14134a56763ea2a87e7ef0edd1e3 Mon Sep 17 00:00:00 2001 From: Guillem George Date: Sat, 28 Feb 2026 15:43:07 +0100 Subject: [PATCH 2/4] 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); From 57db392019aeda3105c670b327a5e04da33f7089 Mon Sep 17 00:00:00 2001 From: Guillem George Date: Sat, 28 Feb 2026 16:53:09 +0100 Subject: [PATCH 3/4] yuh --- libzork/libzork/src/story/choice.hh | 1 - libzork/libzork/src/story/node.cc | 25 ++++++++++++++++++++++--- libzork/libzork/src/story/node_impl.cc | 5 +++++ libzork/libzork/src/story/node_impl.hh | 5 +++-- libzork/libzork/src/story/story.cc | 9 +++++++-- libzork/libzork/src/story/story_impl.cc | 6 ++++++ libzork/libzork/src/story/story_impl.hh | 4 ++-- 7 files changed, 45 insertions(+), 10 deletions(-) diff --git a/libzork/libzork/src/story/choice.hh b/libzork/libzork/src/story/choice.hh index f080bf6..0646668 100644 --- a/libzork/libzork/src/story/choice.hh +++ b/libzork/libzork/src/story/choice.hh @@ -12,7 +12,6 @@ namespace libzork::story class Choice { public: - Choice() = default; Choice(const Node* node, const std::string& text, const std::vector>& conditions, const std::vector>& actions); diff --git a/libzork/libzork/src/story/node.cc b/libzork/libzork/src/story/node.cc index 343834a..dc6b8b6 100644 --- a/libzork/libzork/src/story/node.cc +++ b/libzork/libzork/src/story/node.cc @@ -1,17 +1,36 @@ +#include #include +#include +#include #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(in), + std::istreambuf_iterator()); +} + namespace libzork::story { std::unique_ptr 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(a), + std::istreambuf_iterator()); + + return std::make_unique(NodeImpl{ name, text }); } } // namespace libzork::story diff --git a/libzork/libzork/src/story/node_impl.cc b/libzork/libzork/src/story/node_impl.cc index e216ff3..dfec5e4 100644 --- a/libzork/libzork/src/story/node_impl.cc +++ b/libzork/libzork/src/story/node_impl.cc @@ -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_; diff --git a/libzork/libzork/src/story/node_impl.hh b/libzork/libzork/src/story/node_impl.hh index de94ae6..db7f3a6 100644 --- a/libzork/libzork/src/story/node_impl.hh +++ b/libzork/libzork/src/story/node_impl.hh @@ -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> actions = {}) override; private: - std::string name_; - std::string text_; + const std::string name_; + const std::string text_; std::vector> choices_; }; diff --git a/libzork/libzork/src/story/story.cc b/libzork/libzork/src/story/story.cc index c96b02d..1dca863 100644 --- a/libzork/libzork/src/story/story.cc +++ b/libzork/libzork/src/story/story.cc @@ -1,9 +1,10 @@ #include #include -#include +#include #include #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())); } } - return nullptr; + + // 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 1a036f7..ce785b5 100644 --- a/libzork/libzork/src/story/story_impl.cc +++ b/libzork/libzork/src/story/story_impl.cc @@ -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 { diff --git a/libzork/libzork/src/story/story_impl.hh b/libzork/libzork/src/story/story_impl.hh index fda5a85..e3067f6 100644 --- a/libzork/libzork/src/story/story_impl.hh +++ b/libzork/libzork/src/story/story_impl.hh @@ -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_; }; From 2bc2fe035d583612fea58601a299e88189c87a07 Mon Sep 17 00:00:00 2001 From: Guillem George Date: Sat, 28 Feb 2026 18:39:43 +0100 Subject: [PATCH 4/4] ff --- libzork/libzork/src/story/story.cc | 32 ++++++++++++++++++++----- libzork/libzork/src/story/story_impl.cc | 6 ++--- libzork/libzork/src/story/story_impl.hh | 6 +++-- 3 files changed, 33 insertions(+), 11 deletions(-) diff --git a/libzork/libzork/src/story/story.cc b/libzork/libzork/src/story/story.cc index 1dca863..f39b3b4 100644 --- a/libzork/libzork/src/story/story.cc +++ b/libzork/libzork/src/story/story.cc @@ -1,9 +1,12 @@ #include #include #include +#include +#include #include #include "exceptions.hh" +#include "libzork/story/node.hh" #include "story/node_impl.hh" #include "story/story_impl.hh" @@ -13,17 +16,20 @@ 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"]) - return nullptr; + throw std::runtime_error("Missing fields in YAML file"); const std::string title = story_node["title"].as(); const std::string scripts_path = story_node["scripts-path"].as(); - // Stories + // Stories (get nodes) + std::unordered_map> nodes; auto stories = story_node["story"]; for (auto story : stories) { @@ -31,11 +37,21 @@ 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(); - // Choices + // 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(); auto story_choices = story["choices"]; auto choices_list = std::list>(); @@ -48,12 +64,16 @@ 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 ce785b5..eca972a 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, - const store::Store* store) + store::Store* store) : title_{ title } , current_{ current_node } , store_{ store } @@ -18,12 +18,12 @@ namespace libzork::story const Node* StoryImpl::get_current() const { - return current_; + return store_->get_active_node(); } void StoryImpl::set_current(const Node* node) { - current_ = node; + store_->set_active_node(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 e3067f6..9007994 100644 --- a/libzork/libzork/src/story/story_impl.hh +++ b/libzork/libzork/src/story/story_impl.hh @@ -2,6 +2,7 @@ #define STORY_IMPL_HH #include +#include namespace libzork::story { @@ -11,7 +12,7 @@ namespace libzork::story public: StoryImpl() = default; StoryImpl(const std::string& title, const Node* current_node, - const store::Store* store); + store::Store* store); ~StoryImpl() override = default; const std::string& get_title() const override; @@ -22,8 +23,9 @@ namespace libzork::story private: const std::string title_; + const std::vector nodes_; const Node* current_; - const store::Store* store_; + store::Store* store_; }; const StoryImpl& to_impl(const Story& story);