diff --git a/src/system/controls.c b/src/system/controls.c index b4a150d..142dfb6 100644 --- a/src/system/controls.c +++ b/src/system/controls.c @@ -60,12 +60,12 @@ void initControlsDisplay(void) strcpy(controlWidget[i]->options[0], ""); strcpy(controlWidget[i]->options[1], ""); - if (app.keyControls[i] != -1) + if (app.keyControls[i] != 0) { sprintf(controlWidget[i]->options[0], "%s", SDL_GetScancodeName(app.keyControls[i])); } - if (app.mouseControls[i] != -1) + if (app.mouseControls[i] != 0) { sprintf(controlWidget[i]->options[1], "Btn %d", app.mouseControls[i]); } @@ -77,7 +77,7 @@ int isControl(int type) int key = app.keyControls[type]; int btn = app.mouseControls[type]; - return ((key != -1 && app.keyboard[key]) || (btn != -1 && app.mouse.button[btn])); + return ((key != 0 && app.keyboard[key]) || (btn != 0 && app.mouse.button[btn])); } int isAcceptControl(void) @@ -90,12 +90,12 @@ void clearControl(int type) int key = app.keyControls[type]; int btn = app.mouseControls[type]; - if (key != -1) + if (key != 0) { app.keyboard[key] = 0; } - if (btn != -1) + if (btn != 0) { app.mouse.button[btn] = 0; } @@ -128,7 +128,7 @@ void clearControlConfig(char *name) i = lookup(name); - app.keyControls[i] = app.mouseControls[i] = -1; + app.keyControls[i] = app.mouseControls[i] = 0; initControlsDisplay(); } diff --git a/src/system/init.c b/src/system/init.c index ebdfe93..4845b4c 100644 --- a/src/system/init.c +++ b/src/system/init.c @@ -21,6 +21,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "init.h" static void loadConfig(void); +static void loadConfigFile(char *filename); void saveConfig(void); static void initColor(SDL_Color *c, int r, int g, int b); static void showLoadingStep(float step, float maxSteps); @@ -203,20 +204,27 @@ static void initColor(SDL_Color *c, int r, int g, int b) static void loadConfig(void) { - int i; - cJSON *root, *controlsJSON, *node; - char *text, *configFilename; - + char *configFilename; + + /* load default config first */ + loadConfigFile("data/app/"CONFIG_FILENAME); + + /* load saved config */ configFilename = getSaveFilePath(CONFIG_FILENAME); if (fileExists(configFilename)) { - text = readFile(configFilename); - } - else - { - text = readFile("data/app/"CONFIG_FILENAME); + loadConfigFile(configFilename); } +} + +static void loadConfigFile(char *filename) +{ + int i; + cJSON *root, *controlsJSON, *node; + char *text; + + text = readFile(filename); root = cJSON_Parse(text);