Initialize every button in Snowy.kt

This commit is contained in:
Username404-59 2021-05-15 17:15:24 +02:00
parent 9122d5f007
commit 3d08c24c17
Signed by: Username404-59
GPG Key ID: 7AB361FBB257A5D1
2 changed files with 15 additions and 1 deletions

View File

@ -80,7 +80,8 @@ subprojects {
listOf( listOf(
"$kotlinX:kotlinx-datetime:0.2.0", "$kotlinX:kotlinx-datetime:0.2.0",
"com.typesafe:config:1.4.1", "com.typesafe:config:1.4.1",
"io.github.config4k:config4k:0.4.2" "io.github.config4k:config4k:0.4.2",
"org.reflections:reflections:0.9.12"
).forEach { implementation(it); shadowC(it) { isTransitive = false } } ).forEach { implementation(it); shadowC(it) { isTransitive = false } }
"minecraft"("com.mojang:minecraft:${rootProject.property("minecraft")}") "minecraft"("com.mojang:minecraft:${rootProject.property("minecraft")}")
"mappings"(mappingsDep) "mappings"(mappingsDep)
@ -120,6 +121,7 @@ allprojects {
withType(ShadowJar::class) { withType(ShadowJar::class) {
relocate("kotlinx-datetime", "${rootProject.group}.kotlinx-datetime") relocate("kotlinx-datetime", "${rootProject.group}.kotlinx-datetime")
relocate("org.jetbrains", "${rootProject.group}.jetbrainslibs") relocate("org.jetbrains", "${rootProject.group}.jetbrainslibs")
relocate("org.reflections", "${rootProject.group}.reflectionlib")
relocate("com.typesafe.config", "${rootProject.group}.typesafe.config") relocate("com.typesafe.config", "${rootProject.group}.typesafe.config")
relocate("io.github.config4k", "${rootProject.group}.config4k") relocate("io.github.config4k", "${rootProject.group}.config4k")
relocate("net.arikia.dev.drpc", "${rootProject.group}.drpc") relocate("net.arikia.dev.drpc", "${rootProject.group}.drpc")

View File

@ -2,14 +2,17 @@ package fr.username404.snowygui
import fr.username404.snowygui.EventSnowy.Companion.useKey import fr.username404.snowygui.EventSnowy.Companion.useKey
import fr.username404.snowygui.config.Configuration.obtained import fr.username404.snowygui.config.Configuration.obtained
import fr.username404.snowygui.gui.feature.ButtonInfo
import fr.username404.snowygui.misc.AddKeyMaps import fr.username404.snowygui.misc.AddKeyMaps
import io.github.config4k.getValue import io.github.config4k.getValue
import org.apache.logging.log4j.LogManager import org.apache.logging.log4j.LogManager
import org.apache.logging.log4j.Logger import org.apache.logging.log4j.Logger
import org.reflections.Reflections
abstract class Snowy { abstract class Snowy {
private val displayInitMessage: Boolean by obtained private val displayInitMessage: Boolean by obtained
companion object { companion object {
val reflections = Reflections("fr.username404.snowygui")
fun onEvent(e: String, lambda: argsLambda) = useKey(e).add(lambda) fun onEvent(e: String, lambda: argsLambda) = useKey(e).add(lambda)
@JvmField @JvmField
val logs: Logger = LogManager.getLogger() val logs: Logger = LogManager.getLogger()
@ -25,6 +28,15 @@ abstract class Snowy {
} }
fun atInit() { fun atInit() {
if (displayInitMessage) logs.info("Init point of SnowyGUI hit.") if (displayInitMessage) logs.info("Init point of SnowyGUI hit.")
reflections.getTypesAnnotatedWith(ButtonInfo::class.java).forEach { // Initializes every button
logs.info(
try {
it.getConstructor().newInstance()
} catch (e: NoSuchMethodException) {
it.kotlin.objectInstance
}
)
}
eventsInit() eventsInit()
} }
} }