Example #1
0
void saveConfig(void)
{
	int i;
	char *out, *configFilename;
	cJSON *root, *controlsJSON, *keysJSON, *mouseJSON, *gameplayJSON;

	configFilename = getSaveFilePath(CONFIG_FILENAME);

	SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "Saving config ...");

	root = cJSON_CreateObject();
	cJSON_AddNumberToObject(root, "winWidth", app.winWidth);
	cJSON_AddNumberToObject(root, "winHeight", app.winHeight);
	cJSON_AddNumberToObject(root, "fullscreen", app.fullscreen);
	cJSON_AddNumberToObject(root, "musicVolume", app.musicVolume);
	cJSON_AddNumberToObject(root, "soundVolume", app.soundVolume);

	keysJSON = cJSON_CreateObject();
	for (i = 0 ; i < CONTROL_MAX ; i++)
	{
		cJSON_AddNumberToObject(keysJSON, getLookupName("CONTROL_", i), app.keyControls[i]);
	}

	mouseJSON = cJSON_CreateObject();
	for (i = 0 ; i < CONTROL_MAX ; i++)
	{
		cJSON_AddNumberToObject(mouseJSON, getLookupName("CONTROL_", i), app.mouseControls[i]);
	}

	controlsJSON = cJSON_CreateObject();
	cJSON_AddItemToObject(controlsJSON, "keys", keysJSON);
	cJSON_AddItemToObject(controlsJSON, "mouse", mouseJSON);
	cJSON_AddItemToObject(root, "controls", controlsJSON);
	
	gameplayJSON = cJSON_CreateObject();
	cJSON_AddNumberToObject(gameplayJSON, "friendlyFire", app.gameplay.friendlyFire);
	cJSON_AddNumberToObject(gameplayJSON, "autoSwitchPlayerTarget", app.gameplay.autoSwitchPlayerTarget);
	cJSON_AddNumberToObject(gameplayJSON, "missileReTarget", app.gameplay.missileReTarget);
	cJSON_AddNumberToObject(gameplayJSON, "healthBars", app.gameplay.healthBars);
	cJSON_AddItemToObject(root, "gameplay", gameplayJSON);

	out = cJSON_Print(root);

	if (!writeFile(configFilename, out))
	{
		SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_ERROR, "Failed to save config");
	}

	cJSON_Delete(root);
	free(out);
}
Example #2
0
void initControls(void)
{
    int i;

    controlName[CONTROL_FIRE] = _("Fire");
    controlName[CONTROL_ACCELERATE] = _("Accelerate");
    controlName[CONTROL_BOOST] = _("Boost");
    controlName[CONTROL_ECM] = _("ECM");
    controlName[CONTROL_BRAKE] = _("Brake");
    controlName[CONTROL_TARGET] = _("Select Target");
    controlName[CONTROL_MISSILE] = _("Fire Missile");
    controlName[CONTROL_GUNS] = _("Cycle Guns");
    controlName[CONTROL_RADAR] = _("Cycle Radar");
    controlName[CONTROL_NEXT_FIGHTER] = _("Next Fighter");
    controlName[CONTROL_PREV_FIGHTER] = _("Previous Fighter");
    controlName[CONTROL_SCREENSHOT] = _("Screenshot");

    for (i = 0 ; i < CONTROL_MAX ; i++)
    {
        controlWidget[i] = getWidget(getLookupName("CONTROL_", i), "controls");
        controlWidget[i]->numOptions = 2;
        controlWidget[i]->options = malloc(2 * sizeof(char*));
        controlWidget[i]->options[0] = malloc(sizeof(char) * MAX_NAME_LENGTH);
        controlWidget[i]->options[1] = malloc(sizeof(char) * MAX_NAME_LENGTH);
        strcpy(controlWidget[i]->options[0], "");
        strcpy(controlWidget[i]->options[1], "");
    }

    CONTROLS_TEXT = _("Controls");
    HELP_TEXT = _("Click a control to change it, and then the key or mouse button you want to use.");
    BACKSPACE_TEXT = _("[BACKSPACE] - Clear");
    ESCAPE_TEXT = _("[ESCAPE] - Cancel");
}
Example #3
0
File: load.c Project: nnesse/tbftss
static void loadStats(cJSON *stats)
{
	int i;
	
	for (i = 0 ; i < STAT_MAX ; i++)
	{
		game.stats[i] = cJSON_GetObjectItem(stats, getLookupName("STAT_", i))->valueint;
	}
}
Example #4
0
static void loadStats(cJSON *statsJSON)
{
	int i;
	char *statName;

	for (i = 0 ; i < STAT_MAX ; i++)
	{
		statName = getLookupName("STAT_", i);

		if (statName && cJSON_GetObjectItem(statsJSON, statName))
		{
			game.stats[i] = cJSON_GetObjectItem(statsJSON, statName)->valueint;
		}
	}
}