From e044fc4255aa64ef1dbc3d20ed87ed6e2f61a6bd Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 9 May 2021 19:01:59 -0400 Subject: Code refactoring --- src/entry.h | 34 +++++++++++++--------------------- 1 file changed, 13 insertions(+), 21 deletions(-) (limited to 'src/entry.h') 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 #include namespace creature { @@ -8,9 +8,7 @@ namespace creature { } namespace entry { - class Entry; - - class Entry : public Jsonable { + class Entry { public: static std::shared_ptr 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; }; } -- cgit v1.2.3