lebooubou
This commit is contained in:
parent
3a0dddabc9
commit
b129bd0039
4 changed files with 55 additions and 9 deletions
|
|
@ -51,9 +51,9 @@ set(CMAKE_BINARY_DIR build/)
|
||||||
#
|
#
|
||||||
# target_link_libraries(zork PUBLIC yaml-cpp::yaml-cpp)
|
# 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_libraries(zork PUBLIC yaml-cpp)
|
||||||
|
|
||||||
|
|
||||||
target_link_options(zork PUBLIC -Wl,--no-undefined)
|
target_link_options(zork PUBLIC ${YAML_CPP} -Wl,--no-undefined)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,7 @@
|
||||||
#include <libzork/story/story.hh>
|
#include <libzork/story/story.hh>
|
||||||
|
#include <list>
|
||||||
|
#include <utility>
|
||||||
|
#include <yaml-cpp/yaml.h>
|
||||||
|
|
||||||
#include "exceptions.hh"
|
#include "exceptions.hh"
|
||||||
#include "story/story_impl.hh"
|
#include "story/story_impl.hh"
|
||||||
|
|
@ -8,8 +11,44 @@ namespace libzork::story
|
||||||
|
|
||||||
std::unique_ptr<Story> make_story(const fs::path& path)
|
std::unique_ptr<Story> make_story(const fs::path& path)
|
||||||
{
|
{
|
||||||
(void)path;
|
YAML::Node story_node = YAML::LoadFile(path);
|
||||||
throw NotImplemented();
|
|
||||||
|
// Check fields
|
||||||
|
if (!story_node["title"] || !story_node["scripts-path"]
|
||||||
|
|| !story_node["story"])
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
const std::string title = story_node["title"].as<std::string>();
|
||||||
|
const std::string scripts_path =
|
||||||
|
story_node["scripts-path"].as<std::string>();
|
||||||
|
|
||||||
|
// 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<std::string>();
|
||||||
|
const std::string story_script_path =
|
||||||
|
scripts_path + story["script"].as<std::string>();
|
||||||
|
|
||||||
|
// Choices
|
||||||
|
auto story_choices = story["choices"];
|
||||||
|
auto choices_list =
|
||||||
|
std::list<std::pair<const std::string, const std::string>>();
|
||||||
|
for (auto choice : story_choices)
|
||||||
|
{
|
||||||
|
// Check fields
|
||||||
|
if (!choice["text"] || !choice["target"])
|
||||||
|
continue;
|
||||||
|
choices_list.push_back(
|
||||||
|
std::make_pair(choice["text"].as<std::string>(),
|
||||||
|
choice["target"].as<std::string>()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace libzork::story
|
} // namespace libzork::story
|
||||||
|
|
|
||||||
|
|
@ -7,23 +7,22 @@ namespace libzork::story
|
||||||
|
|
||||||
const std::string& StoryImpl::get_title() const
|
const std::string& StoryImpl::get_title() const
|
||||||
{
|
{
|
||||||
throw NotImplemented();
|
return title_;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Node* StoryImpl::get_current() const
|
const Node* StoryImpl::get_current() const
|
||||||
{
|
{
|
||||||
throw NotImplemented();
|
return current_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void StoryImpl::set_current(const Node* node)
|
void StoryImpl::set_current(const Node* node)
|
||||||
{
|
{
|
||||||
(void)node;
|
current_ = node;
|
||||||
throw NotImplemented();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const store::Store* StoryImpl::get_store() const
|
const store::Store* StoryImpl::get_store() const
|
||||||
{
|
{
|
||||||
throw NotImplemented();
|
return store_;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::ostream& StoryImpl::display(std::ostream& os) const
|
std::ostream& StoryImpl::display(std::ostream& os) const
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,9 @@ namespace libzork::story
|
||||||
class StoryImpl : public Story
|
class StoryImpl : public Story
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
StoryImpl() = default;
|
||||||
|
StoryImpl(std::string& title, const Node* current_node,
|
||||||
|
const store::Store* store);
|
||||||
~StoryImpl() override = default;
|
~StoryImpl() override = default;
|
||||||
|
|
||||||
const std::string& get_title() const override;
|
const std::string& get_title() const override;
|
||||||
|
|
@ -16,6 +19,11 @@ namespace libzork::story
|
||||||
void set_current(const Node* node) override;
|
void set_current(const Node* node) override;
|
||||||
const store::Store* get_store() const override;
|
const store::Store* get_store() const override;
|
||||||
std::ostream& display(std::ostream& os) 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);
|
const StoryImpl& to_impl(const Story& story);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue