]> git.localhorst.tv Git - tacos.git/blob - src/app/config.cpp
basic floor idea
[tacos.git] / src / app / config.cpp
1 #include "config.hpp"
2
3 #include <cstring>
4 #include <iostream>
5 #include <SDL.h>
6
7 using namespace std;
8
9
10 namespace tacos {
11
12 Config::Config() {
13         char *base = SDL_GetBasePath();
14         char *pref = SDL_GetPrefPath("localhorst", "tacos");
15
16         asset_path = string(base) + "assets/";
17         config_path = pref;
18
19         SDL_free(base);
20         SDL_free(pref);
21 }
22
23 void Config::ReadArgs(int argc, const char *const *argv) {
24         if (argc < 1) return;
25
26         for (int i = 1; i < argc; ++i) {
27                 const char *arg = argv[i];
28                 if (!arg || arg[0] == '\0') {
29                         cerr << "empty argument at position " << i << endl;
30                         continue;
31                 }
32                 if (arg[0] != '-' || arg[1] != '-' || arg[2] == '\0') {
33                         cerr << "incomplete argument at position " << i << endl;
34                         continue;
35                 }
36                 const char *name = arg + 2;
37                 if (strcmp(name, "asset-path") == 0) {
38                         ++i;
39                         if (i >= argc || !argv[i]) {
40                                 cerr << "missing argument to --asset-path" << endl;
41                                 continue;
42                         }
43                         asset_path = argv[i];
44                 } else if (strcmp(name, "config-path") == 0) {
45                         ++i;
46                         if (i >= argc || !argv[i]) {
47                                 cerr << "missing argument to --config-path" << endl;
48                                 continue;
49                         }
50                         config_path = argv[i];
51                 } else {
52                         cerr << "unknown argument " << arg << " at position " << i << endl;
53                 }
54         }
55 }
56
57 void Config::ReadFile(const char *path) {
58         // TODO: implement reading config file
59 }
60
61 }