From e927ef6f640644283db5b703c49012c58e5dd3be Mon Sep 17 00:00:00 2001 From: SomeTroglodyte <63000004+SomeTroglodyte@users.noreply.github.com> Date: Wed, 25 May 2022 18:33:17 +0200 Subject: [PATCH] ImageGetter.getDrawable a few ns faster (#6936) --- core/src/com/unciv/ui/images/ImageGetter.kt | 3 +-- core/src/com/unciv/ui/utils/ExtensionFunctions.kt | 12 ++++++------ 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/core/src/com/unciv/ui/images/ImageGetter.kt b/core/src/com/unciv/ui/images/ImageGetter.kt index 8bcfb3f90a..57f97f5887 100644 --- a/core/src/com/unciv/ui/images/ImageGetter.kt +++ b/core/src/com/unciv/ui/images/ImageGetter.kt @@ -170,8 +170,7 @@ object ImageGetter { } fun getDrawable(fileName: String?): TextureRegionDrawable { - return if (fileName != null && textureRegionDrawables.containsKey(fileName)) textureRegionDrawables[fileName]!! - else textureRegionDrawables[whiteDotLocation]!! + return textureRegionDrawables[fileName] ?: textureRegionDrawables[whiteDotLocation]!! } fun getRoundedEdgeRectangle(tintColor: Color? = null): NinePatchDrawable { diff --git a/core/src/com/unciv/ui/utils/ExtensionFunctions.kt b/core/src/com/unciv/ui/utils/ExtensionFunctions.kt index 046886f16e..6b306fe8ca 100644 --- a/core/src/com/unciv/ui/utils/ExtensionFunctions.kt +++ b/core/src/com/unciv/ui/utils/ExtensionFunctions.kt @@ -57,13 +57,13 @@ fun Color.darken(t: Float): Color = Color(this).lerp(Color.BLACK, t) * The result is returned as a new instance. */ fun Color.brighten(t: Float): Color = Color(this).lerp(Color.WHITE, t) -fun Actor.centerX(parent: Actor){ x = parent.width/2 - width/2 } -fun Actor.centerY(parent: Actor){ y = parent.height/2- height/2} -fun Actor.center(parent: Actor){ centerX(parent); centerY(parent)} +fun Actor.centerX(parent: Actor) { x = parent.width / 2 - width / 2 } +fun Actor.centerY(parent: Actor) { y = parent.height / 2 - height / 2 } +fun Actor.center(parent: Actor) { centerX(parent); centerY(parent) } -fun Actor.centerX(parent: Stage){ x = parent.width/2 - width/2 } -fun Actor.centerY(parent: Stage){ y = parent.height/2- height/2} -fun Actor.center(parent: Stage){ centerX(parent); centerY(parent)} +fun Actor.centerX(parent: Stage) { x = parent.width / 2 - width / 2 } +fun Actor.centerY(parent: Stage) { y = parent.height / 2 - height / 2 } +fun Actor.center(parent: Stage) { centerX(parent); centerY(parent) } /** same as [onClick], but sends the [InputEvent] and coordinates along */ fun Actor.onClickEvent(sound: UncivSound = UncivSound.Click, function: (event: InputEvent?, x: Float, y: Float) -> Unit) {