aboutsummaryrefslogtreecommitdiff
path: root/src/entry.cc
blob: ef2ec9669ead9a11044bdfbf9461e38ea70fe8a8 (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"] == "creatures") {
            return utils::loadDFromJson<Entry, creature::Creature>(data);
        } else if(data["entry"] == "spells") {
            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() + ")";
    }
}