aboutsummaryrefslogtreecommitdiff
path: root/src/entry.h
diff options
context:
space:
mode:
authorYour Name <you@example.com>2021-05-09 19:01:59 -0400
committerYour Name <you@example.com>2021-05-09 19:01:59 -0400
commite044fc4255aa64ef1dbc3d20ed87ed6e2f61a6bd (patch)
tree344c09421c5839a764a132fe9166f0e6e3f90e45 /src/entry.h
parentd13358b71ec15085f2638fd9c3fc634df62dfc94 (diff)
downloaddmtool-e044fc4255aa64ef1dbc3d20ed87ed6e2f61a6bd.tar.gz
dmtool-e044fc4255aa64ef1dbc3d20ed87ed6e2f61a6bd.tar.bz2
dmtool-e044fc4255aa64ef1dbc3d20ed87ed6e2f61a6bd.zip
Code refactoring
Diffstat (limited to 'src/entry.h')
-rw-r--r--src/entry.h34
1 files changed, 13 insertions, 21 deletions
diff --git a/src/entry.h b/src/entry.h
index efc402b..56fc884 100644
--- a/src/entry.h
+++ b/src/entry.h
@@ -1,6 +1,6 @@
#pragma once
-#include "json.hpp"
-#include "jsonable.h"
+#include "defines.h"
+#include <nlohmann/json.hpp>
#include <memory>
namespace creature {
@@ -8,9 +8,7 @@ namespace creature {
}
namespace entry {
- class Entry;
-
- class Entry : public Jsonable {
+ class Entry {
public:
static std::shared_ptr<Entry> create(const nlohmann::json& data);
virtual ~Entry() {}
@@ -19,28 +17,22 @@ namespace entry {
std::string getType(void) const {return type;}
virtual std::string getText(void) const {return text;}
void setText(std::string t) {text = t;}
+ virtual void init(void) {}
+ virtual nlohmann::json serialize(void) const {
+ nlohmann::json ret;
+ to_json(ret, *this);
+ return ret;
+ }
virtual std::string getText(const creature::Creature& c) const {
return getName() + " (" + getType() + "): " + getText();
}
- virtual nlohmann::json toJson(void) const {
- return nlohmann::json({
- {"entry", entry},
- {"name", name},
- {"type", type},
- {"text", text}
- });
- }
-
- protected:
- Entry(const nlohmann::json& data) : Entry(data["entry"], data["name"], data["type"], data["text"]) {};
- // Can also be instantiated programmatically
- Entry(const std::string& entry, const std::string& name, const std::string& type, const std::string& text) : entry(entry), name(name), type(type), text(text) {};
+ NLOHMANN_DEFINE_TYPE_INTRUSIVE(Entry, entry, name, type, text);
private:
- const std::string entry;
- const std::string name;
- const std::string type;
+ std::string entry;
+ std::string name;
+ std::string type;
std::string text;
};
}