1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-22 22:13:35 +02:00

Auto-recover from cases when active preset is invalid

This commit is contained in:
Ivan Savenko 2024-12-15 19:43:43 +00:00
parent d42ae2995b
commit 50838f24bf

View File

@ -163,7 +163,7 @@ ModsPresetState::ModsPresetState()
CResourceHandler::get("local")->createResource(settingsPath.getOriginalName() + ".json");
}
if(modConfig["presets"].isNull())
if(modConfig["presets"].isNull() || modConfig["presets"].Struct().empty())
{
modConfig["activePreset"] = JsonNode("default");
if(modConfig["activeMods"].isNull())
@ -171,6 +171,10 @@ ModsPresetState::ModsPresetState()
else
importInitialPreset(); // 1.5 format import
}
auto allPresets = getAllPresets();
if (!vstd::contains(allPresets, modConfig["activePreset"].String()))
modConfig["activePreset"] = JsonNode(allPresets.front());
}
void ModsPresetState::createInitialPreset()