diff --git a/src/game/save.cpp b/src/game/save.cpp index 269a282..6501c1c 100644 --- a/src/game/save.cpp +++ b/src/game/save.cpp @@ -19,12 +19,25 @@ #include "game/save.hpp" #include "application.hpp" +#include "debug/logger.hpp" +#include namespace game { -bool save(game::context* ctx) +void save_config(game::context* ctx) { - return false; + const std::string config_file_path = ctx->config_path + "config.json"; + ctx->logger->push_task("Saving config to \"" + config_file_path + "\""); + try + { + std::ofstream config_file(config_file_path); + config_file << *(ctx->config); + } + catch (...) + { + ctx->logger->pop_task(EXIT_FAILURE); + } + ctx->logger->pop_task(EXIT_SUCCESS); } } // namespace game diff --git a/src/game/save.hpp b/src/game/save.hpp index bc7f227..d67b430 100644 --- a/src/game/save.hpp +++ b/src/game/save.hpp @@ -24,7 +24,7 @@ namespace game { -bool save(game::context* ctx); +void save_config(game::context* ctx); } // namespace game diff --git a/src/game/states/language-menu.cpp b/src/game/states/language-menu.cpp index 7563fb8..7129b29 100644 --- a/src/game/states/language-menu.cpp +++ b/src/game/states/language-menu.cpp @@ -24,6 +24,7 @@ #include "render/passes/clear-pass.hpp" #include "debug/logger.hpp" #include "game/fonts.hpp" +#include "game/save.hpp" namespace game { namespace state { @@ -181,6 +182,9 @@ void enter(game::context* ctx) ctx->language_code = (*ctx->string_table)[0][ctx->language_index + 2]; ctx->strings = &ctx->string_table_map[ctx->language_code]; + // Update language in config + (*ctx->config)["language"] = ctx->language_code; + ctx->logger->log("Language changed to \"" + ctx->language_code + "\""); // Reload fonts @@ -271,6 +275,9 @@ void exit(game::context* ctx) } ctx->language_menu_texts.clear(); + // Save config + game::save_config(ctx); + ctx->ui_clear_pass->set_cleared_buffers(false, true, false); }