mirror of
https://github.com/yairm210/Unciv.git
synced 2025-01-03 13:30:51 +07:00
Allow lower-case "all" for all filters
This commit is contained in:
parent
e7a2b94c60
commit
58318cb199
@ -3,8 +3,7 @@ package com.unciv
|
||||
object Constants {
|
||||
const val settler = "Settler"
|
||||
const val eraSpecificUnit = "Era Starting Unit"
|
||||
const val spreadReligion = "Spread Religion"
|
||||
const val removeHeresy = "Remove Foreign religions from your own cities"
|
||||
val all = setOf("All", "all")
|
||||
|
||||
const val english = "English"
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.unciv.logic.battle
|
||||
|
||||
import com.unciv.Constants
|
||||
import com.unciv.logic.MultiFilter
|
||||
import com.unciv.logic.city.City
|
||||
import com.unciv.logic.civilization.Civilization
|
||||
@ -24,7 +25,7 @@ class CityCombatant(val city: City) : ICombatant {
|
||||
override fun isDefeated(): Boolean = city.health == 1
|
||||
override fun isInvisible(to: Civilization): Boolean = false
|
||||
override fun canAttack(): Boolean = city.canBombard()
|
||||
override fun matchesFilter(filter: String) = MultiFilter.multiFilter(filter, {it == "City" || it == "All" || city.matchesFilter(it)})
|
||||
override fun matchesFilter(filter: String) = MultiFilter.multiFilter(filter, {it == "City" || it in Constants.all || city.matchesFilter(it)})
|
||||
override fun getAttackSound() = UncivSound.Bombard
|
||||
|
||||
override fun takeDamage(damage: Int) {
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.unciv.logic.city
|
||||
|
||||
import com.badlogic.gdx.math.Vector2
|
||||
import com.unciv.Constants
|
||||
import com.unciv.GUI
|
||||
import com.unciv.logic.IsPartOfGameInfoSerialization
|
||||
import com.unciv.logic.MultiFilter
|
||||
@ -486,7 +487,8 @@ class City : IsPartOfGameInfoSerialization {
|
||||
private fun matchesSingleFilter(filter: String, viewingCiv: Civilization? = civ): Boolean {
|
||||
return when (filter) {
|
||||
"in this city" -> true // Filtered by the way uniques are found
|
||||
"in all cities", "All" -> true
|
||||
"in all cities" -> true
|
||||
in Constants.all -> true
|
||||
"in your cities", "Your" -> viewingCiv == civ
|
||||
"in all coastal cities", "Coastal" -> isCoastal()
|
||||
"in capital", "Capital" -> isCapital()
|
||||
|
@ -502,10 +502,10 @@ class TechManager : IsPartOfGameInfoSerialization {
|
||||
private fun updateTransientBooleans() {
|
||||
unitsCanEmbark = civInfo.hasUnique(UniqueType.LandUnitEmbarkation)
|
||||
val enterOceanUniques = civInfo.getMatchingUniques(UniqueType.UnitsMayEnterOcean)
|
||||
allUnitsCanEnterOcean = enterOceanUniques.any { it.params[0] == "All" }
|
||||
allUnitsCanEnterOcean = enterOceanUniques.any { it.params[0] in Constants.all }
|
||||
embarkedUnitsCanEnterOcean = allUnitsCanEnterOcean ||
|
||||
enterOceanUniques.any { it.params[0] == Constants.embarked }
|
||||
specificUnitsCanEnterOcean = enterOceanUniques.any { it.params[0] != "All" && it.params[0] != Constants.embarked }
|
||||
specificUnitsCanEnterOcean = enterOceanUniques.any { it.params[0] !in Constants.all && it.params[0] != Constants.embarked }
|
||||
|
||||
movementSpeedOnRoads = if (civInfo.hasUnique(UniqueType.RoadMovementSpeed))
|
||||
RoadStatus.Road.movementImproved else RoadStatus.Road.movement
|
||||
|
@ -498,7 +498,8 @@ open class Tile : IsPartOfGameInfoSerialization {
|
||||
/** Implements [UniqueParameterType.TerrainFilter][com.unciv.models.ruleset.unique.UniqueParameterType.TerrainFilter] */
|
||||
fun matchesSingleTerrainFilter(filter: String, observingCiv: Civilization? = null): Boolean {
|
||||
return when (filter) {
|
||||
"All", "Terrain" -> true
|
||||
"Terrain" -> true
|
||||
in Constants.all -> true
|
||||
baseTerrain -> true
|
||||
"Water" -> isWater
|
||||
"Land" -> isLand
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.unciv.models.ruleset
|
||||
|
||||
import com.unciv.Constants
|
||||
import com.unciv.logic.MultiFilter
|
||||
import com.unciv.logic.city.City
|
||||
import com.unciv.logic.city.CityConstructions
|
||||
@ -447,9 +448,9 @@ class Building : RulesetStatsObject(), INonPerpetualConstruction {
|
||||
return MultiFilter.multiFilter(filter, ::matchesSingleFilter)
|
||||
}
|
||||
|
||||
fun matchesSingleFilter(filter: String): Boolean {
|
||||
private fun matchesSingleFilter(filter: String): Boolean {
|
||||
return when (filter) {
|
||||
"All" -> true
|
||||
in Constants.all -> true
|
||||
name -> true
|
||||
"Building", "Buildings" -> !isAnyWonder()
|
||||
"Wonder", "Wonders" -> isAnyWonder()
|
||||
|
@ -263,9 +263,9 @@ class Nation : RulesetObject() {
|
||||
return MultiFilter.multiFilter(filter, ::matchesSingleFilter)
|
||||
}
|
||||
|
||||
fun matchesSingleFilter(filter: String): Boolean {
|
||||
private fun matchesSingleFilter(filter: String): Boolean {
|
||||
return when (filter) {
|
||||
"All" -> true
|
||||
in Constants.all -> true
|
||||
name -> true
|
||||
"Major" -> isMajorCiv
|
||||
// "CityState" to be deprecated, replaced by "City-States"
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.unciv.models.ruleset.tech
|
||||
|
||||
import com.unciv.Constants
|
||||
import com.unciv.logic.civilization.Civilization
|
||||
import com.unciv.models.ruleset.Ruleset
|
||||
import com.unciv.models.ruleset.RulesetObject
|
||||
@ -34,7 +35,7 @@ class Technology: RulesetObject() {
|
||||
|
||||
fun matchesFilter(filter: String): Boolean {
|
||||
return when (filter) {
|
||||
"All" -> true
|
||||
in Constants.all -> true
|
||||
name -> true
|
||||
era() -> true
|
||||
else -> uniques.contains(filter)
|
||||
|
@ -93,10 +93,10 @@ class TileImprovement : RulesetStatsObject() {
|
||||
return MultiFilter.multiFilter(filter, ::matchesSingleFilter)
|
||||
}
|
||||
|
||||
fun matchesSingleFilter(filter: String): Boolean {
|
||||
private fun matchesSingleFilter(filter: String): Boolean {
|
||||
return when (filter) {
|
||||
name -> true
|
||||
"All" -> true
|
||||
in Constants.all -> true
|
||||
"Improvement" -> true // For situations involving tileFilter
|
||||
"All Road" -> isRoad()
|
||||
"Great Improvement", "Great" -> isGreatImprovement()
|
||||
|
@ -77,7 +77,7 @@ enum class UniqueParameterType(
|
||||
// todo potentially remove if OneTimeRevealSpecificMapTiles changes
|
||||
KeywordAll("'all'", "All") {
|
||||
override fun getErrorSeverity(parameterText: String, ruleset: Ruleset) =
|
||||
if (parameterText == "All") null else UniqueType.UniqueParameterErrorSeverity.RulesetInvariant
|
||||
if (parameterText in Constants.all) null else UniqueType.UniqueParameterErrorSeverity.RulesetInvariant
|
||||
},
|
||||
|
||||
/** Implemented by [ICombatant.matchesCategory][com.unciv.logic.battle.ICombatant.matchesFilter] */
|
||||
@ -115,10 +115,10 @@ enum class UniqueParameterType(
|
||||
/** Implemented by [BaseUnit.matchesFilter][com.unciv.models.ruleset.unit.BaseUnit.matchesFilter] */
|
||||
BaseUnitFilter("baseUnitFilter", "Melee") {
|
||||
private val knownValues = setOf(
|
||||
"All", "Melee", "Ranged", "Civilian", "Military", "non-air",
|
||||
"Melee", "Ranged", "Civilian", "Military", "non-air",
|
||||
"Nuclear Weapon", "Great Person", "Religious",
|
||||
"relevant", // used for UniqueType.UnitStartingPromotions
|
||||
)
|
||||
) + Constants.all
|
||||
override fun getErrorSeverity(parameterText: String, ruleset: Ruleset):
|
||||
UniqueType.UniqueParameterErrorSeverity? = getErrorSeverityForFilter(parameterText, ruleset)
|
||||
|
||||
@ -222,7 +222,7 @@ enum class UniqueParameterType(
|
||||
|
||||
/** Implemented by [Nation.matchesFilter][com.unciv.models.ruleset.nation.Nation.matchesFilter] */
|
||||
NationFilter("nationFilter", Constants.cityStates) {
|
||||
private val knownValues = setOf(Constants.cityStates, "Major", "All")
|
||||
private val knownValues = setOf(Constants.cityStates, "Major") + Constants.all
|
||||
|
||||
override fun getErrorSeverity(parameterText: String, ruleset: Ruleset):
|
||||
UniqueType.UniqueParameterErrorSeverity? = getErrorSeverityForFilter(parameterText, ruleset)
|
||||
@ -239,7 +239,7 @@ enum class UniqueParameterType(
|
||||
CityFilter("cityFilter", "in all cities", null, "City filters") {
|
||||
private val knownValues = setOf(
|
||||
"in this city",
|
||||
"in all cities", "All",
|
||||
"in all cities",
|
||||
"in your cities", "Your",
|
||||
"in all coastal cities", "Coastal",
|
||||
"in capital", "Capital",
|
||||
@ -258,7 +258,7 @@ enum class UniqueParameterType(
|
||||
"in City-State cities",
|
||||
"in cities following this religion",
|
||||
"in cities following our religion",
|
||||
)
|
||||
) + Constants.all
|
||||
|
||||
override fun getErrorSeverity(parameterText: String, ruleset: Ruleset):
|
||||
UniqueType.UniqueParameterErrorSeverity? = getErrorSeverityForFilter(parameterText, ruleset)
|
||||
@ -284,8 +284,8 @@ enum class UniqueParameterType(
|
||||
|
||||
/** Implemented by [Building.matchesFilter][com.unciv.models.ruleset.Building.matchesFilter] */
|
||||
BuildingFilter("buildingFilter", "Culture") {
|
||||
private val knownValues = mutableSetOf("All", "Building", "Buildings", "Wonder", "Wonders", "National Wonder", "World Wonder")
|
||||
.apply { addAll(Stat.names()) }
|
||||
private val knownValues = mutableSetOf("Building", "Buildings", "Wonder", "Wonders", "National Wonder", "World Wonder")
|
||||
.apply { addAll(Stat.names()); addAll(Constants.all) }
|
||||
|
||||
override fun getErrorSeverity(parameterText: String, ruleset: Ruleset):
|
||||
UniqueType.UniqueParameterErrorSeverity? = getErrorSeverityForFilter(parameterText, ruleset)
|
||||
@ -298,7 +298,7 @@ enum class UniqueParameterType(
|
||||
}
|
||||
|
||||
override fun isTranslationWriterGuess(parameterText: String, ruleset: Ruleset) =
|
||||
parameterText != "All" && getErrorSeverity(parameterText, ruleset) == null
|
||||
parameterText !in Constants.all && getErrorSeverity(parameterText, ruleset) == null
|
||||
},
|
||||
|
||||
/** Implemented by [PopulationManager.getPopulationFilterAmount][com.unciv.logic.city.managers.CityPopulationManager.getPopulationFilterAmount] */
|
||||
@ -317,13 +317,12 @@ 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", "Terrain",
|
||||
"Terrain",
|
||||
Constants.coastal, Constants.river, "Open terrain", "Rough terrain", "Water resource",
|
||||
"resource", "Foreign Land", "Foreign", "Friendly Land", "Friendly", "Enemy Land", "Enemy", "your",
|
||||
"Featureless", Constants.freshWaterFilter, "non-fresh water", "Natural Wonder",
|
||||
"Impassable", "Land", "Water"
|
||||
) +
|
||||
ResourceType.values().map { it.name + " resource" }
|
||||
) + ResourceType.values().map { it.name + " resource" } + Constants.all
|
||||
|
||||
override fun getErrorSeverity(parameterText: String, ruleset: Ruleset):
|
||||
UniqueType.UniqueParameterErrorSeverity? = getErrorSeverityForFilter(parameterText, ruleset)
|
||||
@ -340,7 +339,7 @@ enum class UniqueParameterType(
|
||||
}
|
||||
|
||||
override fun isTranslationWriterGuess(parameterText: String, ruleset: Ruleset) =
|
||||
parameterText in ruleset.terrains || parameterText != "All" && parameterText in knownValues
|
||||
parameterText in ruleset.terrains || parameterText !in Constants.all && parameterText in knownValues
|
||||
|
||||
override fun getTranslationWriterStringsForOutput() = knownValues
|
||||
},
|
||||
@ -450,7 +449,7 @@ enum class UniqueParameterType(
|
||||
|
||||
/** Implemented by [TileImprovement.matchesFilter][com.unciv.models.ruleset.tile.TileImprovement.matchesFilter] */
|
||||
ImprovementFilter("improvementFilter", "All Road", null, "Improvement Filters") {
|
||||
private val knownValues = setOf("All", "Improvement", "All Road", "Great Improvement", "Great")
|
||||
private val knownValues = setOf("Improvement", "All Road", "Great Improvement", "Great") + Constants.all
|
||||
|
||||
override fun getErrorSeverity(parameterText: String, ruleset: Ruleset):
|
||||
UniqueType.UniqueParameterErrorSeverity? = getErrorSeverityForFilter(parameterText, ruleset)
|
||||
@ -463,7 +462,7 @@ enum class UniqueParameterType(
|
||||
}
|
||||
|
||||
override fun isTranslationWriterGuess(parameterText: String, ruleset: Ruleset) =
|
||||
parameterText != "All" && getErrorSeverity(parameterText, ruleset) == null
|
||||
parameterText !in Constants.all && getErrorSeverity(parameterText, ruleset) == null
|
||||
|
||||
override fun getTranslationWriterStringsForOutput() = knownValues
|
||||
},
|
||||
@ -568,20 +567,6 @@ enum class UniqueParameterType(
|
||||
}
|
||||
},
|
||||
|
||||
/** For untyped "Can [] [] times" unique */
|
||||
@Deprecated("As of 4.8.9")
|
||||
Action("action", Constants.spreadReligion, "An action that a unit can perform. Currently, there are only two actions part of this: 'Spread Religion' and 'Remove Foreign religions from your own cities'", "Religious Action Filters") {
|
||||
private val knownValues = setOf(Constants.spreadReligion, Constants.removeHeresy)
|
||||
override fun getErrorSeverity(
|
||||
parameterText: String,
|
||||
ruleset: Ruleset
|
||||
): UniqueType.UniqueParameterErrorSeverity? {
|
||||
return if (parameterText in knownValues) null
|
||||
else UniqueType.UniqueParameterErrorSeverity.RulesetInvariant
|
||||
}
|
||||
override fun getTranslationWriterStringsForOutput() = knownValues
|
||||
},
|
||||
|
||||
/** Mod declarative compatibility: Define Mod relations by their name. */
|
||||
ModName("modFilter", "DeCiv Redux", """A Mod name, case-sensitive _or_ a simple wildcard filter beginning and ending in an Asterisk, case-insensitive""", "Mod name filter") {
|
||||
override fun getErrorSeverity(parameterText: String, ruleset: Ruleset):
|
||||
|
@ -598,7 +598,7 @@ object UniqueTriggerActivation {
|
||||
val filter = unique.params[1]
|
||||
val radius = unique.params[2].toInt()
|
||||
|
||||
val isAll = amount == "All"
|
||||
val isAll = amount in Constants.all
|
||||
val positions = ArrayList<Vector2>()
|
||||
|
||||
var explorableTiles = tile.getTilesInDistance(radius)
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.unciv.models.ruleset.unit
|
||||
|
||||
import com.unciv.Constants
|
||||
import com.unciv.logic.MultiFilter
|
||||
import com.unciv.logic.city.City
|
||||
import com.unciv.logic.city.CityConstructions
|
||||
@ -315,7 +316,7 @@ class BaseUnit : RulesetObject(), INonPerpetualConstruction {
|
||||
unitType -> true
|
||||
name -> true
|
||||
replaces -> true
|
||||
"All" -> true
|
||||
in Constants.all -> true
|
||||
|
||||
"Melee" -> isMelee()
|
||||
"Ranged" -> isRanged()
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.unciv.models.ruleset.validation
|
||||
|
||||
import com.unciv.Constants
|
||||
import com.unciv.logic.map.mapunit.MapUnitCache
|
||||
import com.unciv.models.ruleset.IRulesetObject
|
||||
import com.unciv.models.ruleset.Ruleset
|
||||
@ -86,7 +87,7 @@ class UniqueValidator(val ruleset: Ruleset) {
|
||||
}
|
||||
|
||||
if (unique.type in MapUnitCache.UnitMovementUniques
|
||||
&& unique.conditionals.any { it.type != UniqueType.ConditionalOurUnit || it.params[0] != "All" }
|
||||
&& unique.conditionals.any { it.type != UniqueType.ConditionalOurUnit || it.params[0] !in Constants.all }
|
||||
)
|
||||
// (Stay silent if the only conditional is `<for [All] units>` - as in G&K Denmark)
|
||||
// Not necessarily even a problem, but yes something mod maker should be aware of
|
||||
|
@ -298,7 +298,7 @@ object UnitActionsFromUniques {
|
||||
|
||||
// If a unit has terrainFilter "Land" or improvementFilter "All", then we may proceed.
|
||||
// If a unit only had improvement filter "Road" or "Railroad", then we need to also check if that tech is unlocked
|
||||
val unitCanBuildRoad = uniquesToCheck.any { it.params[0] == "Land" || it.params[0] == "All" }
|
||||
val unitCanBuildRoad = uniquesToCheck.any { it.params[0] == "Land" || it.params[0] in Constants.all }
|
||||
|| uniquesToCheck.any {it.params[0] == "Road" } && (unitCivBestRoad == RoadStatus.Road || unitCivBestRoad == RoadStatus.Railroad)
|
||||
|| uniquesToCheck.any {it.params[0] == "Railroad"} && (unitCivBestRoad == RoadStatus.Railroad)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user