mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-22 22:00:24 +07: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:
@ -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 */
|
||||
val placeholderText = text.getPlaceholderText()
|
||||
val params = text.getPlaceholderParameters()
|
||||
val type = UniqueType.values().firstOrNull { it.placeholderText == placeholderText }
|
||||
val type = UniqueType.uniqueTypeMap[placeholderText]
|
||||
|
||||
val stats: Stats by lazy {
|
||||
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 hasTriggerConditional(): Boolean {
|
||||
if(conditionals.none()) return false
|
||||
if (conditionals.none()) return false
|
||||
return conditionals.any { conditional ->
|
||||
conditional.type?.targetTypes?.any {
|
||||
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 */
|
||||
fun canAcceptUniqueTarget(uniqueTarget: UniqueTarget) =
|
||||
targetTypes.any { uniqueTarget.canAcceptUniqueTarget(it) }
|
||||
|
||||
companion object {
|
||||
val uniqueTypeMap: Map<String, UniqueType> = UniqueType.values().associateBy { it.placeholderText }
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user