aboutsummaryrefslogtreecommitdiff
path: root/src/item.cc
diff options
context:
space:
mode:
authorYour Name <you@example.com>2021-04-15 15:23:23 -0400
committerYour Name <you@example.com>2021-04-15 15:23:23 -0400
commitdfce4d0398a8bafbb7ad7a31345af181c0269c09 (patch)
tree695162ff8cc25e146f52d9e26fe19ffa9934b3d6 /src/item.cc
parent9034c3d2533177f7cb7a7ce939ec53f7fa63f60e (diff)
downloaddmtool-dfce4d0398a8bafbb7ad7a31345af181c0269c09.tar.gz
dmtool-dfce4d0398a8bafbb7ad7a31345af181c0269c09.tar.bz2
dmtool-dfce4d0398a8bafbb7ad7a31345af181c0269c09.zip
Added spells
Diffstat (limited to 'src/item.cc')
-rw-r--r--src/item.cc36
1 files changed, 5 insertions, 31 deletions
diff --git a/src/item.cc b/src/item.cc
index 0aad620..f602be2 100644
--- a/src/item.cc
+++ b/src/item.cc
@@ -10,39 +10,13 @@ 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));
+ if(data["type"] == "weapon") {
+ return utils::loadDFromJson<Item, Weapon>(data);
+ } else if(data["type"] == "armor") {
+ return utils::loadDFromJson<Item, 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}
- });
- }
}