Load default config first, and then overwrite with user config.

This commit is contained in:
Steve 2016-04-16 15:50:23 +01:00
parent efb4cfe52d
commit 97a067cb34
2 changed files with 23 additions and 15 deletions

View File

@ -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();
}

View File

@ -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);
loadConfigFile(configFilename);
}
else
}
static void loadConfigFile(char *filename)
{
text = readFile("data/app/"CONFIG_FILENAME);
}
int i;
cJSON *root, *controlsJSON, *node;
char *text;
text = readFile(filename);
root = cJSON_Parse(text);