aboutsummaryrefslogtreecommitdiff
path: root/src/entry.h
diff options
context:
space:
mode:
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;
};
}