mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-22 02:42:16 -04:00
Better Validation of Nation colors (#13568)
* Fix json arrays that aren't [r,g,b] causing Ruleset load to throw * Fix checkNation forgetting to call its super * Ruleset-Validate array content of Nation colors
This commit is contained in:
parent
212a772190
commit
0846b6d486
@ -97,10 +97,12 @@ class Nation : RulesetObject() {
|
||||
var ignoreHillMovementCost = false
|
||||
|
||||
fun setTransients() {
|
||||
outerColorObject = colorFromRGB(outerColor)
|
||||
fun safeColorFromRGB(rgb: List<Int>) = if (rgb.size >= 3) colorFromRGB(rgb) else Color.PURPLE
|
||||
|
||||
outerColorObject = safeColorFromRGB(outerColor)
|
||||
|
||||
innerColorObject = if (innerColor == null) ImageGetter.CHARCOAL
|
||||
else colorFromRGB(innerColor!!)
|
||||
else safeColorFromRGB(innerColor!!)
|
||||
|
||||
forestsAndJunglesAreRoads = uniqueMap.hasUnique(UniqueType.ForestsAndJunglesAreRoads)
|
||||
ignoreHillMovementCost = uniqueMap.hasUnique(UniqueType.IgnoreHillMovementCost)
|
||||
|
@ -153,6 +153,7 @@ internal class BaseRulesetValidator(
|
||||
}
|
||||
|
||||
override fun checkNation(nation: Nation, lines: RulesetErrorList) {
|
||||
super.checkNation(nation, lines)
|
||||
if (nation.preferredVictoryType != Constants.neutralVictoryType && nation.preferredVictoryType !in ruleset.victories)
|
||||
lines.add("${nation.name}'s preferredVictoryType is ${nation.preferredVictoryType} which does not exist!", sourceObject = nation)
|
||||
if (nation.cityStateType != null && nation.cityStateType !in ruleset.cityStateTypes)
|
||||
|
@ -328,7 +328,21 @@ open class RulesetValidator protected constructor(
|
||||
lines.add("${nation.name} can settle cities, but has no city names!", sourceObject = nation)
|
||||
}
|
||||
|
||||
checkContrasts(nation.getInnerColor(), nation.getOuterColor(), nation, lines)
|
||||
fun isColorFaulty(rgb: List<Int>?) = when {
|
||||
rgb == null -> false
|
||||
rgb.size != 3 -> true
|
||||
rgb.any { it !in 0..255 } -> true
|
||||
else -> false
|
||||
}
|
||||
val badInner = isColorFaulty(nation.innerColor)
|
||||
val badOuter = isColorFaulty(nation.outerColor)
|
||||
if (badInner)
|
||||
lines.add("${nation.name}'s innerColor is not an array of three integers in the 0..255 range", sourceObject = nation)
|
||||
if (badOuter)
|
||||
lines.add("${nation.name}'s outerColor is not an array of three integers in the 0..255 range", sourceObject = nation)
|
||||
|
||||
if (!badInner && !badOuter)
|
||||
checkContrasts(nation.getInnerColor(), nation.getOuterColor(), nation, lines)
|
||||
}
|
||||
|
||||
protected open fun addPersonalityErrors(lines: RulesetErrorList) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user