aboutsummaryrefslogtreecommitdiff
path: root/src/entry.cc
blob: 77cf144174e924b90cfd17a0657f1ad46615dc88 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#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"]));
    }
}