#include "entry.h" #include "utils.h" #include "features/feature.h" #include "item.h" #include "spell.h" #include "creature.h" #include namespace entry { // 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"] == "creatures") { return utils::loadDFromJson(data); } else if(data["entry"] == "spells") { return utils::loadDFromJson(data); } throw std::invalid_argument("Invalid entry: " + std::string(data["entry"])); } struct entryImpl { std::string entry; std::string name; std::string type; std::string text; }; NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(entryImpl, entry, name, type, text); NLOHMANN_FRIEND_DEFS_BASE(Entry, data); Entry::Entry() : data(new entryImpl()) {} Entry::Entry(const std::string& entry, const std::string& name, const std::string& type, const std::string& text) : data(new entryImpl()) { data->entry = entry; data->name = name; data->type = type; data->text = text; } std::string Entry::getName(void) const {return data->name;} std::string Entry::getType(void) const {return data->type;} std::string Entry::getText(void) const {return data->text;} std::string Entry::getText(const creature::Creature& c) const { return getName() + " (" + getType() + "): " + getText(); } void Entry::setText(const std::string& t) {data->text = t;} }