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; if (!mppass->length) mppass = &defMppass;
Options_PauseSaving();
Options_Set("launcher-dc-username", user); Options_Set("launcher-dc-username", user);
Options_Set("launcher-dc-ip", &ip); Options_Set("launcher-dc-ip", &ip);
Options_Set("launcher-dc-port", &port); 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 */ /* Save resume info */
if (server->length) { if (server->length) {
Options_PauseSaving();
Options_Set(ROPT_SERVER, server); Options_Set(ROPT_SERVER, server);
Options_Set(ROPT_USER, user); Options_Set(ROPT_USER, user);
Options_Set(ROPT_IP, ip); Options_Set(ROPT_IP, ip);

View File

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

View File

@ -103,6 +103,9 @@ void Options_Load(void);
CC_API void Options_Reload(void); CC_API void Options_Reload(void);
/* Saves options to disc, if any were changed via Options_SetXYZ since last save. */ /* Saves options to disc, if any were changed via Options_SetXYZ since last save. */
CC_API void Options_SaveIfChanged(void); 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. */ /* Sets value to value of option directly in Options.Buffer if found, String_Empty if not. */
/* Returns whether the option was actually found. */ /* Returns whether the option was actually found. */