diff options
author | Your Name <you@example.com> | 2021-05-09 19:01:59 -0400 |
---|---|---|
committer | Your Name <you@example.com> | 2021-05-09 19:01:59 -0400 |
commit | e044fc4255aa64ef1dbc3d20ed87ed6e2f61a6bd (patch) | |
tree | 344c09421c5839a764a132fe9166f0e6e3f90e45 /src/item.cc | |
parent | d13358b71ec15085f2638fd9c3fc634df62dfc94 (diff) | |
download | dmtool-e044fc4255aa64ef1dbc3d20ed87ed6e2f61a6bd.tar.gz dmtool-e044fc4255aa64ef1dbc3d20ed87ed6e2f61a6bd.tar.bz2 dmtool-e044fc4255aa64ef1dbc3d20ed87ed6e2f61a6bd.zip |
Code refactoring
Diffstat (limited to 'src/item.cc')
-rw-r--r-- | src/item.cc | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/src/item.cc b/src/item.cc index 3691c28..3bb9895 100644 --- a/src/item.cc +++ b/src/item.cc @@ -1,4 +1,3 @@ -#include "json.hpp" #include "item.h" #include "weapon.h" #include "armor.h" @@ -6,12 +5,12 @@ #include <iostream> #include <memory> #include <sstream> +#include <nlohmann/json.hpp> using namespace std; -typedef nlohmann::json json; namespace entry { - shared_ptr<Item> Item::create(const json& data) { + shared_ptr<Item> Item::create(const nlohmann::json& data) { if(data["type"] == "weapons") { return utils::loadDFromJson<Item, Weapon>(data); } else if(data["type"] == "armor") { @@ -20,19 +19,19 @@ namespace entry { return shared_ptr<Item>(new Item(data)); } - string genText(const Substantial& s) { + string Substantial::getText() const { stringstream text; - if(s.getCost() >= 0) { + if(getCost() >= 0) { text << "Cost: "; - string costStr = to_string(s.getCost()) + " cp"; + string costStr = to_string(getCost()) + " cp"; text << costStr; - string condensedCostStr = utils::getCostString(s.getCost()); + string condensedCostStr = utils::getCostString(getCost()); if(costStr != condensedCostStr) { text << ", i.e., " << condensedCostStr; } } - if(s.getWeight() >= 0) { - text << ". Weight: " << s.getWeight() << " lbs."; + if(getWeight() >= 0) { + text << ". Weight: " << getWeight() << " lbs."; } return text.str(); } |