From 3f78a7e1647ba94129236bd2bf4fc855c109628a Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 3 Jan 2022 16:25:45 -0500 Subject: Added command to force a saving throw --- src/dmtool.cc | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'src/dmtool.cc') diff --git a/src/dmtool.cc b/src/dmtool.cc index e84630b..6ae096f 100644 --- a/src/dmtool.cc +++ b/src/dmtool.cc @@ -24,16 +24,23 @@ void checkArgs(std::string cmd, std::vector args) { } } -// Removes flags from args (in-place) and returns vector of flags -std::vector extractFlags(std::vector& args) { - std::vector ret; +// Removes flags from args (in-place) and returns map of options +std::map extractFlags(std::vector& args, const std::vector& knownOptions = {}) { + std::map ret; auto it = args.begin(); while(it != args.end()) { if((*it)[0] == '-') { while((*it)[0] == '-') { (*it).erase((*it).begin()); } - ret.push_back(*it); + if(it < args.end()-1) { + ret.emplace(*it, *(it+1)); + if(std::find(knownOptions.begin(), knownOptions.end(), *it) != knownOptions.end()) { + args.erase(it); + } + } else { + ret.emplace(*it, std::string()); + } args.erase(it); } else { it++; @@ -43,12 +50,12 @@ std::vector extractFlags(std::vector& args) { } int main(int argc, char *argv[]) { - // Full thing is surrounded in try/catch to pleasantly print out any errors + // Full thing is surrounded in try/catch to plesantly print out any errors try { std::string exename = argv[0]; std::vector args(&argv[1], &argv[argc]); auto argsWithFlags = args; - std::vector flags = extractFlags(args); + auto flags = extractFlags(args); cmd::mkdir({cmd::getTruePath("")}); if(args.empty()) { std::cout << cmd::list(args); @@ -68,6 +75,12 @@ int main(int argc, char *argv[]) { else if(cmd == "attack") std::cout << cmd::attack(args, flags); else if(cmd == "damage") std::cout << cmd::damage(args, flags); else if(cmd == "heal") std::cout << cmd::heal(args); + else if(cmd == "save") { + args = argsWithFlags; + extractFlags(args, {"damage", "type"}); + args.erase(args.begin()); + std::cout << cmd::save(args, flags); + } else if(cmd == "reset") std::cout << cmd::reset(args); else if(cmd == "set") std::cout << cmd::set(args); else if(cmd == "add") std::cout << cmd::add(args); -- cgit v1.2.3