]> git.localhorst.tv Git - tacos.git/blobdiff - src/app/config.cpp
basic floor idea
[tacos.git] / src / app / config.cpp
diff --git a/src/app/config.cpp b/src/app/config.cpp
new file mode 100644 (file)
index 0000000..f1e0087
--- /dev/null
@@ -0,0 +1,61 @@
+#include "config.hpp"
+
+#include <cstring>
+#include <iostream>
+#include <SDL.h>
+
+using namespace std;
+
+
+namespace tacos {
+
+Config::Config() {
+       char *base = SDL_GetBasePath();
+       char *pref = SDL_GetPrefPath("localhorst", "tacos");
+
+       asset_path = string(base) + "assets/";
+       config_path = pref;
+
+       SDL_free(base);
+       SDL_free(pref);
+}
+
+void Config::ReadArgs(int argc, const char *const *argv) {
+       if (argc < 1) return;
+
+       for (int i = 1; i < argc; ++i) {
+               const char *arg = argv[i];
+               if (!arg || arg[0] == '\0') {
+                       cerr << "empty argument at position " << i << endl;
+                       continue;
+               }
+               if (arg[0] != '-' || arg[1] != '-' || arg[2] == '\0') {
+                       cerr << "incomplete argument at position " << i << endl;
+                       continue;
+               }
+               const char *name = arg + 2;
+               if (strcmp(name, "asset-path") == 0) {
+                       ++i;
+                       if (i >= argc || !argv[i]) {
+                               cerr << "missing argument to --asset-path" << endl;
+                               continue;
+                       }
+                       asset_path = argv[i];
+               } else if (strcmp(name, "config-path") == 0) {
+                       ++i;
+                       if (i >= argc || !argv[i]) {
+                               cerr << "missing argument to --config-path" << endl;
+                               continue;
+                       }
+                       config_path = argv[i];
+               } else {
+                       cerr << "unknown argument " << arg << " at position " << i << endl;
+               }
+       }
+}
+
+void Config::ReadFile(const char *path) {
+       // TODO: implement reading config file
+}
+
+}