From 5937d893da5656be3f486c863ae54e08bbe66579 Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 9 Aug 2022 16:57:53 -0400 Subject: Added generic items, worked on features --- src/item.cc | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'src/item.cc') diff --git a/src/item.cc b/src/item.cc index 5ecdb0c..24498db 100644 --- a/src/item.cc +++ b/src/item.cc @@ -20,10 +20,24 @@ namespace entry { } else if(data["type"] == "armor") { return utils::loadDFromJson(data); } - return shared_ptr(new Item(data)); + return utils::loadDFromJson(data); } - string Substantial::getText() const { + struct itemImpl { + int cost; + double weight; + }; + NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(itemImpl, cost, weight); + + NLOHMANN_FRIEND_DEFS(Entry, Item, data); + + Item::Item() : data(new itemImpl()) {} + + int Item::getCost() const {return data->cost;} + + double Item::getWeight() const {return data->weight;} + + string Item::getCostWeightText() const { stringstream text; if(getCost() >= 0) { text << "Cost: "; @@ -39,4 +53,12 @@ namespace entry { } return text.str(); } + + string Item::getText() const { + return Entry::getText() + " " + getCostWeightText(); + } + + string Item::getText(const creature::Creature& c) const { + return getText(); + } } -- cgit v1.2.3