diff --git a/build.gradle.kts b/build.gradle.kts index 5b1374e..ccbb78c 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -40,6 +40,7 @@ subprojects { keep("class fr.username404.snowygui.fabric.** { * ; }") keep("class fr.username404.snowygui.forge.** { * ; }") keepclassmembers("class fr.username404.snowygui.** { public protected ; }") + // TODO Fix kotlin keepattributes(); keepdirectories(); keeppackagenames(); keepparameternames() obfuscationdictionary("$dictionariesDir/dictionary.txt") classobfuscationdictionary("$dictionariesDir/classdictionary.txt") @@ -65,6 +66,7 @@ subprojects { exclude(module = "kotlin-stdlib-common") exclude(module = "annotations") } + "io.github.config4k:config4k:0.4.2".also { implementation(it); shadowC(it) } "minecraft"("com.mojang:minecraft:${rootProject.property("minecraft")}") "mappings"(MappingsDep) } diff --git a/common/src/main/java/fr/username404/snowygui/mixins/KeyMappings.java b/common/src/main/java/fr/username404/snowygui/mixins/KeyMappings.java index 0829381..52b48cb 100644 --- a/common/src/main/java/fr/username404/snowygui/mixins/KeyMappings.java +++ b/common/src/main/java/fr/username404/snowygui/mixins/KeyMappings.java @@ -1,7 +1,7 @@ package fr.username404.snowygui.mixins; import com.google.common.collect.Lists; -import fr.username404.snowygui.config.AddKeyMaps; +import fr.username404.snowygui.misc.AddKeyMaps; import net.minecraft.client.KeyMapping; import net.minecraft.client.Minecraft; import net.minecraft.client.Options; diff --git a/common/src/main/kotlin/fr/username404/snowygui/Snowy.kt b/common/src/main/kotlin/fr/username404/snowygui/Snowy.kt index 242fb68..2019ac4 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/Snowy.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/Snowy.kt @@ -1,15 +1,16 @@ package fr.username404.snowygui import fr.username404.snowygui.EventSnowy.Companion.useKey -import fr.username404.snowygui.config.AddKeyMaps +import fr.username404.snowygui.config.Configuration.obtained +import fr.username404.snowygui.misc.AddKeyMaps +import io.github.config4k.getValue import org.apache.logging.log4j.LogManager import org.apache.logging.log4j.Logger abstract class Snowy { + private val displayInitMessage: Boolean by obtained companion object { - fun onEvent(e: String, lambda: argsLambda) { - useKey(e).add(lambda) - } + fun onEvent(e: String, lambda: argsLambda) = useKey(e).add(lambda) @JvmStatic val logs: Logger = LogManager.getLogger() } @@ -23,7 +24,7 @@ abstract class Snowy { } } fun atInit() { - logs.info("Init point of SnowyGUI hit.") + if (displayInitMessage) logs.info("Init point of SnowyGUI hit.") eventsInit() } } \ No newline at end of file diff --git a/common/src/main/kotlin/fr/username404/snowygui/config/Configuration.kt b/common/src/main/kotlin/fr/username404/snowygui/config/Configuration.kt new file mode 100644 index 0000000..ff0eea1 --- /dev/null +++ b/common/src/main/kotlin/fr/username404/snowygui/config/Configuration.kt @@ -0,0 +1,34 @@ +package fr.username404.snowygui.config + +import com.typesafe.config.Config +import com.typesafe.config.ConfigException +import com.typesafe.config.ConfigFactory +import fr.username404.snowygui.Snowy +import net.minecraft.client.Minecraft +import java.io.File + +object Configuration { + private val file: File = File(Minecraft.getInstance().gameDirectory.absolutePath + File.separator + "snowy.conf") + private val base = """ + |Snowy { + | displayInitMessage = true + |} + """.trimMargin() + val obtained: Config = run { + var result: Config? = null + with(file) { + if (!exists()) { + createNewFile() + setWritable(true) + writeText(base) + setReadable(true) + } else result = try { + ConfigFactory.parseFile(file) + } catch (e: ConfigException) { + Snowy.logs.warn("Could not parse the snowy configuration file, the default configuration will be used instead."); null + } + } + if (result == null) result = ConfigFactory.parseString(base) + ConfigFactory.load(result).getConfig("Snowy") + } +} diff --git a/common/src/main/kotlin/fr/username404/snowygui/config/AddKeyMaps.kt b/common/src/main/kotlin/fr/username404/snowygui/misc/AddKeyMaps.kt similarity index 90% rename from common/src/main/kotlin/fr/username404/snowygui/config/AddKeyMaps.kt rename to common/src/main/kotlin/fr/username404/snowygui/misc/AddKeyMaps.kt index 002df80..f24c2d9 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/config/AddKeyMaps.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/misc/AddKeyMaps.kt @@ -1,7 +1,8 @@ -package fr.username404.snowygui.config +package fr.username404.snowygui.misc import com.mojang.blaze3d.platform.InputConstants import fr.username404.snowygui.ClickGui +import fr.username404.snowygui.config.SnowyConfigScreen import net.minecraft.client.KeyMapping import net.minecraft.client.Minecraft import org.lwjgl.glfw.GLFW.GLFW_KEY_U