Android/iOS: Options now save immediately after changing instead of after clicking Quit Game, addresses #962

This commit is contained in:
UnknownShadow200 2022-08-21 22:05:11 +10:00
parent dcbd7d8b94
commit 345904244f
4 changed files with 12 additions and 2 deletions

View File

@ -533,6 +533,7 @@ static void DirectConnectScreen_StartClient(void* w) {
}
if (!mppass->length) mppass = &defMppass;
Options_PauseSaving();
Options_Set("launcher-dc-username", user);
Options_Set("launcher-dc-ip", &ip);
Options_Set("launcher-dc-port", &port);

View File

@ -81,6 +81,7 @@ cc_bool Launcher_StartGame(const cc_string* user, const cc_string* mppass, const
/* Save resume info */
if (server->length) {
Options_PauseSaving();
Options_Set(ROPT_SERVER, server);
Options_Set(ROPT_USER, user);
Options_Set(ROPT_IP, ip);

View File

@ -10,6 +10,7 @@
struct StringsBuffer Options;
static struct StringsBuffer changedOpts;
cc_result Options_LoadResult;
static cc_bool savingPaused;
void Options_Free(void) {
StringsBuffer_Clear(&Options);
@ -62,11 +63,15 @@ static void SaveOptions(void) {
}
void Options_SaveIfChanged(void) {
savingPaused = false;
if (!changedOpts.count) return;
Options_Reload();
SaveOptions();
}
void Options_PauseSaving(void) { savingPaused = true; }
cc_bool Options_UNSAFE_Get(const char* keyRaw, cc_string* value) {
int idx;
@ -157,8 +162,8 @@ void Options_SetString(const cc_string* key, const cc_string* value) {
EntryList_Set(&Options, key, value, '=');
}
#ifdef CC_BUILD_WEB
SaveOptions();
#if defined CC_BUILD_WEB || defined CC_BUILD_ANDROID || defined CC_BUILD_IOS
if (!savingPaused) SaveOptions();
#endif
if (HasChanged(key)) return;

View File

@ -103,6 +103,9 @@ void Options_Load(void);
CC_API void Options_Reload(void);
/* Saves options to disc, if any were changed via Options_SetXYZ since last save. */
CC_API void Options_SaveIfChanged(void);
/* Temporarily prevents saving options until Options_SaveIfChanged is called */
/* NOTE: Only makes a difference for web/Android/iOS versions */
void Options_PauseSaving(void);
/* Sets value to value of option directly in Options.Buffer if found, String_Empty if not. */
/* Returns whether the option was actually found. */