diff options
Diffstat (limited to 'src/entry.cc')
-rw-r--r-- | src/entry.cc | 29 |
1 files changed, 21 insertions, 8 deletions
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 <stdexcept> 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> 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<Entry, creature::Creature>(data); + } else if(data["entry"] == "spell") { + return utils::loadDFromJson<Entry, Spell>(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() + ")"; } } |