diff options
Diffstat (limited to 'src/item.cc')
-rw-r--r-- | src/item.cc | 26 |
1 files changed, 24 insertions, 2 deletions
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<Item, Armor>(data); } - return shared_ptr<Item>(new Item(data)); + return utils::loadDFromJson<Item, Item>(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(); + } } |