mirror of
https://github.com/HarbourMasters/Shipwright
synced 2026-10-13 07:25:54 -04:00
Add migrations for presets and drag-and-drops (#7312)
This commit is contained in:
@@ -56,5 +56,6 @@
|
||||
}
|
||||
},
|
||||
"presetName": "Enhancements - Curated First Time Vanilla",
|
||||
"isBuiltIn": true
|
||||
"isBuiltIn": true,
|
||||
"ConfigVersion": 7
|
||||
}
|
||||
|
||||
@@ -137,5 +137,6 @@
|
||||
}
|
||||
},
|
||||
"presetName": "Enhancements - Curated Randomizer",
|
||||
"isBuiltIn": true
|
||||
"isBuiltIn": true,
|
||||
"ConfigVersion": 7
|
||||
}
|
||||
|
||||
@@ -59,5 +59,6 @@
|
||||
}
|
||||
},
|
||||
"presetName": "Enhancements - Curated Returning Vanilla",
|
||||
"isBuiltIn": true
|
||||
"isBuiltIn": true,
|
||||
"ConfigVersion": 7
|
||||
}
|
||||
|
||||
@@ -7,5 +7,6 @@
|
||||
}
|
||||
},
|
||||
"presetName": "Enhancements - Reset to Default",
|
||||
"isBuiltIn": true
|
||||
"isBuiltIn": true,
|
||||
"ConfigVersion": 7
|
||||
}
|
||||
|
||||
@@ -65,5 +65,6 @@
|
||||
}
|
||||
},
|
||||
"presetName": "Rando Seed Settings - Advanced",
|
||||
"isBuiltIn": true
|
||||
"isBuiltIn": true,
|
||||
"ConfigVersion": 7
|
||||
}
|
||||
|
||||
@@ -48,5 +48,6 @@
|
||||
}
|
||||
},
|
||||
"presetName": "Rando Seed Settings - Beginner",
|
||||
"isBuiltIn": true
|
||||
"isBuiltIn": true,
|
||||
"ConfigVersion": 7
|
||||
}
|
||||
|
||||
@@ -138,5 +138,6 @@
|
||||
}
|
||||
},
|
||||
"presetName": "Rando Seed Settings - Demise Difficulty",
|
||||
"isBuiltIn": true
|
||||
"isBuiltIn": true,
|
||||
"ConfigVersion": 7
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
"MixThievesHideout": 1,
|
||||
"MixedEntrances": 1,
|
||||
"ProgressiveGoronSword": 1,
|
||||
"RainbowBridge": 9,
|
||||
"RainbowBridge": 8,
|
||||
"ScrubsPrices": 2,
|
||||
"ShopShieldsTunicsGate": 1,
|
||||
"Shopsanity": 1,
|
||||
@@ -114,5 +114,6 @@
|
||||
}
|
||||
},
|
||||
"presetName": "Rando Seed Settings - Hell Mode",
|
||||
"isBuiltIn": true
|
||||
"isBuiltIn": true,
|
||||
"ConfigVersion": 7
|
||||
}
|
||||
|
||||
@@ -5,5 +5,6 @@
|
||||
}
|
||||
},
|
||||
"presetName": "Rando Seed Settings - Reset to Default",
|
||||
"isBuiltIn": true
|
||||
"isBuiltIn": true,
|
||||
"ConfigVersion": 7
|
||||
}
|
||||
|
||||
@@ -59,5 +59,6 @@
|
||||
}
|
||||
},
|
||||
"presetName": "Rando Seed Settings - Standard",
|
||||
"isBuiltIn": true
|
||||
"isBuiltIn": true,
|
||||
"ConfigVersion": 7
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include "soh/Enhancements/randomizer/randomizer_item_tracker.h"
|
||||
#include "soh/Enhancements/randomizer/settings.h"
|
||||
#include "soh/ShipInit.hpp"
|
||||
#include "soh/config/ConfigUpdaters.h"
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
@@ -107,6 +108,7 @@ std::string FormatPresetPath(std::string name) {
|
||||
|
||||
void applyPreset(std::string presetName, std::vector<PresetSection> includeSections) {
|
||||
auto& info = presets[presetName];
|
||||
bool randoApplied = false;
|
||||
for (int i = PRESET_SECTION_SETTINGS; i < PRESET_SECTION_MAX; i++) {
|
||||
if (info.apply[i] && info.presetValues["blocks"].contains(blockInfo[i].names[1])) {
|
||||
if (!includeSections.empty() && !SohUtils::Contains(i, includeSections)) {
|
||||
@@ -150,12 +152,22 @@ void applyPreset(std::string presetName, std::vector<PresetSection> includeSecti
|
||||
}
|
||||
}
|
||||
if (i == PRESET_SECTION_RANDOMIZER) {
|
||||
Rando::Settings::GetInstance()->UpdateAllOptions();
|
||||
SohGui::UpdateMenuTricks();
|
||||
SohGui::UpdateMenuLocations();
|
||||
randoApplied = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (randoApplied) {
|
||||
// Unversioned presets predate v4. Only migrate when rando came from the preset
|
||||
uint32_t presetVersion = SOH::GetConfigVersion(info.presetValues, 3);
|
||||
if (presetVersion < SOH::GetLatestConfigVersion()) {
|
||||
SOH::RunVersionUpdatesFrom(presetVersion);
|
||||
// SetBlock already saved the unmigrated values
|
||||
Ship::Context::GetRawInstance()->GetWindow()->GetGui()->SaveConsoleVariablesNextFrame();
|
||||
}
|
||||
Rando::Settings::GetInstance()->UpdateAllOptions();
|
||||
SohGui::UpdateMenuTricks();
|
||||
SohGui::UpdateMenuLocations();
|
||||
}
|
||||
ShipInit::InitAll();
|
||||
OTRGlobals::Instance->ScaleImGui();
|
||||
}
|
||||
@@ -284,6 +296,7 @@ void SavePreset(std::string& presetName) {
|
||||
}
|
||||
presets[presetName].presetValues["presetName"] = presetName;
|
||||
presets[presetName].presetValues["fileType"] = FILE_TYPE_PRESET;
|
||||
presets[presetName].presetValues["ConfigVersion"] = SOH::GetLatestConfigVersion();
|
||||
|
||||
std::ofstream file(FormatPresetPath(presetName));
|
||||
if (!file.is_open()) {
|
||||
|
||||
@@ -1532,13 +1532,7 @@ extern "C" void InitOTR(int argc, char* argv[]) {
|
||||
SaveManager::Instance = new SaveManager();
|
||||
|
||||
std::shared_ptr<Ship::Config> conf = OTRGlobals::Instance->context->GetConfig();
|
||||
conf->RegisterVersionUpdater(std::make_shared<SOH::ConfigVersion1Updater>());
|
||||
conf->RegisterVersionUpdater(std::make_shared<SOH::ConfigVersion2Updater>());
|
||||
conf->RegisterVersionUpdater(std::make_shared<SOH::ConfigVersion3Updater>());
|
||||
conf->RegisterVersionUpdater(std::make_shared<SOH::ConfigVersion4Updater>());
|
||||
conf->RegisterVersionUpdater(std::make_shared<SOH::ConfigVersion5Updater>());
|
||||
conf->RegisterVersionUpdater(std::make_shared<SOH::ConfigVersion6Updater>());
|
||||
conf->RegisterVersionUpdater(std::make_shared<SOH::ConfigVersion7Updater>());
|
||||
SOH::RegisterVersionUpdaters(conf.get());
|
||||
conf->RunVersionUpdates();
|
||||
|
||||
SohGui::SetupGuiElements();
|
||||
@@ -2481,6 +2475,8 @@ bool SoH_HandleConfigDrop(char* filePath) {
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32_t configVersion = SOH::GetConfigVersion(configJson, 0);
|
||||
|
||||
CVarClearBlock(CVAR_PREFIX_ENHANCEMENT);
|
||||
CVarClearBlock(CVAR_PREFIX_CHEAT);
|
||||
CVarClearBlock(CVAR_PREFIX_RANDOMIZER_SETTING);
|
||||
@@ -2506,6 +2502,9 @@ bool SoH_HandleConfigDrop(char* filePath) {
|
||||
}
|
||||
}
|
||||
|
||||
// Migrate configs from older versions
|
||||
SOH::RunVersionUpdatesFrom(configVersion);
|
||||
|
||||
gui->GetGuiWindow("Console")->Hide();
|
||||
gui->GetGuiWindow("Actor Viewer")->Hide();
|
||||
gui->GetGuiWindow("Collision Viewer")->Hide();
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
#include "ConfigUpdaters.h"
|
||||
|
||||
#include <array>
|
||||
#include <algorithm>
|
||||
#include <memory>
|
||||
#include <libultraship/bridge/consolevariablebridge.h>
|
||||
#include <spdlog/spdlog.h>
|
||||
#include <ship/Context.h>
|
||||
#include "soh/Enhancements/randomizer/randomizerEnums.h"
|
||||
|
||||
namespace SOH {
|
||||
@@ -1631,21 +1636,24 @@ void ConfigVersion7Updater::Update(Ship::Config* conf) {
|
||||
}
|
||||
|
||||
// Triforce Hunt: the Off/Win/GBK combobox was folded into TriforceHuntTotalPieces (0 = off)
|
||||
// and the required piece count moved to the Wincon/GBK trigger counts
|
||||
// and the required piece count moved to the Wincon/GBK trigger counts.
|
||||
// Counts need +1 from previous values
|
||||
switch (CVarGetInteger("gRandoSettings.TriforceHunt", 0)) {
|
||||
case 1: // Win
|
||||
CVarSetInteger("gRandoSettings.ShuffleWincon", RO_WINCON_TRIFORCE_PIECES);
|
||||
CVarSetInteger("gRandoSettings.WinconTriforceCount",
|
||||
CVarGetInteger("gRandoSettings.TriforceHuntRequiredPieces", 19));
|
||||
CVarGetInteger("gRandoSettings.TriforceHuntRequiredPieces", 19) + 1);
|
||||
CVarSetInteger("gRandoSettings.GbkTriforceCount",
|
||||
CVarGetInteger("gRandoSettings.TriforceHuntRequiredPieces", 19) + 1);
|
||||
CVarSetInteger("gRandoSettings.TriforceHuntTotalPieces",
|
||||
CVarGetInteger("gRandoSettings.TriforceHuntTotalPieces", 29));
|
||||
CVarGetInteger("gRandoSettings.TriforceHuntTotalPieces", 29) + 1);
|
||||
break;
|
||||
case 2: // Ganon's Boss Key
|
||||
CVarSetInteger("gRandoSettings.ShuffleGanonBossKey", RO_GANON_BOSS_KEY_TRIFORCE_PIECES);
|
||||
CVarSetInteger("gRandoSettings.GbkTriforceCount",
|
||||
CVarGetInteger("gRandoSettings.TriforceHuntRequiredPieces", 19));
|
||||
CVarGetInteger("gRandoSettings.TriforceHuntRequiredPieces", 19) + 1);
|
||||
CVarSetInteger("gRandoSettings.TriforceHuntTotalPieces",
|
||||
CVarGetInteger("gRandoSettings.TriforceHuntTotalPieces", 29));
|
||||
CVarGetInteger("gRandoSettings.TriforceHuntTotalPieces", 29) + 1);
|
||||
break;
|
||||
default: // Off; a leftover total would now silently enable the hunt
|
||||
CVarClear("gRandoSettings.TriforceHuntTotalPieces");
|
||||
@@ -1693,4 +1701,46 @@ void ConfigVersion7Updater::Update(Ship::Config* conf) {
|
||||
}
|
||||
CVarClear("gRandoSettings.CompleteMaskQuest");
|
||||
}
|
||||
|
||||
// v4+ also run on dropped configs and presets
|
||||
static const auto& GetVersionUpdaters() {
|
||||
static const std::array<std::shared_ptr<Ship::ConfigVersionUpdater>, 7> updaters = {
|
||||
std::make_shared<ConfigVersion1Updater>(), std::make_shared<ConfigVersion2Updater>(),
|
||||
std::make_shared<ConfigVersion3Updater>(), std::make_shared<ConfigVersion4Updater>(),
|
||||
std::make_shared<ConfigVersion5Updater>(), std::make_shared<ConfigVersion6Updater>(),
|
||||
std::make_shared<ConfigVersion7Updater>(),
|
||||
};
|
||||
return updaters;
|
||||
}
|
||||
|
||||
void RegisterVersionUpdaters(Ship::Config* conf) {
|
||||
for (const auto& updater : GetVersionUpdaters()) {
|
||||
conf->RegisterVersionUpdater(updater);
|
||||
}
|
||||
}
|
||||
|
||||
void RunVersionUpdatesFrom(uint32_t fromVersion) {
|
||||
if (fromVersion < GetLatestConfigVersion()) {
|
||||
SPDLOG_INFO("Migrating config from ConfigVersion {} to {}", fromVersion, GetLatestConfigVersion());
|
||||
}
|
||||
fromVersion = std::max(fromVersion, 3u);
|
||||
Ship::Config* conf = Ship::Context::GetRawInstance()->GetConfig().get();
|
||||
for (const auto& updater : GetVersionUpdaters()) {
|
||||
if (updater->GetVersion() > fromVersion) {
|
||||
updater->Update(conf);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t GetLatestConfigVersion() {
|
||||
return GetVersionUpdaters().back()->GetVersion();
|
||||
}
|
||||
|
||||
uint32_t GetConfigVersion(const nlohmann::json& json, uint32_t defaultVersion) {
|
||||
auto version = json.find("ConfigVersion");
|
||||
if (version == json.end() || !version->is_number_unsigned()) {
|
||||
return defaultVersion;
|
||||
}
|
||||
return version->get<uint32_t>();
|
||||
}
|
||||
} // namespace SOH
|
||||
|
||||
@@ -44,4 +44,12 @@ class ConfigVersion7Updater final : public Ship::ConfigVersionUpdater {
|
||||
ConfigVersion7Updater();
|
||||
void Update(Ship::Config* conf);
|
||||
};
|
||||
|
||||
void RegisterVersionUpdaters(Ship::Config* conf);
|
||||
|
||||
void RunVersionUpdatesFrom(uint32_t fromVersion);
|
||||
|
||||
uint32_t GetLatestConfigVersion();
|
||||
|
||||
uint32_t GetConfigVersion(const nlohmann::json& json, uint32_t defaultVersion);
|
||||
} // namespace SOH
|
||||
|
||||
Reference in New Issue
Block a user