Browse Source

Add support for saving game config

master
C. J. Howard 2 years ago
parent
commit
19247d220d
3 changed files with 23 additions and 3 deletions
  1. +15
    -2
      src/game/save.cpp
  2. +1
    -1
      src/game/save.hpp
  3. +7
    -0
      src/game/states/language-menu.cpp

+ 15
- 2
src/game/save.cpp View File

@ -19,12 +19,25 @@
#include "game/save.hpp"
#include "application.hpp"
#include "debug/logger.hpp"
#include <fstream>
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

+ 1
- 1
src/game/save.hpp View File

@ -24,7 +24,7 @@
namespace game {
bool save(game::context* ctx);
void save_config(game::context* ctx);
} // namespace game

+ 7
- 0
src/game/states/language-menu.cpp View File

@ -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);
}

Loading…
Cancel
Save