Config versioning to fix the Fullscreen Shortcut debacle (#2966)

* WIP adding new config version.

* Implements a ConfigVersionUpdater

* Updates to account for new LUS-side changes.

* Change `ConfigVersionUpdater` to store `toVersion`

* fix typo
This commit is contained in:
Christopher Leggett 2023-06-12 18:59:23 -04:00 committed by GitHub
parent eba0b4c146
commit 430d5cddf2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 76 additions and 0 deletions

View File

@ -131,6 +131,13 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
set_source_files_properties(soh/OTRGlobals.cpp PROPERTIES COMPILE_FLAGS "/utf-8") set_source_files_properties(soh/OTRGlobals.cpp PROPERTIES COMPILE_FLAGS "/utf-8")
endif() endif()
# soh/config {{{
file(GLOB_RECURSE soh__config RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
"soh/config/*.h"
"soh/config/*.cpp"
)
# }}}
# soh/enhancements {{{ # soh/enhancements {{{
file(GLOB_RECURSE soh__Enhancements RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} file(GLOB_RECURSE soh__Enhancements RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
"soh/Enhancements/*.c" "soh/Enhancements/*.c"
@ -246,6 +253,7 @@ set(ALL_FILES
${Header_Files} ${Header_Files}
${Header_Files__include} ${Header_Files__include}
${soh__} ${soh__}
${soh__config}
${soh__Enhancements} ${soh__Enhancements}
${soh__Extractor} ${soh__Extractor}
${soh__Resource} ${soh__Resource}

View File

@ -110,6 +110,8 @@ CrowdControl* CrowdControl::Instance;
#include "soh/resource/importer/TextFactory.h" #include "soh/resource/importer/TextFactory.h"
#include "soh/resource/importer/BackgroundFactory.h" #include "soh/resource/importer/BackgroundFactory.h"
#include "soh/config/ConfigUpdaters.h"
OTRGlobals* OTRGlobals::Instance; OTRGlobals* OTRGlobals::Instance;
SaveManager* SaveManager::Instance; SaveManager* SaveManager::Instance;
CustomMessageManager* CustomMessageManager::Instance; CustomMessageManager* CustomMessageManager::Instance;
@ -789,6 +791,10 @@ extern "C" void InitOTR() {
CrowdControl::Instance->Disable(); CrowdControl::Instance->Disable();
} }
#endif #endif
std::shared_ptr<LUS::Config> conf = OTRGlobals::Instance->context->GetConfig();
conf->RegisterConfigVersionUpdater(std::make_shared<LUS::ConfigVersion1Updater>());
conf->RunVersionUpdates();
} }
extern "C" void SaveManager_ThreadPoolWait() { extern "C" void SaveManager_ThreadPoolWait() {

View File

@ -0,0 +1,53 @@
#include "ConfigUpdaters.h"
namespace LUS {
ConfigVersion1Updater::ConfigVersion1Updater() : ConfigVersionUpdater(1) {}
void ConfigVersion1Updater::Update(Config* conf) {
if (conf->GetInt("Window.Width", 640) == 640) {
conf->Erase("Window.Width");
}
if (conf->GetInt("Window.Height", 480) == 480) {
conf->Erase("Window.Height");
}
if (conf->GetInt("Window.PositionX", 100) == 100) {
conf->Erase("Window.PositionX");
}
if (conf->GetInt("Window.PositionY", 100) == 100) {
conf->Erase("Window.PositionY");
}
if (conf->GetString("Window.GfxBackend", "") == "") {
conf->Erase("Window.GfxBackend");
}
if (conf->GetString("Window.GfxApi", "") == "") {
conf->Erase("Window.GfxApi");
}
if (conf->GetString("Window.AudioBackend", "") == "") {
conf->Erase("Window.AudioBackend");
}
if (conf->GetBool("Window.Fullscreen.Enabled", false) == false) {
conf->Erase("Window.Fullscreen.Enabled");
}
if (conf->GetInt("Window.Fullscreen.Width", 1920) == 1920) {
conf->Erase("Window.Fullscreen.Width");
}
if (conf->GetInt("Window.Fullscreen.Height", 1080) == 1080) {
conf->Erase("Window.Fullscreen.Height");
}
if (conf->GetInt("Shortcuts.Fullscreen", KbScancode::LUS_KB_F11) == KbScancode::LUS_KB_F10) {
conf->Erase("Shortcuts.Fullscreen");
}
if (conf->GetInt("Shortcuts.Console", KbScancode::LUS_KB_OEM_3) == KbScancode::LUS_KB_OEM_3) {
conf->Erase("Shortcuts.Console");
}
if (conf->GetString("Game.SaveName", "") == "") {
conf->Erase("Game.SaveName");
}
if (conf->GetString("Game.Main Archive", "") == "") {
conf->Erase("Game.Main Archive");
}
if (conf->GetString("Game.Patches Archive", "") == "") {
conf->Erase("Game.Patches Archive");
}
}
}

View File

@ -0,0 +1,9 @@
#include "libultraship/libultraship.h"
namespace LUS {
class ConfigVersion1Updater : public ConfigVersionUpdater {
public:
ConfigVersion1Updater();
void Update(Config* conf);
};
}