We now check compatibility of newly selected mods to the existing mod ruleset

This commit is contained in:
Yair Morgenstern 2020-11-16 21:18:17 +02:00
parent 03193e4f61
commit 3176cd147a
2 changed files with 27 additions and 4 deletions

View File

@ -228,7 +228,7 @@ class Ruleset {
}
}
for(building in buildings.values) {
for (building in buildings.values) {
if (building.requiredTech == null && building.cost == 0)
lines += "${building.name} must either have an explicit cost or reference an existing tech!"
}
@ -346,7 +346,7 @@ object RulesetCache :HashMap<String,Ruleset>() {
for (mod in loadedMods.sortedByDescending { it.modOptions.isBaseRuleset }) {
newRuleset.add(mod)
newRuleset.mods += mod.name
if(mod.modOptions.isBaseRuleset){
if (mod.modOptions.isBaseRuleset) {
newRuleset.modOptions = mod.modOptions
}
}

View File

@ -199,12 +199,35 @@ class GameOptionsTable(val previousScreen: IPreviousScreen, val updatePlayerPick
return@onChange
}
val previousMods = gameParameters.mods.toList()
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)
gameParameters.mods.remove(oldBaseRuleset)
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 {
gameParameters.mods.remove(mod.name)