소스 검색

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
부모
커밋
f3d50bcd99
3개의 변경된 파일40개의 추가작업 그리고 26개의 파일을 삭제
  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 파일 보기

@@ -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 파일 보기

@@ -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 파일 보기

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


불러오는 중...
취소
저장