From cf09e74f030e39c1da1dc1baeb7dd7a55ddbaf57 Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 29 Nov 2023 16:11:08 -0500 Subject: Improved feedback for set command --- src/cmd/cmd_manipulate.cc | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/src/cmd/cmd_manipulate.cc b/src/cmd/cmd_manipulate.cc index e29fd34..48d0341 100644 --- a/src/cmd/cmd_manipulate.cc +++ b/src/cmd/cmd_manipulate.cc @@ -179,6 +179,7 @@ namespace cmd { throw std::runtime_error("Subcommand 'set' requires at least 3 arguments"); } fs::path p = getTruePath(args[0]); + std::stringstream text; args.erase(args.begin()); // remove path from args if(args[0] == "name") { args.erase(args.begin()); // remove "name" from args @@ -187,22 +188,27 @@ namespace cmd { if(e->getEntryType() == "creatures") { // creature, we should do given name instead auto c = utils::instantiate(p); c->setGivenName(newname); + text << "Set the given name of the " << c->getName() << " to " << c->getGivenName() << std::endl; utils::saveJson(c->serialize(), p); } else { // Standard entry, no given name so we set name e->setName(newname); + text << "Set the name of the " << e->getType() << " to " << e->getName() << std::endl; utils::saveJson(e->serialize(), p); } } else if(args[0] == "proficiency") { auto c = utils::instantiate(p); c->setProficiency(utils::parseInt(args[1])); + text << "Set the proficiency of " << c->getGivenName() << " the " << c->getName() << " to " << c->getProficiency() << std::endl; utils::saveJson(c->serialize(), p); } else if(args[0] == "cost") { auto i = utils::instantiate(p); i->setCost(utils::parseInt(args[1])); + text << "Set the cost of the " << i->getType() << " " << i->getName() << " to " << utils::getCostString(i->getCost()) << std::endl; utils::saveJson(i->serialize(), p); } else if(args[0] == "weight") { auto i = utils::instantiate(p); i->setWeight(utils::parseDouble(args[1])); + text << "Set the weight of the " << i->getType() << " " << i->getName() << " to " << i->getWeight() << " lbs" << std::endl; utils::saveJson(i->serialize(), p); } else { auto c = utils::instantiate(p); @@ -216,23 +222,37 @@ namespace cmd { // ensure lower case utils::lower(toSet); int level = -1; - if(toSet == "none") level = 0; - else if(toSet == "proficient") level = 1; - else if(toSet == "expert") level = 2; + if(toSet == "none") { + level = 0; + text << "Removed proficiency in " << skill << " for " << c->getGivenName() << " the " << c->getName() << std::endl; + } else if(toSet == "proficient") { + level = 1; + text << "Granted proficiency in " << skill << " for " << c->getGivenName() << " the " << c->getName() << std::endl; + } else if(toSet == "expert") { + level = 2; + text << "Granted expertise in " << skill << " for " << c->getGivenName() << " the " << c->getName() << std::endl; + } if(level == -1) { throw std::runtime_error("Skill levels can be set to none, proficient, or expert, but " + toSet + " was given."); } c->setProfLevel(skill, level); } else if(ability) { - if(toSet == "proficient") c->setProficientSave(ability); - else if(toSet == "none") c->removeProficientSave(ability); - else c->setScore(ability, utils::parseInt(toSet)); + if(toSet == "proficient") { + c->setProficientSave(ability); + text << "Granted proficiency in " << ability << " saves for " << c->getGivenName() << " the " << c->getName() << std::endl; + } else if(toSet == "none") { + c->removeProficientSave(ability); + text << "Removed proficiency in " << ability << " saves for " << c->getGivenName() << " the " << c->getName() << std::endl; + } else { + c->setScore(ability, utils::parseInt(toSet)); + text << "Set " << ability << " score to " << c->getScore(ability) << " for " << c->getGivenName() << " the " << c->getName() << std::endl; + } } else { throw std::runtime_error("Subcommand 'set' expected an ability, skill, proficiency, or name field to set, but was given " + abilityOrSkill); } utils::saveJson(c->serialize(), p); } - return ""; + return text.str(); } std::string add(std::vector args) { -- cgit v1.2.3