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

This commit is contained in:
Yair Morgenstern 2023-11-18 22:27:47 +02:00
parent 2a862aa895
commit 5484576640
2 changed files with 31 additions and 13 deletions

View File

@ -4,6 +4,7 @@ import com.badlogic.gdx.math.Vector2
import com.unciv.Constants
import com.unciv.GUI
import com.unciv.logic.IsPartOfGameInfoSerialization
import com.unciv.logic.MultiFilter
import com.unciv.logic.city.City
import com.unciv.logic.civilization.Civilization
import com.unciv.logic.civilization.PlayerType
@ -477,8 +478,12 @@ open class Tile : IsPartOfGameInfoSerialization {
return improvement == null && filter == "unimproved"
}
/** Implements [UniqueParameterType.TerrainFilter][com.unciv.models.ruleset.unique.UniqueParameterType.TerrainFilter] */
fun matchesTerrainFilter(filter: String, observingCiv: Civilization? = null): Boolean {
return MultiFilter.multiFilter(filter, {matchesSingleTerrainFilter(it, observingCiv)})
}
/** Implements [UniqueParameterType.TerrainFilter][com.unciv.models.ruleset.unique.UniqueParameterType.TerrainFilter] */
fun matchesSingleTerrainFilter(filter: String, observingCiv: Civilization? = null): Boolean {
return when (filter) {
"All" -> true
baseTerrain -> true

View File

@ -321,22 +321,35 @@ enum class UniqueParameterType(
/** Implemented by [Tile.matchesTerrainFilter][com.unciv.logic.map.tile.Tile.matchesTerrainFilter] */
TerrainFilter("terrainFilter", Constants.freshWaterFilter, null, "Terrain Filters") {
private val knownValues = setOf("All",
Constants.coastal, Constants.river, "Open terrain", "Rough terrain", "Water resource",
"Foreign Land", "Foreign", "Friendly Land", "Friendly", "Enemy Land", "Enemy",
"Featureless", Constants.freshWaterFilter, "non-fresh water", "Natural Wonder",
"Impassable", "Land", "Water") +
private val knownValues = setOf(
"All",
Constants.coastal, Constants.river, "Open terrain", "Rough terrain", "Water resource",
"Foreign Land", "Foreign", "Friendly Land", "Friendly", "Enemy Land", "Enemy",
"Featureless", Constants.freshWaterFilter, "non-fresh water", "Natural Wonder",
"Impassable", "Land", "Water"
) +
ResourceType.values().map { it.name + " resource" }
override fun getErrorSeverity(parameterText: String, ruleset: Ruleset) = when(parameterText) {
in knownValues -> null
in ruleset.terrains -> null
in ruleset.tileResources -> null
in ruleset.terrains.values.asSequence().flatMap { it.uniques } -> null
in ruleset.tileResources.values.asSequence().flatMap { it.uniques } -> null
else -> UniqueType.UniqueParameterErrorSeverity.PossibleFilteringUnique
override fun getErrorSeverity(parameterText: String, ruleset: Ruleset): 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 {
return when (parameterText) {
in knownValues -> true
in ruleset.terrains -> true
in ruleset.tileResources -> true
in ruleset.terrains.values.asSequence().flatMap { it.uniques } -> true
in ruleset.tileResources.values.asSequence().flatMap { it.uniques } -> true
else -> false
}
}
override fun isTranslationWriterGuess(parameterText: String, ruleset: Ruleset) =
parameterText in ruleset.terrains || parameterText != "All" && parameterText in knownValues
override fun getTranslationWriterStringsForOutput() = knownValues
},