Add kotlinx-coroutines + kotlinx-datetime, and save Configuration.obtained when it is constructed
This commit is contained in:
parent
282f873da4
commit
c2b87fddbc
|
@ -26,6 +26,7 @@ architectury {
|
|||
minecraft = rootProject.property("minecraft") as String
|
||||
}
|
||||
|
||||
val kotlinX: String = "org.jetbrains.kotlinx"
|
||||
subprojects {
|
||||
group = rootProject.group.toString()
|
||||
lateinit var mappingsDep: Dependency
|
||||
|
@ -78,7 +79,11 @@ subprojects {
|
|||
exclude(module = "kotlin-stdlib-common")
|
||||
exclude(module = "annotations")
|
||||
}
|
||||
"io.github.config4k:config4k:0.4.2".also { implementation(it); shadowC(it) }
|
||||
listOf(
|
||||
"$kotlinX:kotlinx-coroutines-core:1.5.0-RC",
|
||||
"$kotlinX:kotlinx-datetime:0.2.0",
|
||||
"io.github.config4k:config4k:0.4.2"
|
||||
).forEach { implementation(it); shadowC(it) }
|
||||
"minecraft"("com.mojang:minecraft:${rootProject.property("minecraft")}")
|
||||
"mappings"(mappingsDep)
|
||||
}
|
||||
|
@ -98,6 +103,7 @@ allprojects {
|
|||
tasks {
|
||||
withType(ShadowJar::class) {
|
||||
relocate("kotlin", "${rootProject.group}.kotlin")
|
||||
relocate("org.jetbrains", "${rootProject.group}.jetbrainslibs")
|
||||
relocate("com.typesafe.config", "${rootProject.group}.typesafe.config")
|
||||
relocate("io.github.config4k", "${rootProject.group}.config4k")
|
||||
exclude("**/*.kotlin_metadata")
|
||||
|
|
|
@ -6,6 +6,9 @@ import com.typesafe.config.ConfigFactory
|
|||
import com.typesafe.config.ConfigRenderOptions
|
||||
import fr.username404.snowygui.Snowy
|
||||
import io.github.config4k.extract
|
||||
import kotlinx.coroutines.coroutineScope
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import net.minecraft.client.Minecraft
|
||||
import java.io.File
|
||||
|
||||
|
@ -17,6 +20,24 @@ object Configuration {
|
|||
|}
|
||||
""".trimMargin()
|
||||
private val baseConf = ConfigFactory.parseString(base)
|
||||
private suspend fun writeConfig(c: Config) = coroutineScope {
|
||||
launch {
|
||||
file.writeText(
|
||||
"""
|
||||
Snowy {
|
||||
${
|
||||
c.root().render(
|
||||
ConfigRenderOptions.defaults()
|
||||
.setFormatted(true)
|
||||
.setJson(false)
|
||||
.setOriginComments(false)
|
||||
).trimEnd()
|
||||
}
|
||||
}
|
||||
""".trimIndent()
|
||||
)
|
||||
}
|
||||
}
|
||||
@JvmField
|
||||
val obtained: Config = run {
|
||||
var result: Config = baseConf
|
||||
|
@ -32,24 +53,15 @@ object Configuration {
|
|||
}
|
||||
}
|
||||
ConfigFactory.load(result).extract<Config>("Snowy").resolveWith(baseConf)
|
||||
}.also {
|
||||
runBlocking {
|
||||
writeConfig(it)
|
||||
}
|
||||
}
|
||||
init {
|
||||
Runtime.getRuntime().addShutdownHook(
|
||||
Thread {
|
||||
file.writeText(
|
||||
"""
|
||||
Snowy {
|
||||
${
|
||||
obtained.root().render(
|
||||
ConfigRenderOptions.defaults()
|
||||
.setFormatted(true)
|
||||
.setJson(false)
|
||||
.setOriginComments(false)
|
||||
).trimEnd()
|
||||
}
|
||||
}
|
||||
""".trimIndent()
|
||||
)
|
||||
runBlocking { writeConfig(obtained).join() }
|
||||
}
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue