diff options
| author | Your Name <you@example.com> | 2022-08-09 16:57:53 -0400 | 
|---|---|---|
| committer | Your Name <you@example.com> | 2022-08-09 16:57:53 -0400 | 
| commit | 5937d893da5656be3f486c863ae54e08bbe66579 (patch) | |
| tree | 15aedaf0753fcf73fe85e90e88a7d0af33036eca /src/item.cc | |
| parent | 947d83c59ea86615e3a81a2ec122d843b5eceee9 (diff) | |
| download | dmtool-5937d893da5656be3f486c863ae54e08bbe66579.tar.gz dmtool-5937d893da5656be3f486c863ae54e08bbe66579.tar.bz2 dmtool-5937d893da5656be3f486c863ae54e08bbe66579.zip | |
Added generic items, worked on features
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(); +    }  } | 
