Skip to content

Commit

Permalink
Easier location of mod errors, by specifying not only the name of the…
Browse files Browse the repository at this point in the history
… object with unique problems, but also the type
  • Loading branch information
yairm210 committed Oct 30, 2023
1 parent 6ce685b commit c8365b8
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
4 changes: 2 additions & 2 deletions core/src/com/unciv/models/ruleset/Ruleset.kt
Original file line number Diff line number Diff line change
Expand Up @@ -382,15 +382,15 @@ class Ruleset {
UniqueValidator(this@Ruleset).checkUnique(
Unique(it),
false,
cityStateType,
null,
true
).isEmpty()
})
allyBonusUniques = ArrayList(cityStateType.allyBonusUniques.filter {
UniqueValidator(this@Ruleset).checkUnique(
Unique(it),
false,
cityStateType,
null,
true
).isEmpty()
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class RulesetValidator(val ruleset: Ruleset) {
val errors = uniqueValidator.checkUnique(
unique,
tryFixUnknownUniques,
cityStateType,
null,
true
)
lines.addAll(errors)
Expand Down
11 changes: 5 additions & 6 deletions core/src/com/unciv/models/ruleset/validation/UniqueValidator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Expand Down Expand Up @@ -46,7 +45,7 @@ class UniqueValidator(val ruleset: Ruleset) {
val errors = checkUnique(
unique,
tryFixUnknownUniques,
uniqueContainer as? INamed,
uniqueContainer,
reportRulesetSpecificErrors
)
lines.addAll(errors)
Expand All @@ -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)
Expand Down

0 comments on commit c8365b8

Please sign in to comment.