blob: 3691c28d5dd4ade89adc02ce202d749995b1f0f8 (
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
|
#include "json.hpp"
#include "item.h"
#include "weapon.h"
#include "armor.h"
#include "utils.h"
#include <iostream>
#include <memory>
#include <sstream>
using namespace std;
typedef nlohmann::json json;
namespace entry {
shared_ptr<Item> Item::create(const 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 genText(const Substantial& s) {
stringstream text;
if(s.getCost() >= 0) {
text << "Cost: ";
string costStr = to_string(s.getCost()) + " cp";
text << costStr;
string condensedCostStr = utils::getCostString(s.getCost());
if(costStr != condensedCostStr) {
text << ", i.e., " << condensedCostStr;
}
}
if(s.getWeight() >= 0) {
text << ". Weight: " << s.getWeight() << " lbs.";
}
return text.str();
}
}
|