From 5a813a75412ac9b8fadb90c9abd46dd95aee8e9b Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 29 Apr 2021 14:17:08 -0400 Subject: Removed data files from repo --- src/entry.cc | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) (limited to 'src/entry.cc') diff --git a/src/entry.cc b/src/entry.cc index b6431f0..a3b4133 100644 --- a/src/entry.cc +++ b/src/entry.cc @@ -1,15 +1,28 @@ #include "entry.h" - -namespace creature { - class Creature; -} +#include "utils.h" +#include "feature.h" +#include "item.h" +#include "spell.h" +#include "creature.h" +#include namespace entry { - std::string genText(const Entry& e, const creature::Creature& c) { - return e.getName() + " (" + e.getType() + ")"; + // Returns either a feature, an item, a creature, or a spell + std::shared_ptr Entry::create(const nlohmann::json& data) { + if(data["entry"] == "feature") { + return Feature::create(data); + } else if(data["entry"] == "item") { + return Item::create(data); + } else if(data["entry"] == "creature") { + return utils::loadDFromJson(data); + } else if(data["entry"] == "spell") { + return utils::loadDFromJson(data); + } + throw std::invalid_argument("Invalid entry: " + std::string(data["entry"])); } - std::string Entry::getText(const creature::Creature& c) const { - return genText(*this, c); + + std::string genText(const Entry& e, const creature::Creature& c) { + return e.getName() + " (" + e.getType() + ")"; } } -- cgit v1.2.3