From d0e356d09e30a11c1e072415a5088f829d5c0a04 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 16 Jan 2022 21:32:01 -0500 Subject: Worked on features --- src/cmd/cmd.cc | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 src/cmd/cmd.cc (limited to 'src/cmd/cmd.cc') diff --git a/src/cmd/cmd.cc b/src/cmd/cmd.cc new file mode 100644 index 0000000..a1fd760 --- /dev/null +++ b/src/cmd/cmd.cc @@ -0,0 +1,54 @@ +#include "cmd.h" +#include "../settings.h" +#include +#include +#include +#include + +namespace cmd { + std::vector getVirtDirs() { + return {"weapons", "armor", "spells", "creatures"}; + } + + // Not idempotent: only do once! + std::filesystem::path getTruePath(std::filesystem::path virtPath) { + std::filesystem::path p; + auto virtPaths = getVirtDirs(); + if(std::find(virtPaths.begin(), virtPaths.end(), *virtPath.begin()) != virtPaths.end()) { + p = settings::getString(*virtPath.begin()); + // Erase root (part to be replaced by virtPaths) + std::filesystem::path tmp; + auto it = virtPath.begin(); + while(++it != virtPath.end()) { + tmp /= *it; + } + virtPath = tmp; + } else { + p = settings::getString("savedir"); + } + p /= virtPath; + if(std::filesystem::directory_entry(p.string() + ".json").is_regular_file()) return p.string() + ".json"; + return p; + } + + std::string formatRoll(std::string name, std::string type, int rolled, int bonus) { + std::stringstream text; + text << name << " " << type << ": " << rolled << " (d20) + " << bonus << " (" << name << " " << type << " bonus) = " << rolled + bonus << std::endl; + return text.str(); + } + + std::vector parseQualifiers(std::map flags) { + std::vector qualifiers; + for(auto flagPair : flags) { + auto flag = flagPair.first; + if(flag == "m" || flag == "magical") { + qualifiers.push_back(rules::Qualifier::Magical()); + } else if(flag == "s" || flag == "silvered") { + qualifiers.push_back(rules::Qualifier::Silvered()); + } else if(flag == "a" || flag == "adamantine") { + qualifiers.push_back(rules::Qualifier::Adamantine()); + } + } + return qualifiers; + } +} -- cgit v1.2.3