From e044fc4255aa64ef1dbc3d20ed87ed6e2f61a6bd Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 9 May 2021 19:01:59 -0400 Subject: Code refactoring --- src/item.cc | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'src/item.cc') 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 #include #include +#include using namespace std; -typedef nlohmann::json json; namespace entry { - shared_ptr Item::create(const json& data) { + shared_ptr Item::create(const nlohmann::json& data) { if(data["type"] == "weapons") { return utils::loadDFromJson(data); } else if(data["type"] == "armor") { @@ -20,19 +19,19 @@ namespace entry { return shared_ptr(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(); } -- cgit v1.2.3