Procházet zdrojové kódy

Save config upon loading

Ensure that initial loading of the config saves the values back to the
config file, in order to account for fallback values.
master
TheoryOfNekomata před 2 roky
rodič
revize
f3d50bcd99
3 změnil soubory, kde provedl 40 přidání a 26 odebrání
  1. +0
    -5
      CMakeLists.txt
  2. +21
    -21
      docs/reference/files/config.ini
  3. +19
    -0
      src/packages/game/main.c

+ 0
- 5
CMakeLists.txt Zobrazit soubor

@@ -33,8 +33,3 @@ if (WIN32)
"${PROJECT_SOURCE_DIR}/dependencies/SDL2/lib/${PROJECT_ARCH}/SDL2.dll" # <--this is in-file
$<TARGET_FILE_DIR:izanagi>) # <--this is out-file path
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

assets/config.ini → docs/reference/files/config.ini Zobrazit soubor

@@ -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

+ 19
- 0
src/packages/game/main.c Zobrazit soubor

@@ -72,6 +72,24 @@ static void IZ_GetConfigPath(char* config_path) {
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 char config_path[128];
IZ_GetConfigPath(config_path);
@@ -90,6 +108,7 @@ int main(int argc, char* args[]) {
SDL_Surface* screen_surface = NULL;
IZ_Config config;
IZ_LoadConfig(&config);
IZ_SaveConfig(&config);

if (SDL_Init(
SDL_INIT_VIDEO


Načítá se…
Zrušit
Uložit