|
- #include <stdio.h>
- #include <string.h>
- #include <minIni.h>
- #include <SDL_filesystem.h>
- #include <SDL_keyboard.h>
-
- #include "../IZ_action.h"
- #include "IZ_config.h"
-
- void IZ_GetConfigPath(char* config_path) {
- //const char* config_path_dir = SDL_GetPrefPath("Modal Studios", APP_NAME);
- const char* config_path_dir = SDL_GetBasePath();
- memcpy_s(config_path, 128, config_path_dir, 128);
- strcat_s(config_path, 128, "config.ini");
- }
-
- void IZ_SaveConfig(IZ_Config* config) {
- char config_path[128];
- IZ_GetConfigPath(config_path);
- FILE* fp;
- fopen_s(&fp, config_path, "w");
- fprintf_s(fp, "[Video]\n");
- fprintf_s(fp, "Width=%u\n", config->video.width);
- fprintf_s(fp, "Height=%u\n", config->video.height);
- fprintf_s(fp, "\n");
-
- for (uint8_t p = 0; p < PLAYERS; p += 1) {
- fprintf_s(fp, "[Controls.%u.Keyboard]\n", p);
- for (uint8_t i = 0; i < CONTROLS; i += 1) {
- fprintf_s(fp, "%s=%s\n", ACTION_NAMES[i], SDL_GetKeyName(config->controls[p].keyboard[i]));
- }
- }
- }
-
- void IZ_LoadConfig(IZ_Config* config) {
- char config_path[128];
- IZ_GetConfigPath(config_path);
- config->video.width = ini_getl("Video", "Width", 640l, config_path);
- config->video.height = ini_getl("Video", "Height", 480l, config_path);
- char buffer[128];
- char section_name[20] = "Controls.0.Keyboard";
- for (uint8_t i = 0; i < CONTROLS; i += 1) {
- section_name[9] = (char) (48 + i);
- ini_gets(section_name, ACTION_NAMES[i], SDL_GetKeyName(IZ_DEFAULT_KEYBOARD_CONTROLS[i]), buffer, 128, config_path);
- config->controls[0].keyboard[i] = SDL_GetKeyFromName(buffer);
- }
- }
|