Skip to content

Commit 49b10bb

Browse files
committed
Nit and enum lambda
1 parent 817acbd commit 49b10bb

File tree

1 file changed

+15
-26
lines changed
  • src/main/kotlin/com/lambda/module/modules/render

1 file changed

+15
-26
lines changed

src/main/kotlin/com/lambda/module/modules/render/Zoom.kt

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,13 @@ import com.lambda.event.events.RenderEvent
2222
import com.lambda.event.listener.SafeListener.Companion.listen
2323
import com.lambda.module.Module
2424
import com.lambda.module.tag.ModuleTag
25+
import com.lambda.util.NamedEnum
2526
import java.lang.Math.clamp
2627

2728
object Zoom : Module(
28-
"Zoom",
29-
"Zooms the current view",
30-
ModuleTag.RENDER
29+
name = "Zoom",
30+
description = "Zooms the current view",
31+
tag = ModuleTag.RENDER,
3132
) {
3233
override val disableOnRelease by setting("Disable On Release", true)
3334
private var zoom by setting("Zoom", 2f, 1f..10f, 0.1f)
@@ -48,8 +49,7 @@ object Zoom : Module(
4849
@JvmStatic var currentZoom = 1f; private set
4950
private var lastZoomTime = 1L
5051
private val zoomProgress
51-
get() =
52-
clamp((System.currentTimeMillis() - lastZoomTime) / (animationDuration * 1000).toDouble(), 0.0, 1.0).toFloat()
52+
get() = clamp((System.currentTimeMillis() - lastZoomTime) / (animationDuration * 1000).toDouble(), 0.0, 1.0).toFloat()
5353

5454
init {
5555
listen<MouseEvent.Scroll> { event ->
@@ -68,6 +68,7 @@ object Zoom : Module(
6868
onEnable {
6969
updateZoomTime()
7070
}
71+
7172
onDisable {
7273
extraZoom = 0f
7374
updateZoomTime()
@@ -81,27 +82,15 @@ object Zoom : Module(
8182
@JvmStatic
8283
fun updateCurrentZoom() {
8384
val target = if (isEnabled) targetZoom else 1f
84-
if (currentZoom == target) return
85-
currentZoom = when (style) {
86-
ZoomStyle.Instant -> target
87-
ZoomStyle.EaseOut -> easeOut(currentZoom, target, zoomProgress)
88-
ZoomStyle.EaseIn -> easeIn(currentZoom, target, zoomProgress)
89-
}
90-
}
91-
92-
private fun easeOut(start: Float, end: Float, progress: Float): Float {
93-
val easedT = 1f - (1f - progress) * (1f - progress)
94-
return start + ((end - start) * easedT)
95-
}
96-
97-
private fun easeIn(start: Float, end: Float, progress: Float): Float {
98-
val easedT = progress * progress
99-
return start + ((end - start) * easedT)
85+
currentZoom = style.apply(currentZoom, target, zoomProgress)
10086
}
10187

102-
private enum class ZoomStyle {
103-
Instant,
104-
EaseOut,
105-
EaseIn
88+
private enum class ZoomStyle(
89+
override val displayName: String,
90+
val apply: (Float, Float, Float) -> Float,
91+
) : NamedEnum {
92+
Instant("Instant", { _, v, _ -> v }),
93+
EaseOut("Ease Out", { start, end, progress -> start + ((end - start) * 1f - (1f - progress) * (1f - progress)) }),
94+
EaseIn("Ease In", { start, end, progress -> start + ((end - start) * progress * progress) })
10695
}
107-
}
96+
}

0 commit comments

Comments
 (0)