diff --git a/common/src/main/kotlin/fr/username404/snowygui/EventSnowy.kt b/common/src/main/kotlin/fr/username404/snowygui/EventSnowy.kt index ba8d70f..101b4ee 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/EventSnowy.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/EventSnowy.kt @@ -4,12 +4,12 @@ interface EventSnowy { val type: String @SafeVarargs fun fire(vararg args: T?) { - useKey(type).forEach { + get(type).forEach { it(args) } } companion object { - fun useKey(key: String): MutableSet = eventMap.getOrPut(key, ::mutableSetOf) + operator fun get(key: String): MutableSet = eventMap.getOrPut(key, ::mutableSetOf) private val eventMap: MutableMap> = mutableMapOf() } } diff --git a/common/src/main/kotlin/fr/username404/snowygui/Snowy.kt b/common/src/main/kotlin/fr/username404/snowygui/Snowy.kt index 9a0fa6c..bdf8a4d 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/Snowy.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/Snowy.kt @@ -1,6 +1,5 @@ package fr.username404.snowygui -import fr.username404.snowygui.EventSnowy.Companion.useKey import fr.username404.snowygui.config.Configuration import fr.username404.snowygui.gui.feature.ButtonImpl import fr.username404.snowygui.gui.feature.ButtonInfo @@ -20,7 +19,7 @@ abstract class Snowy { @JvmStatic protected const val FeaturePackage: String = "fr.username404.snowygui.gui.feature" lateinit var annotatedButtons: Set> - fun onEvent(e: Any, lambda: argsLambda) = useKey(e.toString()).add(lambda) + fun onEvent(e: Any, lambda: argsLambda) = EventSnowy[e.toString()].add(lambda) @JvmField val logs: Logger = LogManager.getLogger() } diff --git a/common/src/main/kotlin/fr/username404/snowygui/gui/feature/ButtonImplWithHud.kt b/common/src/main/kotlin/fr/username404/snowygui/gui/feature/ButtonImplWithHud.kt index 32d4bb7..3346a94 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/gui/feature/ButtonImplWithHud.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/gui/feature/ButtonImplWithHud.kt @@ -1,7 +1,7 @@ package fr.username404.snowygui.gui.feature import com.mojang.blaze3d.vertex.PoseStack -import fr.username404.snowygui.EventSnowy.Companion.useKey +import fr.username404.snowygui.EventSnowy import fr.username404.snowygui.argsLambda import fr.username404.snowygui.gui.Renderable @@ -9,7 +9,7 @@ sealed class ButtonImplWithHud: ButtonImpl() { protected abstract val hudRenderLambda: Renderable private val generatedLambda: argsLambda = { hudRenderLambda.render(it.first() as PoseStack?) } final override fun execAction() { - useKey("HudRender").run { + EventSnowy["HudRender"].run { if (toggled) add(generatedLambda) else remove(generatedLambda) }