blob: 7029f0c9365cbae66a33f663c87fd7597a77fa64 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
#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;
}
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();
}
}
|