aboutsummaryrefslogtreecommitdiff
path: root/src/cmd.cc
diff options
context:
space:
mode:
authorYour Name <you@example.com>2021-05-06 14:13:28 -0400
committerYour Name <you@example.com>2021-05-06 14:13:28 -0400
commit9f3802690f9dd9452e96d1d7a879291978d66e35 (patch)
tree6d6c17b39abdb9490119241bc4fc061744b46d7d /src/cmd.cc
parent2a9f262e6db5906db445d465e500d7ba8c90fab3 (diff)
downloaddmtool-9f3802690f9dd9452e96d1d7a879291978d66e35.tar.gz
dmtool-9f3802690f9dd9452e96d1d7a879291978d66e35.tar.bz2
dmtool-9f3802690f9dd9452e96d1d7a879291978d66e35.zip
Refactoring
Diffstat (limited to 'src/cmd.cc')
-rw-r--r--src/cmd.cc33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/cmd.cc b/src/cmd.cc
new file mode 100644
index 0000000..7be5e01
--- /dev/null
+++ b/src/cmd.cc
@@ -0,0 +1,33 @@
+#include "cmd.h"
+#include "settings.h"
+#include <vector>
+#include <string>
+#include <filesystem>
+#include <algorithm>
+
+namespace cmd {
+ std::vector<std::string> 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;
+ }
+}