diff --git a/libzork/libzork/CMakeLists.txt b/libzork/libzork/CMakeLists.txt index 5b450c6..d6f37a3 100644 --- a/libzork/libzork/CMakeLists.txt +++ b/libzork/libzork/CMakeLists.txt @@ -33,27 +33,3 @@ set_target_properties(zork PROPERTIES CXX_STANDARD 20 zork PROPERTIES CXX_STANDARD_REQUIRED ON zork PROPERTIES CXX_EXTENSIONS OFF) target_compile_options(zork PUBLIC -Wall -Wextra -Werror -pedantic -std=c++20 -Wold-style-cast) - -set(CMAKE_BINARY_DIR build/) - - -# Import yaml-cpp -# 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) -# -# target_link_libraries(zork PUBLIC yaml-cpp::yaml-cpp) - -find_library(YAML_CPP yaml-cpp REQUIRED ) -target_link_libraries(zork PUBLIC yaml-cpp) - - -target_link_options(zork PUBLIC ${YAML_CPP} -Wl,--no-undefined) - diff --git a/libzork/libzork/src/store/store_impl.cc b/libzork/libzork/src/store/store_impl.cc index 3abcb55..6b8f5ab 100644 --- a/libzork/libzork/src/store/store_impl.cc +++ b/libzork/libzork/src/store/store_impl.cc @@ -7,12 +7,13 @@ namespace libzork::store const story::Node* StoreImpl::get_active_node() const { - return active_node_; + throw NotImplemented(); } void StoreImpl::set_active_node(const story::Node* node) { - active_node_ = node; + (void)node; + throw NotImplemented(); } bool StoreImpl::has_variable(const std::string& name) const diff --git a/libzork/libzork/src/store/store_impl.hh b/libzork/libzork/src/store/store_impl.hh index 360a601..b3cffa1 100644 --- a/libzork/libzork/src/store/store_impl.hh +++ b/libzork/libzork/src/store/store_impl.hh @@ -18,9 +18,6 @@ namespace libzork::store int get_variable(const std::string& name) const override; void set_variable(const std::string& name, int value) override; std::map get_inventory() const override; - - private: - const story::Node* active_node_ = nullptr; }; } // namespace libzork::store diff --git a/libzork/libzork/src/story/choice.cc b/libzork/libzork/src/story/choice.cc index 9994c0c..5d50c2a 100644 --- a/libzork/libzork/src/story/choice.cc +++ b/libzork/libzork/src/story/choice.cc @@ -3,10 +3,9 @@ namespace libzork::story { - Choice::Choice( - const Node* node, const std::string& text, - const std::vector>& conditions, - const std::vector>& actions) + Choice::Choice(Node* node, std::string& text, + std::vector>& conditions, + std::vector>& actions) : node_{ node } , text_{ text } { @@ -14,11 +13,11 @@ namespace libzork::story (void)actions; } - const std::string& Choice::get_text() + std::string& Choice::get_text() { return text_; } - const Node* Choice::get_node() + Node* Choice::get_node() { return node_; } diff --git a/libzork/libzork/src/story/choice.hh b/libzork/libzork/src/story/choice.hh index 0646668..30dd9cd 100644 --- a/libzork/libzork/src/story/choice.hh +++ b/libzork/libzork/src/story/choice.hh @@ -12,19 +12,20 @@ namespace libzork::story class Choice { public: - Choice(const Node* node, const std::string& text, - const std::vector>& conditions, - const std::vector>& actions); + Choice() = default; + Choice(Node* node, std::string& text, + std::vector>& conditions, + std::vector>& actions); ~Choice() = default; - const std::string& get_text(); - const Node* get_node(); + std::string& get_text(); + Node* get_node(); private: - const Node* node_; - const std::string text_; - const std::vector> conditions_; - const std::vector> actions_; + Node* node_; + std::string text_; + std::vector> conditions_; + std::vector> actions_; }; } // namespace libzork::story diff --git a/libzork/libzork/src/story/node.cc b/libzork/libzork/src/story/node.cc index dc6b8b6..343834a 100644 --- a/libzork/libzork/src/story/node.cc +++ b/libzork/libzork/src/story/node.cc @@ -1,36 +1,17 @@ -#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) { - 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 }); + (void)name; + (void)script_path; + throw NotImplemented(); } } // namespace libzork::story diff --git a/libzork/libzork/src/story/node_impl.cc b/libzork/libzork/src/story/node_impl.cc index dfec5e4..e216ff3 100644 --- a/libzork/libzork/src/story/node_impl.cc +++ b/libzork/libzork/src/story/node_impl.cc @@ -8,11 +8,6 @@ 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 db7f3a6..de94ae6 100644 --- a/libzork/libzork/src/story/node_impl.hh +++ b/libzork/libzork/src/story/node_impl.hh @@ -15,7 +15,6 @@ 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; @@ -30,8 +29,8 @@ namespace libzork::story std::vector> actions = {}) override; private: - const std::string name_; - const std::string text_; + std::string name_; + std::string text_; std::vector> choices_; }; diff --git a/libzork/libzork/src/story/story.cc b/libzork/libzork/src/story/story.cc index f39b3b4..33b30b4 100644 --- a/libzork/libzork/src/story/story.cc +++ b/libzork/libzork/src/story/story.cc @@ -1,13 +1,6 @@ #include -#include -#include -#include -#include -#include #include "exceptions.hh" -#include "libzork/story/node.hh" -#include "story/node_impl.hh" #include "story/story_impl.hh" namespace libzork::story @@ -15,65 +8,8 @@ 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"); - - 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; - auto stories = story_node["story"]; - for (auto story : stories) - { - // Check fields - 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(); - 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())); - } - - // 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; - } - - return std::make_unique(title, nullptr, nullptr); + (void)path; + throw NotImplemented(); } } // namespace libzork::story diff --git a/libzork/libzork/src/story/story_impl.cc b/libzork/libzork/src/story/story_impl.cc index eca972a..d991c20 100644 --- a/libzork/libzork/src/story/story_impl.cc +++ b/libzork/libzork/src/story/story_impl.cc @@ -4,31 +4,26 @@ namespace libzork::story { - StoryImpl::StoryImpl(const std::string& title, const Node* current_node, - store::Store* store) - : title_{ title } - , current_{ current_node } - , store_{ store } - {} const std::string& StoryImpl::get_title() const { - return title_; + throw NotImplemented(); } const Node* StoryImpl::get_current() const { - return store_->get_active_node(); + throw NotImplemented(); } void StoryImpl::set_current(const Node* node) { - store_->set_active_node(node); + (void)node; + throw NotImplemented(); } const store::Store* StoryImpl::get_store() const { - return store_; + throw NotImplemented(); } 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 9007994..9107452 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 { @@ -10,9 +9,6 @@ namespace libzork::story class StoryImpl : public Story { public: - StoryImpl() = default; - StoryImpl(const std::string& title, const Node* current_node, - store::Store* store); ~StoryImpl() override = default; const std::string& get_title() const override; @@ -20,12 +16,6 @@ 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: - const std::string title_; - const std::vector nodes_; - const Node* current_; - store::Store* store_; }; const StoryImpl& to_impl(const Story& story);