Easier location of mod errors, by specifying not only the name of the object with unique problems, but also the type

This commit is contained in:
Yair Morgenstern 2023-10-30 13:32:13 +02:00
parent 6ce685b719
commit c8365b8919
3 changed files with 8 additions and 9 deletions

View File

@ -382,7 +382,7 @@ class Ruleset {
UniqueValidator(this@Ruleset).checkUnique(
Unique(it),
false,
cityStateType,
null,
true
).isEmpty()
})
@ -390,7 +390,7 @@ class Ruleset {
UniqueValidator(this@Ruleset).checkUnique(
Unique(it),
false,
cityStateType,
null,
true
).isEmpty()
})

View File

@ -102,7 +102,7 @@ class RulesetValidator(val ruleset: Ruleset) {
val errors = uniqueValidator.checkUnique(
unique,
tryFixUnknownUniques,
cityStateType,
null,
true
)
lines.addAll(errors)

View File

@ -9,7 +9,6 @@ import com.unciv.models.ruleset.unique.UniqueComplianceError
import com.unciv.models.ruleset.unique.UniqueParameterType
import com.unciv.models.ruleset.unique.UniqueTarget
import com.unciv.models.ruleset.unique.UniqueType
import com.unciv.models.stats.INamed
class UniqueValidator(val ruleset: Ruleset) {
@ -46,7 +45,7 @@ class UniqueValidator(val ruleset: Ruleset) {
val errors = checkUnique(
unique,
tryFixUnknownUniques,
uniqueContainer as? INamed,
uniqueContainer,
reportRulesetSpecificErrors
)
lines.addAll(errors)
@ -56,16 +55,16 @@ class UniqueValidator(val ruleset: Ruleset) {
fun checkUnique(
unique: Unique,
tryFixUnknownUniques: Boolean,
namedObj: INamed?,
uniqueContainer: IHasUniques?,
reportRulesetSpecificErrors: Boolean
): List<RulesetError> {
val prefix by lazy { (if (namedObj is IRulesetObject) "${namedObj.originRuleset}: " else "") +
(if (namedObj == null) "The" else "${namedObj.name}'s") }
val prefix by lazy { (if (uniqueContainer is IRulesetObject) "${uniqueContainer.originRuleset}: " else "") +
(if (uniqueContainer == null) "The" else "(${uniqueContainer.getUniqueTarget().name}) ${uniqueContainer.name}'s") }
if (unique.type == null) return checkUntypedUnique(unique, tryFixUnknownUniques, prefix)
val rulesetErrors = RulesetErrorList()
if (namedObj is IHasUniques && !unique.type.canAcceptUniqueTarget(namedObj.getUniqueTarget()))
if (uniqueContainer != null && !unique.type.canAcceptUniqueTarget(uniqueContainer.getUniqueTarget()))
rulesetErrors.add(RulesetError("$prefix unique \"${unique.text}\" is not allowed on its target type", RulesetErrorSeverity.Warning))
val typeComplianceErrors = getComplianceErrors(unique)