aboutsummaryrefslogtreecommitdiff
path: root/src/entry.cc
diff options
context:
space:
mode:
authorYour Name <you@example.com>2021-04-29 14:17:08 -0400
committerYour Name <you@example.com>2021-04-29 14:17:08 -0400
commit5a813a75412ac9b8fadb90c9abd46dd95aee8e9b (patch)
tree75c5466d459c793430a6481cd276a624cd843794 /src/entry.cc
parentcd57ad6e208728bafcbc8c7d7b85d88603706978 (diff)
downloaddmtool-5a813a75412ac9b8fadb90c9abd46dd95aee8e9b.tar.gz
dmtool-5a813a75412ac9b8fadb90c9abd46dd95aee8e9b.tar.bz2
dmtool-5a813a75412ac9b8fadb90c9abd46dd95aee8e9b.zip
Removed data files from repo
Diffstat (limited to 'src/entry.cc')
-rw-r--r--src/entry.cc29
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() + ")";
}
}