Replace the useKey method with a get operator function in EventSnowy.kt
This commit is contained in:
parent
05319d5aeb
commit
5cc5303b32
|
@ -4,12 +4,12 @@ interface EventSnowy {
|
||||||
val type: String
|
val type: String
|
||||||
@SafeVarargs
|
@SafeVarargs
|
||||||
fun <T> fire(vararg args: T?) {
|
fun <T> fire(vararg args: T?) {
|
||||||
useKey(type).forEach {
|
get(type).forEach {
|
||||||
it(args)
|
it(args)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
companion object {
|
companion object {
|
||||||
fun useKey(key: String): MutableSet<argsLambda> = eventMap.getOrPut(key, ::mutableSetOf)
|
operator fun get(key: String): MutableSet<argsLambda> = eventMap.getOrPut(key, ::mutableSetOf)
|
||||||
private val eventMap: MutableMap<String, MutableSet<argsLambda>> = mutableMapOf()
|
private val eventMap: MutableMap<String, MutableSet<argsLambda>> = mutableMapOf()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package fr.username404.snowygui
|
package fr.username404.snowygui
|
||||||
|
|
||||||
import fr.username404.snowygui.EventSnowy.Companion.useKey
|
|
||||||
import fr.username404.snowygui.config.Configuration
|
import fr.username404.snowygui.config.Configuration
|
||||||
import fr.username404.snowygui.gui.feature.ButtonImpl
|
import fr.username404.snowygui.gui.feature.ButtonImpl
|
||||||
import fr.username404.snowygui.gui.feature.ButtonInfo
|
import fr.username404.snowygui.gui.feature.ButtonInfo
|
||||||
|
@ -20,7 +19,7 @@ abstract class Snowy {
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
protected const val FeaturePackage: String = "fr.username404.snowygui.gui.feature"
|
protected const val FeaturePackage: String = "fr.username404.snowygui.gui.feature"
|
||||||
lateinit var annotatedButtons: Set<Class<out ButtonImpl>>
|
lateinit var annotatedButtons: Set<Class<out ButtonImpl>>
|
||||||
fun onEvent(e: Any, lambda: argsLambda) = useKey(e.toString()).add(lambda)
|
fun onEvent(e: Any, lambda: argsLambda) = EventSnowy[e.toString()].add(lambda)
|
||||||
@JvmField
|
@JvmField
|
||||||
val logs: Logger = LogManager.getLogger()
|
val logs: Logger = LogManager.getLogger()
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package fr.username404.snowygui.gui.feature
|
package fr.username404.snowygui.gui.feature
|
||||||
|
|
||||||
import com.mojang.blaze3d.vertex.PoseStack
|
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.argsLambda
|
||||||
import fr.username404.snowygui.gui.Renderable
|
import fr.username404.snowygui.gui.Renderable
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ sealed class ButtonImplWithHud: ButtonImpl() {
|
||||||
protected abstract val hudRenderLambda: Renderable
|
protected abstract val hudRenderLambda: Renderable
|
||||||
private val generatedLambda: argsLambda = { hudRenderLambda.render(it.first() as PoseStack?) }
|
private val generatedLambda: argsLambda = { hudRenderLambda.render(it.first() as PoseStack?) }
|
||||||
final override fun execAction() {
|
final override fun execAction() {
|
||||||
useKey("HudRender").run {
|
EventSnowy["HudRender"].run {
|
||||||
if (toggled) add(generatedLambda)
|
if (toggled) add(generatedLambda)
|
||||||
else remove(generatedLambda)
|
else remove(generatedLambda)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue