modding: Added validation for UnitType.movementType

This commit is contained in:
yairm210 2025-01-29 15:10:10 +02:00
parent 9c618a242f
commit 55f4f44e65
2 changed files with 5 additions and 1 deletions

View File

@ -13,7 +13,7 @@ enum class UnitMovementType { // The types of tiles the unit can by default ente
}
class UnitType() : RulesetObject() {
private var movementType: String? = null
internal var movementType: String? = null
private val unitMovementType: UnitMovementType? by lazy { if (movementType == null) null else UnitMovementType.valueOf(movementType!!) }
override fun getUniqueTarget() = UniqueTarget.UnitType
override fun makeLink() = "UnitType/$name"

View File

@ -18,6 +18,7 @@ import com.unciv.models.ruleset.unique.StateForConditionals
import com.unciv.models.ruleset.unique.UniqueType
import com.unciv.models.ruleset.unit.BaseUnit
import com.unciv.models.ruleset.unit.Promotion
import com.unciv.models.ruleset.unit.UnitMovementType
import com.unciv.models.stats.INamed
import com.unciv.models.stats.Stats
import com.unciv.models.tilesets.TileSetCache
@ -312,11 +313,14 @@ class RulesetValidator(val ruleset: Ruleset) {
}
}
val unitMovementTypes = UnitMovementType.entries.map { it.name }.toSet()
private fun addUnitTypeErrors(
lines: RulesetErrorList,
tryFixUnknownUniques: Boolean
) {
for (unitType in ruleset.unitTypes.values) {
if (unitType.movementType !in unitMovementTypes)
lines.add("Unit type ${unitType.name} has an invalid movement type ${unitType.movementType}", sourceObject = unitType)
uniqueValidator.checkUniques(unitType, lines, true, tryFixUnknownUniques)
}
}