From ddf8b449b37b4a1c4518578fe193b3331073e809 Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Sat, 18 Nov 2023 22:30:07 +0200 Subject: [PATCH] Modding: Added "non-[filter]" and multi-value filtering to Improvement filter --- .../unciv/models/ruleset/tile/TileImprovement.kt | 5 +++++ .../models/ruleset/unique/UniqueParameterType.kt | 16 ++++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/core/src/com/unciv/models/ruleset/tile/TileImprovement.kt b/core/src/com/unciv/models/ruleset/tile/TileImprovement.kt index 386703813f..a8081e4ff3 100644 --- a/core/src/com/unciv/models/ruleset/tile/TileImprovement.kt +++ b/core/src/com/unciv/models/ruleset/tile/TileImprovement.kt @@ -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 diff --git a/core/src/com/unciv/models/ruleset/unique/UniqueParameterType.kt b/core/src/com/unciv/models/ruleset/unique/UniqueParameterType.kt index 176b928508..fe2100fb56 100644 --- a/core/src/com/unciv/models/ruleset/unique/UniqueParameterType.kt +++ b/core/src/com/unciv/models/ruleset/unique/UniqueParameterType.kt @@ -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 },