aboutsummaryrefslogtreecommitdiff
path: root/src/entry.cc
blob: a3b413394de750977a13d298c2747cbec711b518 (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
#include "entry.h"
#include "utils.h"
#include "feature.h"
#include "item.h"
#include "spell.h"
#include "creature.h"
#include <stdexcept>

namespace entry {
    // 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 genText(const Entry& e, const creature::Creature& c) {
        return e.getName() + " (" + e.getType() + ")";
    }
}