blob: 0aad6201c47ac59d7765526936b0ee69c9f0ad9f (
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
|
#include "json.hpp"
#include "item.h"
#include "weapon.h"
#include "armor.h"
#include "utils.h"
#include <iostream>
#include <memory>
using namespace std;
typedef nlohmann::json json;
namespace item {
shared_ptr<Item> Item::create(const json& data) {
auto dataMap = (map<string, json>) data;
if(dataMap.contains("damage")) {
return shared_ptr<Item>(new Weapon(data));
} else if(dataMap.contains("ac")) {
return shared_ptr<Item>(new Armor(data));
}
return shared_ptr<Item>(new Item(data));
}
Item::Item(const json& data) : name(data["name"]), cost(data["cost"]), weight(data["weight"]) {};
//Item::Item(const std::string& name, int cost, double weight) : name(name), cost(cost), weight(weight) {};
Item::~Item() {}
string Item::getName() const {
return name;
}
int Item::getCost() const {
return cost;
}
double Item::getWeight() const {
return weight;
}
json Item::toJson() const {
return json({
{"name", name},
{"cost", cost},
{"weight", weight}
});
}
}
|