Ensure that initial loading of the config saves the values back to the config file, in order to account for fallback values.feature/data-structs
@@ -33,8 +33,3 @@ if (WIN32) | |||||
"${PROJECT_SOURCE_DIR}/dependencies/SDL2/lib/${PROJECT_ARCH}/SDL2.dll" # <--this is in-file | "${PROJECT_SOURCE_DIR}/dependencies/SDL2/lib/${PROJECT_ARCH}/SDL2.dll" # <--this is in-file | ||||
$<TARGET_FILE_DIR:izanagi>) # <--this is out-file path | $<TARGET_FILE_DIR:izanagi>) # <--this is out-file path | ||||
endif () | endif () | ||||
add_custom_command(TARGET izanagi POST_BUILD | |||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different # which executes "cmake - E copy_if_different..." | |||||
"${PROJECT_SOURCE_DIR}/assets/config.ini" # <--this is in-file | |||||
$<TARGET_FILE_DIR:izanagi>) # <--this is out-file path |
@@ -1,21 +1,21 @@ | |||||
[Video] | |||||
Width=640 | |||||
Height=480 | |||||
[Controls.0.Keyboard] | |||||
Right=Right | |||||
Down=Down | |||||
Left=Left | |||||
Up=Up | |||||
Affirm=Return | |||||
Negate=Backspace | |||||
Action0=A | |||||
Action1=S | |||||
Action2=D | |||||
Action3=F | |||||
Action4=Z | |||||
Action5=X | |||||
Action6=C | |||||
Action7=V | |||||
Action8=W | |||||
Action9=E | |||||
[Video] | |||||
Width=640 | |||||
Height=480 | |||||
[Controls.0.Keyboard] | |||||
Right=Right | |||||
Down=Down | |||||
Left=Left | |||||
Up=Up | |||||
Affirm=Return | |||||
Negate=Backspace | |||||
Action0=A | |||||
Action1=S | |||||
Action2=D | |||||
Action3=F | |||||
Action4=Z | |||||
Action5=X | |||||
Action6=C | |||||
Action7=V | |||||
Action8=W | |||||
Action9=E |
@@ -72,6 +72,24 @@ static void IZ_GetConfigPath(char* config_path) { | |||||
strcat_s(config_path, 128, "config.ini"); | strcat_s(config_path, 128, "config.ini"); | ||||
} | } | ||||
static void IZ_SaveConfig(IZ_Config* config) { | |||||
static 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 (unsigned int p = 0; p < PLAYERS; p += 1) { | |||||
fprintf_s(fp, "[Controls.%u.Keyboard]\n", p); | |||||
for (unsigned int i = 0; i < CONTROLS; i += 1) { | |||||
fprintf_s(fp, "%s=%s\n", ACTION_NAMES[i], SDL_GetKeyName(config->controls[p].keyboard[i])); | |||||
} | |||||
} | |||||
} | |||||
static void IZ_LoadConfig(IZ_Config* config) { | static void IZ_LoadConfig(IZ_Config* config) { | ||||
static char config_path[128]; | static char config_path[128]; | ||||
IZ_GetConfigPath(config_path); | IZ_GetConfigPath(config_path); | ||||
@@ -90,6 +108,7 @@ int main(int argc, char* args[]) { | |||||
SDL_Surface* screen_surface = NULL; | SDL_Surface* screen_surface = NULL; | ||||
IZ_Config config; | IZ_Config config; | ||||
IZ_LoadConfig(&config); | IZ_LoadConfig(&config); | ||||
IZ_SaveConfig(&config); | |||||
if (SDL_Init( | if (SDL_Init( | ||||
SDL_INIT_VIDEO | SDL_INIT_VIDEO | ||||