Add a configuration made using the config4k library

This commit is contained in:
Username404-59 2021-04-16 22:44:03 +02:00
parent 8651c34ed7
commit dac1294ee3
Signed by: Username404-59
GPG Key ID: 7AB361FBB257A5D1
5 changed files with 45 additions and 7 deletions

View File

@ -40,6 +40,7 @@ subprojects {
keep("class fr.username404.snowygui.fabric.** { * ; }")
keep("class fr.username404.snowygui.forge.** { * ; }")
keepclassmembers("class fr.username404.snowygui.** { public protected <methods>; }")
// 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)
}

View File

@ -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;

View File

@ -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()
}
}

View File

@ -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")
}
}

View File

@ -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