aboutsummaryrefslogtreecommitdiff
path: root/src/entry.h
blob: ced854442fa5284b8c7efa49363661dcdb0c82cc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#pragma once
#include "json.hpp"
#include "jsonable.h"
#include <memory>

namespace creature {
    class Creature;
}

namespace entry {
    class Entry;

    // Set up default text generation
    std::string genText(const Entry& e, const creature::Creature& c);
    
    class Entry : public Jsonable {
        public:
            static std::shared_ptr<Entry> create(const nlohmann::json& data);
            virtual ~Entry() {}

            std::string getName(void) const {return name;}
            std::string getType(void) const {return type;}
            virtual std::string getText(void) const {return text;}
            virtual std::string getText(const creature::Creature& c) const {
                //return genText(*this, c);
                return genText(*this, c) + ": " + 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) {};

        private:
            const std::string entry;
            const std::string name;
            const std::string type;
            const std::string text;
    };
}