aboutsummaryrefslogtreecommitdiff
path: root/src/item.cc
diff options
context:
space:
mode:
authorYour Name <you@example.com>2021-04-13 15:14:34 -0400
committerYour Name <you@example.com>2021-04-13 15:14:34 -0400
commit2ab51e507d620c4479e07ca0ec47d22c8c66bc90 (patch)
tree90906ecb043c01034280c767b83a88eb6df6956f /src/item.cc
downloaddmtool-2ab51e507d620c4479e07ca0ec47d22c8c66bc90.tar.gz
dmtool-2ab51e507d620c4479e07ca0ec47d22c8c66bc90.tar.bz2
dmtool-2ab51e507d620c4479e07ca0ec47d22c8c66bc90.zip
Initial commit
Diffstat (limited to 'src/item.cc')
-rw-r--r--src/item.cc48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/item.cc b/src/item.cc
new file mode 100644
index 0000000..0aad620
--- /dev/null
+++ b/src/item.cc
@@ -0,0 +1,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}
+ });
+ }
+}