#include "json.hpp" #include "item.h" #include "weapon.h" #include "armor.h" #include "utils.h" #include #include using namespace std; typedef nlohmann::json json; namespace item { shared_ptr Item::create(const json& data) { auto dataMap = (map) data; if(dataMap.contains("damage")) { return shared_ptr(new Weapon(data)); } else if(dataMap.contains("ac")) { return shared_ptr(new Armor(data)); } return shared_ptr(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} }); } }