mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-28 06:16:37 -04:00
Added city filter as parameter type, some reorg
This commit is contained in:
parent
2f8de2d196
commit
55a77096c1
@ -5,84 +5,6 @@ import com.unciv.models.translations.getPlaceholderParameters
|
|||||||
import com.unciv.models.translations.getPlaceholderText
|
import com.unciv.models.translations.getPlaceholderText
|
||||||
|
|
||||||
|
|
||||||
// parameterName values should be compliant with autogenerated values in TranslationFileWriter.generateStringsFromJSONs
|
|
||||||
// Eventually we'll merge the translation generation to take this as the source of that
|
|
||||||
enum class UniqueParameterType(val parameterName:String) {
|
|
||||||
Number("amount") {
|
|
||||||
override fun getErrorSeverity(parameterText: String, ruleset: Ruleset):
|
|
||||||
UniqueType.UniqueComplianceErrorSeverity? {
|
|
||||||
return if (parameterText.toIntOrNull() == null) UniqueType.UniqueComplianceErrorSeverity.RulesetInvariant
|
|
||||||
else null
|
|
||||||
}
|
|
||||||
},
|
|
||||||
MapUnitFilter("mapUnitFilter"){
|
|
||||||
val knownValues = setOf("Wounded", "Barbarians", "City-State", "Embarked", "Non-City")
|
|
||||||
override fun getErrorSeverity(parameterText: String, ruleset: Ruleset):
|
|
||||||
UniqueType.UniqueComplianceErrorSeverity? {
|
|
||||||
if (parameterText in knownValues) return null
|
|
||||||
return BaseUnitFilter.getErrorSeverity(parameterText, ruleset)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
BaseUnitFilter("baseUnitFilter"){
|
|
||||||
// As you can see there is a difference between these and what's in unitTypeStrings (for translation) -
|
|
||||||
// the goal is to unify, but for now this is the "real" list
|
|
||||||
val knownValues = setOf("All", "Melee", "Ranged", "Civilian", "Military", "Land", "Water", "Air",
|
|
||||||
"non-air", "Nuclear Weapon", "Great Person", "Religious")
|
|
||||||
override fun getErrorSeverity(parameterText: String, ruleset: Ruleset):
|
|
||||||
UniqueType.UniqueComplianceErrorSeverity? {
|
|
||||||
if (parameterText in knownValues) return null
|
|
||||||
if (ruleset.unitTypes.containsKey(parameterText)) return null
|
|
||||||
if (ruleset.units.containsKey(parameterText)) return null
|
|
||||||
|
|
||||||
// We could add a giant hashset of all uniques used by units,
|
|
||||||
// so we could accept that unique-targeting uniques are OK. Maybe later.
|
|
||||||
|
|
||||||
return UniqueType.UniqueComplianceErrorSeverity.WarningOnly
|
|
||||||
}
|
|
||||||
},
|
|
||||||
Stats("stats"){
|
|
||||||
override fun getErrorSeverity(parameterText: String, ruleset: Ruleset):
|
|
||||||
UniqueType.UniqueComplianceErrorSeverity? {
|
|
||||||
if (!com.unciv.models.stats.Stats.isStats(parameterText))
|
|
||||||
return UniqueType.UniqueComplianceErrorSeverity.RulesetInvariant
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
},
|
|
||||||
Unknown("param") {
|
|
||||||
override fun getErrorSeverity(parameterText: String, ruleset: Ruleset):
|
|
||||||
UniqueType.UniqueComplianceErrorSeverity? {
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
abstract fun getErrorSeverity(parameterText:String, ruleset: Ruleset): UniqueType.UniqueComplianceErrorSeverity?
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
val unitTypeStrings = hashSetOf(
|
|
||||||
"Military",
|
|
||||||
"Civilian",
|
|
||||||
"non-air",
|
|
||||||
"relevant",
|
|
||||||
"Nuclear Weapon",
|
|
||||||
"City",
|
|
||||||
// These are up for debate
|
|
||||||
"Air",
|
|
||||||
"land units",
|
|
||||||
"water units",
|
|
||||||
"air units",
|
|
||||||
"military units",
|
|
||||||
"submarine units",
|
|
||||||
// Note: this can't handle combinations of parameters (e.g. [{Military} {Water}])
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class UniqueComplianceError(
|
|
||||||
val parameterName: String,
|
|
||||||
val acceptableParameterTypes: List<UniqueParameterType>,
|
|
||||||
val errorSeverity: UniqueType.UniqueComplianceErrorSeverity
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
enum class UniqueType(val text:String, val replacedBy: UniqueType? = null) {
|
enum class UniqueType(val text:String, val replacedBy: UniqueType? = null) {
|
||||||
|
|
||||||
|
107
core/src/com/unciv/models/ruleset/UniqueParameterType.kt
Normal file
107
core/src/com/unciv/models/ruleset/UniqueParameterType.kt
Normal file
@ -0,0 +1,107 @@
|
|||||||
|
package com.unciv.models.ruleset
|
||||||
|
|
||||||
|
// parameterName values should be compliant with autogenerated values in TranslationFileWriter.generateStringsFromJSONs
|
||||||
|
// Eventually we'll merge the translation generation to take this as the source of that
|
||||||
|
enum class UniqueParameterType(val parameterName:String) {
|
||||||
|
Number("amount") {
|
||||||
|
override fun getErrorSeverity(parameterText: String, ruleset: Ruleset):
|
||||||
|
UniqueType.UniqueComplianceErrorSeverity? {
|
||||||
|
return if (parameterText.toIntOrNull() == null) UniqueType.UniqueComplianceErrorSeverity.RulesetInvariant
|
||||||
|
else null
|
||||||
|
}
|
||||||
|
},
|
||||||
|
MapUnitFilter("mapUnitFilter"){
|
||||||
|
val knownValues = setOf("Wounded", "Barbarians", "City-State", "Embarked", "Non-City")
|
||||||
|
override fun getErrorSeverity(parameterText: String, ruleset: Ruleset):
|
||||||
|
UniqueType.UniqueComplianceErrorSeverity? {
|
||||||
|
if (parameterText in knownValues) return null
|
||||||
|
return BaseUnitFilter.getErrorSeverity(parameterText, ruleset)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
BaseUnitFilter("baseUnitFilter"){
|
||||||
|
// As you can see there is a difference between these and what's in unitTypeStrings (for translation) -
|
||||||
|
// the goal is to unify, but for now this is the "real" list
|
||||||
|
val knownValues = setOf("All", "Melee", "Ranged", "Civilian", "Military", "Land", "Water", "Air",
|
||||||
|
"non-air", "Nuclear Weapon", "Great Person", "Religious")
|
||||||
|
override fun getErrorSeverity(parameterText: String, ruleset: Ruleset):
|
||||||
|
UniqueType.UniqueComplianceErrorSeverity? {
|
||||||
|
if (parameterText in knownValues) return null
|
||||||
|
if (ruleset.unitTypes.containsKey(parameterText)) return null
|
||||||
|
if (ruleset.units.containsKey(parameterText)) return null
|
||||||
|
|
||||||
|
// We could add a giant hashset of all uniques used by units,
|
||||||
|
// so we could accept that unique-targeting uniques are OK. Maybe later.
|
||||||
|
|
||||||
|
return UniqueType.UniqueComplianceErrorSeverity.WarningOnly
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Stats("stats"){
|
||||||
|
override fun getErrorSeverity(parameterText: String, ruleset: Ruleset):
|
||||||
|
UniqueType.UniqueComplianceErrorSeverity? {
|
||||||
|
if (!com.unciv.models.stats.Stats.isStats(parameterText))
|
||||||
|
return UniqueType.UniqueComplianceErrorSeverity.RulesetInvariant
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
},
|
||||||
|
CityFilter("cityFilter"){
|
||||||
|
override fun getErrorSeverity(parameterText: String, ruleset: Ruleset):
|
||||||
|
UniqueType.UniqueComplianceErrorSeverity? {
|
||||||
|
if (parameterText !in cityFilterMap)
|
||||||
|
return UniqueType.UniqueComplianceErrorSeverity.RulesetInvariant
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Unknown("param") {
|
||||||
|
override fun getErrorSeverity(parameterText: String, ruleset: Ruleset):
|
||||||
|
UniqueType.UniqueComplianceErrorSeverity? {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
abstract fun getErrorSeverity(parameterText:String, ruleset: Ruleset): UniqueType.UniqueComplianceErrorSeverity?
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
val unitTypeStrings = hashSetOf(
|
||||||
|
"Military",
|
||||||
|
"Civilian",
|
||||||
|
"non-air",
|
||||||
|
"relevant",
|
||||||
|
"Nuclear Weapon",
|
||||||
|
"City",
|
||||||
|
// These are up for debate
|
||||||
|
"Air",
|
||||||
|
"land units",
|
||||||
|
"water units",
|
||||||
|
"air units",
|
||||||
|
"military units",
|
||||||
|
"submarine units",
|
||||||
|
// Note: this can't handle combinations of parameters (e.g. [{Military} {Water}])
|
||||||
|
)
|
||||||
|
|
||||||
|
val cityFilterMap = setOf( // taken straight from the translation!
|
||||||
|
"in this city",
|
||||||
|
"in all cities",
|
||||||
|
"in all coastal cities",
|
||||||
|
"in capital",
|
||||||
|
"in all non-occupied cities",
|
||||||
|
"in all cities with a world wonder",
|
||||||
|
"in all cities connected to capital",
|
||||||
|
"in all cities with a garrison",
|
||||||
|
"in all cities in which the majority religion is a major religion",
|
||||||
|
"in all cities in which the majority religion is an enhanced religion",
|
||||||
|
"in non-enemy foreign cities",
|
||||||
|
"in foreign cities",
|
||||||
|
"in annexed cities",
|
||||||
|
"in holy cities",
|
||||||
|
"in City-State cities",
|
||||||
|
"in cities following this religion",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class UniqueComplianceError(
|
||||||
|
val parameterName: String,
|
||||||
|
val acceptableParameterTypes: List<UniqueParameterType>,
|
||||||
|
val errorSeverity: UniqueType.UniqueComplianceErrorSeverity
|
||||||
|
)
|
@ -220,24 +220,6 @@ object TranslationFileWriter {
|
|||||||
"Building"
|
"Building"
|
||||||
)) }
|
)) }
|
||||||
val unitTypeMap = ruleset.unitTypes.keys.toMutableSet().apply { addAll(UniqueParameterType.unitTypeStrings) }
|
val unitTypeMap = ruleset.unitTypes.keys.toMutableSet().apply { addAll(UniqueParameterType.unitTypeStrings) }
|
||||||
val cityFilterMap = setOf(
|
|
||||||
"in this city",
|
|
||||||
"in all cities",
|
|
||||||
"in all coastal cities",
|
|
||||||
"in capital",
|
|
||||||
"in all non-occupied cities",
|
|
||||||
"in all cities with a world wonder",
|
|
||||||
"in all cities connected to capital",
|
|
||||||
"in all cities with a garrison",
|
|
||||||
"in all cities in which the majority religion is a major religion",
|
|
||||||
"in all cities in which the majority religion is an enhanced religion",
|
|
||||||
"in non-enemy foreign cities",
|
|
||||||
"in foreign cities",
|
|
||||||
"in annexed cities",
|
|
||||||
"in holy cities",
|
|
||||||
"in City-State cities",
|
|
||||||
"in cities following this religion",
|
|
||||||
)
|
|
||||||
|
|
||||||
val startMillis = System.currentTimeMillis()
|
val startMillis = System.currentTimeMillis()
|
||||||
|
|
||||||
@ -283,7 +265,7 @@ object TranslationFileWriter {
|
|||||||
parameter in buildingMap -> "building"
|
parameter in buildingMap -> "building"
|
||||||
parameter in unitTypeMap -> "unitType"
|
parameter in unitTypeMap -> "unitType"
|
||||||
Stats.isStats(parameter) -> "stats"
|
Stats.isStats(parameter) -> "stats"
|
||||||
parameter in cityFilterMap -> "cityFilter"
|
parameter in UniqueParameterType.cityFilterMap -> "cityFilter"
|
||||||
else -> "param"
|
else -> "param"
|
||||||
}
|
}
|
||||||
if (parameterName in existingParameterNames) {
|
if (parameterName in existingParameterNames) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user