Load default config first, and then overwrite with user config.
This commit is contained in:
parent
efb4cfe52d
commit
97a067cb34
|
@ -60,12 +60,12 @@ void initControlsDisplay(void)
|
||||||
strcpy(controlWidget[i]->options[0], "");
|
strcpy(controlWidget[i]->options[0], "");
|
||||||
strcpy(controlWidget[i]->options[1], "");
|
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]));
|
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]);
|
sprintf(controlWidget[i]->options[1], "Btn %d", app.mouseControls[i]);
|
||||||
}
|
}
|
||||||
|
@ -77,7 +77,7 @@ int isControl(int type)
|
||||||
int key = app.keyControls[type];
|
int key = app.keyControls[type];
|
||||||
int btn = app.mouseControls[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)
|
int isAcceptControl(void)
|
||||||
|
@ -90,12 +90,12 @@ void clearControl(int type)
|
||||||
int key = app.keyControls[type];
|
int key = app.keyControls[type];
|
||||||
int btn = app.mouseControls[type];
|
int btn = app.mouseControls[type];
|
||||||
|
|
||||||
if (key != -1)
|
if (key != 0)
|
||||||
{
|
{
|
||||||
app.keyboard[key] = 0;
|
app.keyboard[key] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (btn != -1)
|
if (btn != 0)
|
||||||
{
|
{
|
||||||
app.mouse.button[btn] = 0;
|
app.mouse.button[btn] = 0;
|
||||||
}
|
}
|
||||||
|
@ -128,7 +128,7 @@ void clearControlConfig(char *name)
|
||||||
|
|
||||||
i = lookup(name);
|
i = lookup(name);
|
||||||
|
|
||||||
app.keyControls[i] = app.mouseControls[i] = -1;
|
app.keyControls[i] = app.mouseControls[i] = 0;
|
||||||
|
|
||||||
initControlsDisplay();
|
initControlsDisplay();
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
#include "init.h"
|
#include "init.h"
|
||||||
|
|
||||||
static void loadConfig(void);
|
static void loadConfig(void);
|
||||||
|
static void loadConfigFile(char *filename);
|
||||||
void saveConfig(void);
|
void saveConfig(void);
|
||||||
static void initColor(SDL_Color *c, int r, int g, int b);
|
static void initColor(SDL_Color *c, int r, int g, int b);
|
||||||
static void showLoadingStep(float step, float maxSteps);
|
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)
|
static void loadConfig(void)
|
||||||
{
|
{
|
||||||
int i;
|
char *configFilename;
|
||||||
cJSON *root, *controlsJSON, *node;
|
|
||||||
char *text, *configFilename;
|
|
||||||
|
|
||||||
|
/* load default config first */
|
||||||
|
loadConfigFile("data/app/"CONFIG_FILENAME);
|
||||||
|
|
||||||
|
/* load saved config */
|
||||||
configFilename = getSaveFilePath(CONFIG_FILENAME);
|
configFilename = getSaveFilePath(CONFIG_FILENAME);
|
||||||
|
|
||||||
if (fileExists(configFilename))
|
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);
|
root = cJSON_Parse(text);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue