#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; } }