Files
shweets-sim/src/save.cpp
T

40 lines
983 B
C++

#include "save.h"
#include <SDL3/SDL.h>
#ifdef SDL_PLATFORM_EMSCRIPTEN
#include <emscripten.h>
#endif
constexpr const char* SETTINGS_FILE = "settings.txt";
void file_write(const std::string& path, const std::string& text)
{
SDL_CreateDirectory(path.substr(0, path.find_last_of('/')).c_str());
if (!SDL_SaveFile(path.c_str(), text.data(), text.size()))
SDL_Log("Failed to save %s: %s", path.c_str(), SDL_GetError());
#ifdef SDL_PLATFORM_EMSCRIPTEN
EM_ASM(FS.syncfs(false, () => {}));
#endif
}
void Settings::load()
{
is_fields_read(pref_path_get(SETTINGS_FILE), *this);
}
void Settings::save()
{
file_write(pref_path_get(SETTINGS_FILE), fields_write(*this));
}
// Puts back the defaults of what the settings menu shows.
void Settings::reset()
{
Settings defaults;
color = defaults.color;
measurement = defaults.measurement;
volume = defaults.volume;
isCharacterColor = defaults.isCharacterColor;
isMuted = defaults.isMuted;
}