mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-30 07:21:34 -04:00
We now check compatibility of newly selected mods to the existing mod ruleset
This commit is contained in:
parent
03193e4f61
commit
3176cd147a
@ -199,12 +199,35 @@ class GameOptionsTable(val previousScreen: IPreviousScreen, val updatePlayerPick
|
|||||||
return@onChange
|
return@onChange
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val previousMods = gameParameters.mods.toList()
|
||||||
|
|
||||||
if (mod.modOptions.isBaseRuleset)
|
if (mod.modOptions.isBaseRuleset)
|
||||||
for (oldBaseRuleset in gameParameters.mods.toList()) // so we don't get concurrent modification excpetions
|
for (oldBaseRuleset in previousMods) // so we don't get concurrent modification excpetions
|
||||||
if (modRulesets.firstOrNull { it.name == oldBaseRuleset }?.modOptions?.isBaseRuleset == true)
|
if (modRulesets.firstOrNull { it.name == oldBaseRuleset }?.modOptions?.isBaseRuleset == true)
|
||||||
gameParameters.mods.remove(oldBaseRuleset)
|
gameParameters.mods.remove(oldBaseRuleset)
|
||||||
gameParameters.mods.add(mod.name)
|
gameParameters.mods.add(mod.name)
|
||||||
reloadRuleset() // This can FAIL at updateBuildingCosts if the mod is incorrectly defined! So we need to popup!
|
|
||||||
|
var isCompatibleWithCurrentRuleset = true
|
||||||
|
try {
|
||||||
|
val newRuleset = RulesetCache.getComplexRuleset(gameParameters)
|
||||||
|
newRuleset.modOptions.isBaseRuleset = true
|
||||||
|
val complexModLinkErrors = newRuleset.checkModLinks()
|
||||||
|
if (complexModLinkErrors != "") isCompatibleWithCurrentRuleset = false
|
||||||
|
} catch (x: Exception) {
|
||||||
|
// This happens if a building is dependent on a tech not in the base ruleset
|
||||||
|
// because newRuleset.updateBuildingCosts() in getComplexRulset() throws an error
|
||||||
|
isCompatibleWithCurrentRuleset = false
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isCompatibleWithCurrentRuleset) {
|
||||||
|
ToastPopup("The mod you selected is incompatible with the defined ruleset!\n\n$modLinkErrors", previousScreen as CameraStageBaseScreen)
|
||||||
|
checkBox.isChecked = false
|
||||||
|
gameParameters.mods.clear()
|
||||||
|
gameParameters.mods.addAll(previousMods)
|
||||||
|
return@onChange
|
||||||
|
}
|
||||||
|
|
||||||
|
reloadRuleset()
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
gameParameters.mods.remove(mod.name)
|
gameParameters.mods.remove(mod.name)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user