aboutsummaryrefslogtreecommitdiff
path: root/src/dmtool.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/dmtool.cc')
-rw-r--r--src/dmtool.cc72
1 files changed, 66 insertions, 6 deletions
diff --git a/src/dmtool.cc b/src/dmtool.cc
index 5c322e3..7f2c72c 100644
--- a/src/dmtool.cc
+++ b/src/dmtool.cc
@@ -1,23 +1,26 @@
#include "creature.h"
-#include "feature.h"
+#include "settings.h"
#include <iostream>
+#include <vector>
+#include <string>
+#include <filesystem>
using namespace std;
+namespace fs = std::filesystem;
+
void usage(string exename) {
cout << "Usage:\n";
string indOpt = " " + exename + " ";
string indDesc = " ";
cout << indOpt << "[ls] [subfolder]\n";
cout << indDesc << "List creatures and objects.\n";
- cout << indOpt << "[print] path\n";
- cout << indDesc << "Print existing creature or object.\n";
cout << indOpt << "cp old-path new-path\n";
cout << indDesc << "Copy old-path to new-path.\n";
- cout << indOpt << "rm [--recursive,-r] path\n";
+ cout << indOpt << "rm path\n";
cout << indDesc << "Remove existing creature, object, or directory.\n";
- cout << indOpt << "roll [--advantage,-a] path name\n";
- cout << indDesc << "Roll, optionally with advantage, a skill check, save, or attack.\n";
+ cout << indOpt << "roll path name\n";
+ cout << indDesc << "Roll a skill check, save, or attack.\n";
cout << indOpt << "damage path amount [type]\n";
cout << indDesc << "Damage creature by amount. Type defaults to \"force\".\n";
cout << indOpt << "set path field value\n";
@@ -31,3 +34,60 @@ void usage(string exename) {
cout << indOpt << "help\n";
cout << indDesc << "Show this help.\n";
}
+
+void list(vector<string> args) {
+ string baseDir = settings::getString("savedir");
+ vector<string> listPaths;
+ if(args.empty()) {
+ listPaths.push_back(baseDir);
+ } else {
+ for(auto dir : args) {
+ listPaths.push_back(baseDir + "/" + dir);
+ }
+ }
+ for(auto listPath : listPaths) {
+ if(fs::is_regular_file(fs::status(listPath))) {
+ // Try loading and printing stuff about it
+ creature::Creature c(utils::loadJson(listPath));
+ cout << genText(c);
+ }
+ else if(fs::is_directory(fs::status(listPath))) {
+ for(fs::directory_entry path : filesystem::directory_iterator(listPath)) {
+ cout << path.path().filename().string();
+ if(path.is_directory()) {
+ cout << "/";
+ }
+ cout << "\n";
+ }
+ }
+ }
+}
+
+void cp(vector<string> args) {}
+void rm(vector<string> args) {}
+void roll(vector<string> args) {}
+void damage(vector<string> args) {}
+void set(vector<string> args) {}
+void add(vector<string> args) {}
+
+int main(int argc, char *argv[]) {
+ string exename = argv[0];
+ vector<string> args(&argv[1], &argv[argc]);
+ if(args.empty()) {
+ list(args);
+ return 0;
+ }
+ string cmd = args[0];
+ vector<string> argsOrig(args);
+ args.erase(args.begin());
+ if(cmd == "ls") list(args);
+ else if(cmd == "cp") cp(args);
+ else if(cmd == "rm") rm(args);
+ else if(cmd == "roll") roll(args);
+ else if(cmd == "damage") damage(args);
+ else if(cmd == "set") set(args);
+ else if(cmd == "add") add(args);
+ else if(cmd == "help") usage(exename);
+ else list(argsOrig);
+ return 0;
+}