blob: 3bb98950e503763de9dea453d670d7d9b12484eb (
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
|
#include "item.h"
#include "weapon.h"
#include "armor.h"
#include "utils.h"
#include <iostream>
#include <memory>
#include <sstream>
#include <nlohmann/json.hpp>
using namespace std;
namespace entry {
shared_ptr<Item> Item::create(const nlohmann::json& data) {
if(data["type"] == "weapons") {
return utils::loadDFromJson<Item, Weapon>(data);
} else if(data["type"] == "armor") {
return utils::loadDFromJson<Item, Armor>(data);
}
return shared_ptr<Item>(new Item(data));
}
string Substantial::getText() const {
stringstream text;
if(getCost() >= 0) {
text << "Cost: ";
string costStr = to_string(getCost()) + " cp";
text << costStr;
string condensedCostStr = utils::getCostString(getCost());
if(costStr != condensedCostStr) {
text << ", i.e., " << condensedCostStr;
}
}
if(getWeight() >= 0) {
text << ". Weight: " << getWeight() << " lbs.";
}
return text.str();
}
}
|