Browse Source

More set commands implemented

Thomas Buck 10 years ago
parent
commit
73135ebc12
3 changed files with 30 additions and 6 deletions
  1. 2
    0
      include/utils/strings.h
  2. 16
    6
      src/OpenRaider.cpp
  3. 12
    0
      src/utils/strings.cpp

+ 2
- 0
include/utils/strings.h View File

@@ -14,6 +14,8 @@
14 14
 
15 15
 void printStringVector(std::vector<char *> *args);
16 16
 
17
+int readBool(const char *value, bool *var);
18
+
17 19
 /*!
18 20
  * \brief Check if a string ends with another string.
19 21
  * \param str string to check

+ 16
- 6
src/OpenRaider.cpp View File

@@ -128,17 +128,27 @@ int OpenRaider::set(const char *var, const char *value) {
128 128
         }
129 129
         mWindow->setSize(w, h);
130 130
     } else if (strcmp(var, "fullscreen") == 0) {
131
-
131
+        bool fullscreen = false;
132
+        if (readBool(value, &fullscreen) != 0) {
133
+            printf("set-fullscreen-Error: Invalid value (%s)\n", value);
134
+            return -3;
135
+        }
136
+        mWindow->setFullscreen(fullscreen);
132 137
     } else if (strcmp(var, "gldriver") == 0) {
133
-
138
+        mWindow->setDriver(value);
134 139
     } else if (strcmp(var, "audio") == 0) {
135
-
140
+        bool audio = false;
141
+        if (readBool(value, &audio) != 0) {
142
+            printf("set-audio-Error: Invalid value (%s)\n", value);
143
+            return -4;
144
+        }
145
+        // TODO enable audio
136 146
     } else if (strcmp(var, "volume") == 0) {
137
-
147
+        // TODO set volume
138 148
     } else if (strcmp(var, "mouse_x") == 0) {
139
-
149
+        // TODO set
140 150
     } else if (strcmp(var, "mouse_y") == 0) {
141
-
151
+        // TODO set
142 152
     } else if (strcmp(var, "basedir") == 0) {
143 153
 
144 154
     } else if (strcmp(var, "pakdir") == 0) {

+ 12
- 0
src/utils/strings.cpp View File

@@ -27,6 +27,18 @@ void printStringVector(std::vector<char *> *args) {
27 27
     printf(")");
28 28
 }
29 29
 
30
+int readBool(const char *value, bool *var) {
31
+    if ((strcmp(value, "1") == 0) || (strcmp(value, "true") == 0) || (strcmp(value, "TRUE") == 0)) {
32
+        *var = true;
33
+    } else if ((strcmp(value, "0") == 0) || (strcmp(value, "false") == 0) || (strcmp(value, "FALSE") == 0)) {
34
+        *var = false;
35
+    } else {
36
+        return -1;
37
+    }
38
+
39
+    return 0;
40
+}
41
+
30 42
 bool stringEndsWith(const char *str, const char *suffix) {
31 43
     assert(str != NULL);
32 44
     assert(suffix != NULL);

Loading…
Cancel
Save