Modding: Added "non-[filter]" and multi-value filtering to Improvement filter

This commit is contained in:
Yair Morgenstern 2023-11-18 22:30:07 +02:00
parent 5484576640
commit ddf8b449b3
2 changed files with 17 additions and 4 deletions

View File

@ -2,6 +2,7 @@ package com.unciv.models.ruleset.tile
import com.unciv.Constants
import com.unciv.UncivGame
import com.unciv.logic.MultiFilter
import com.unciv.logic.civilization.Civilization
import com.unciv.logic.map.mapunit.MapUnit
import com.unciv.logic.map.tile.RoadStatus
@ -87,6 +88,10 @@ class TileImprovement : RulesetStatsObject() {
/** Implements [UniqueParameterType.ImprovementFilter][com.unciv.models.ruleset.unique.UniqueParameterType.ImprovementFilter] */
fun matchesFilter(filter: String): Boolean {
return MultiFilter.multiFilter(filter, ::matchesSingleFilter)
}
fun matchesSingleFilter(filter: String): Boolean {
return when (filter) {
name -> true
"All" -> true

View File

@ -455,14 +455,22 @@ enum class UniqueParameterType(
ImprovementFilter("improvementFilter", "All Road", null, "Improvement Filters") {
private val knownValues = setOf("All", "Improvement", "All Road", "Great Improvement", "Great")
override fun getErrorSeverity(parameterText: String, ruleset: Ruleset):
UniqueType.UniqueParameterErrorSeverity? {
if (parameterText in knownValues) return null
if (ImprovementName.getErrorSeverity(parameterText, ruleset) == null) return null
if (ruleset.tileImprovements.values.any { it.hasUnique(parameterText) }) return null
UniqueType.UniqueParameterErrorSeverity? {
val isKnown = MultiFilter.multiFilter(parameterText, {isKnownValue(it, ruleset)}, true)
if (isKnown) return null
return UniqueType.UniqueParameterErrorSeverity.PossibleFilteringUnique
}
override fun isKnownValue(parameterText: String, ruleset: Ruleset): Boolean {
if (parameterText in knownValues) return true
if (ImprovementName.getErrorSeverity(parameterText, ruleset) == null) return true
if (ruleset.tileImprovements.values.any { it.hasUnique(parameterText) }) return true
return false
}
override fun isTranslationWriterGuess(parameterText: String, ruleset: Ruleset) =
parameterText != "All" && getErrorSeverity(parameterText, ruleset) == null
override fun getTranslationWriterStringsForOutput() = knownValues
},