aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYour Name <you@example.com>2023-11-29 16:11:08 -0500
committerYour Name <you@example.com>2023-11-29 16:11:08 -0500
commitcf09e74f030e39c1da1dc1baeb7dd7a55ddbaf57 (patch)
treebf92a4eaa4d3a756f2b3a8979efd2f70f45b5ea5
parentdf1219af270712f8473fd5fe75d4e54dd1785750 (diff)
downloaddmtool-master.tar.gz
dmtool-master.tar.bz2
dmtool-master.zip
Improved feedback for set commandHEADmaster
-rw-r--r--src/cmd/cmd_manipulate.cc34
1 files 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<creature::Creature>(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<creature::Creature>(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<entry::Item>(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<entry::Item>(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<creature::Creature>(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<std::string> args) {