mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-28 06:16:37 -04:00
performance: #10173 - Use string-to-type map to initialize type for uniques, this is the major time component of unique creation
This commit is contained in:
parent
5d22482a56
commit
f69209029d
@ -21,7 +21,7 @@ class Unique(val text: String, val sourceObjectType: UniqueTarget? = null, val s
|
|||||||
* - for instance, in the city screen, we call every tile unique for every tile, which can lead to ANRs */
|
* - for instance, in the city screen, we call every tile unique for every tile, which can lead to ANRs */
|
||||||
val placeholderText = text.getPlaceholderText()
|
val placeholderText = text.getPlaceholderText()
|
||||||
val params = text.getPlaceholderParameters()
|
val params = text.getPlaceholderParameters()
|
||||||
val type = UniqueType.values().firstOrNull { it.placeholderText == placeholderText }
|
val type = UniqueType.uniqueTypeMap[placeholderText]
|
||||||
|
|
||||||
val stats: Stats by lazy {
|
val stats: Stats by lazy {
|
||||||
val firstStatParam = params.firstOrNull { Stats.isStats(it) }
|
val firstStatParam = params.firstOrNull { Stats.isStats(it) }
|
||||||
@ -41,7 +41,7 @@ class Unique(val text: String, val sourceObjectType: UniqueTarget? = null, val s
|
|||||||
fun hasFlag(flag: UniqueFlag) = type != null && type.flags.contains(flag)
|
fun hasFlag(flag: UniqueFlag) = type != null && type.flags.contains(flag)
|
||||||
|
|
||||||
fun hasTriggerConditional(): Boolean {
|
fun hasTriggerConditional(): Boolean {
|
||||||
if(conditionals.none()) return false
|
if (conditionals.none()) return false
|
||||||
return conditionals.any { conditional ->
|
return conditionals.any { conditional ->
|
||||||
conditional.type?.targetTypes?.any {
|
conditional.type?.targetTypes?.any {
|
||||||
it.canAcceptUniqueTarget(UniqueTarget.TriggerCondition) || it.canAcceptUniqueTarget(UniqueTarget.UnitActionModifier)
|
it.canAcceptUniqueTarget(UniqueTarget.TriggerCondition) || it.canAcceptUniqueTarget(UniqueTarget.UnitActionModifier)
|
||||||
|
@ -1192,4 +1192,8 @@ enum class UniqueType(val text: String, vararg targets: UniqueTarget, val flags:
|
|||||||
/** Checks whether a specific [uniqueTarget] as e.g. given by [IHasUniques.getUniqueTarget] works with `this` UniqueType */
|
/** Checks whether a specific [uniqueTarget] as e.g. given by [IHasUniques.getUniqueTarget] works with `this` UniqueType */
|
||||||
fun canAcceptUniqueTarget(uniqueTarget: UniqueTarget) =
|
fun canAcceptUniqueTarget(uniqueTarget: UniqueTarget) =
|
||||||
targetTypes.any { uniqueTarget.canAcceptUniqueTarget(it) }
|
targetTypes.any { uniqueTarget.canAcceptUniqueTarget(it) }
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
val uniqueTypeMap: Map<String, UniqueType> = UniqueType.values().associateBy { it.placeholderText }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user