Use gson instead of kotlinx-serialization
This commit is contained in:
parent
a4802088ea
commit
22009a53f1
|
@ -11,7 +11,6 @@ buildscript {
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
kotlin("jvm") version "1.5.0"
|
kotlin("jvm") version "1.5.0"
|
||||||
kotlin("plugin.serialization") version "1.5.0"
|
|
||||||
id("com.github.johnrengelman.shadow") version "6.1.0" apply false
|
id("com.github.johnrengelman.shadow") version "6.1.0" apply false
|
||||||
id("architectury-plugin") version "[3.0.100, 3.3["
|
id("architectury-plugin") version "[3.0.100, 3.3["
|
||||||
id("dev.architectury.loom") version "0.7.2.110" apply false
|
id("dev.architectury.loom") version "0.7.2.110" apply false
|
||||||
|
@ -72,7 +71,7 @@ subprojects {
|
||||||
exclude("**/*.kotlin_metadata")
|
exclude("**/*.kotlin_metadata")
|
||||||
exclude("**/*.kotlin_builtins")
|
exclude("**/*.kotlin_builtins")
|
||||||
exclude("META-INF/maven/**/*")
|
exclude("META-INF/maven/**/*")
|
||||||
archiveClassifier.set("shadow")
|
archiveClassifier.set("shadow-${this@subprojects.name}")
|
||||||
}
|
}
|
||||||
val shadowJar = getByName("shadowJar") as ShadowJar
|
val shadowJar = getByName("shadowJar") as ShadowJar
|
||||||
val shrinkJar = register("shrinkJar", proguard.gradle.ProGuardTask::class) { group = this@subprojects.group as String
|
val shrinkJar = register("shrinkJar", proguard.gradle.ProGuardTask::class) { group = this@subprojects.group as String
|
||||||
|
@ -94,12 +93,7 @@ subprojects {
|
||||||
adaptclassstrings()
|
adaptclassstrings()
|
||||||
"$group.**".also { dontnote(it); dontwarn(it) }
|
"$group.**".also { dontnote(it); dontwarn(it) }
|
||||||
|
|
||||||
// kotlinx-serialization related configuration:
|
dontwarn("kotlinx.serialization.**")
|
||||||
dontnote("kotlinx.serialization.AnnotationsKt")
|
|
||||||
keepclasseswithmembers("class kotlinx.serialization.json.** { kotlinx.serialization.KSerializer serializer(...); }")
|
|
||||||
keep(mapOf("includedescriptorclasses" to true), "class $group.snowygui.**$\$serializer { * ; }")
|
|
||||||
keepclassmembers("class $group.snowygui.** { *** Companion; }")
|
|
||||||
keepclasseswithmembers("class $group.snowygui.** { kotlinx.serialization.KSerializer serializer(...); }")
|
|
||||||
|
|
||||||
val homeDir = System.getProperty("java.home") as String
|
val homeDir = System.getProperty("java.home") as String
|
||||||
doFirst {
|
doFirst {
|
||||||
|
@ -151,17 +145,13 @@ allprojects {
|
||||||
**/
|
**/
|
||||||
apply(plugin = "java")
|
apply(plugin = "java")
|
||||||
apply(plugin = "org.jetbrains.kotlin.jvm")
|
apply(plugin = "org.jetbrains.kotlin.jvm")
|
||||||
apply(plugin = "org.jetbrains.kotlin.plugin.serialization")
|
|
||||||
apply(plugin = "architectury-plugin")
|
apply(plugin = "architectury-plugin")
|
||||||
java {
|
java {
|
||||||
sourceCompatibility = JavaVersion.VERSION_11
|
sourceCompatibility = JavaVersion.VERSION_11
|
||||||
}
|
}
|
||||||
val serializationVer: String by rootProject
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation(kotlin("stdlib-jdk8", kotlinVer))
|
implementation(kotlin("stdlib-jdk8", kotlinVer))
|
||||||
implementation(kotlin("reflect", kotlinVer))
|
implementation(kotlin("reflect", kotlinVer))
|
||||||
implementation("$kotlinX:kotlinx-serialization-core:$serializationVer")
|
|
||||||
implementation("$kotlinX:kotlinx-serialization-json:$serializationVer")
|
|
||||||
annotationProcessor("com.github.bsideup.jabel:jabel-javac-plugin:0.3.0") {
|
annotationProcessor("com.github.bsideup.jabel:jabel-javac-plugin:0.3.0") {
|
||||||
listOf("byte-buddy", "byte-buddy-agent").forEach {
|
listOf("byte-buddy", "byte-buddy-agent").forEach {
|
||||||
exclude(module = it)
|
exclude(module = it)
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package fr.username404.snowygui
|
package fr.username404.snowygui
|
||||||
|
|
||||||
|
import com.google.gson.Gson
|
||||||
|
import com.google.gson.GsonBuilder
|
||||||
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.misc.AddKeyMaps
|
import fr.username404.snowygui.misc.AddKeyMaps
|
||||||
|
@ -10,6 +12,7 @@ import org.apache.logging.log4j.Logger
|
||||||
abstract class Snowy {
|
abstract class Snowy {
|
||||||
private val displayInitMessage: Boolean by obtained
|
private val displayInitMessage: Boolean by obtained
|
||||||
companion object {
|
companion object {
|
||||||
|
val Gson: Gson = GsonBuilder().excludeFieldsWithoutExposeAnnotation().create()
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
protected val FeaturePackage: String = "fr.username404.snowygui.gui.feature"
|
protected val FeaturePackage: String = "fr.username404.snowygui.gui.feature"
|
||||||
lateinit var annotatedButtons: Set<Class<*>>
|
lateinit var annotatedButtons: Set<Class<*>>
|
||||||
|
|
|
@ -13,9 +13,6 @@ import io.github.config4k.extract
|
||||||
import kotlinx.coroutines.coroutineScope
|
import kotlinx.coroutines.coroutineScope
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.runBlocking
|
||||||
import kotlinx.serialization.decodeFromString
|
|
||||||
import kotlinx.serialization.encodeToString
|
|
||||||
import kotlinx.serialization.json.Json
|
|
||||||
import net.minecraft.client.Minecraft
|
import net.minecraft.client.Minecraft
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.nio.charset.Charset
|
import java.nio.charset.Charset
|
||||||
|
@ -78,8 +75,8 @@ object Configuration {
|
||||||
val macros: MutableSet<Macro> = run {
|
val macros: MutableSet<Macro> = run {
|
||||||
if (!macroFile.exists()) macroFile.createNewFile()
|
if (!macroFile.exists()) macroFile.createNewFile()
|
||||||
macroFile.readLines(Charset.forName("UTF-8")).map {
|
macroFile.readLines(Charset.forName("UTF-8")).map {
|
||||||
Json.decodeFromString<Macro>(it)
|
Snowy.Gson.fromJson(it, Macro::class.java)
|
||||||
}.toMutableSet()
|
}.map { it.copy() }.toMutableSet()
|
||||||
}
|
}
|
||||||
init {
|
init {
|
||||||
Runtime.getRuntime().addShutdownHook(
|
Runtime.getRuntime().addShutdownHook(
|
||||||
|
@ -94,7 +91,7 @@ object Configuration {
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
macros.map { Json.encodeToString(it) }.forEachIndexed { index, s ->
|
macros.map { Snowy.Gson.toJson(it) }.forEachIndexed { index, s ->
|
||||||
with(macroFile) {
|
with(macroFile) {
|
||||||
"$s\n".let {
|
"$s\n".let {
|
||||||
if (index == 0) {
|
if (index == 0) {
|
||||||
|
|
|
@ -1,14 +1,13 @@
|
||||||
package fr.username404.snowygui.gui.feature
|
package fr.username404.snowygui.gui.feature
|
||||||
|
|
||||||
|
import com.google.gson.annotations.Expose
|
||||||
import net.minecraft.client.Minecraft
|
import net.minecraft.client.Minecraft
|
||||||
import kotlinx.serialization.*
|
|
||||||
import fr.username404.snowygui.gui.feature.ButtonInfo.Companion.Type
|
import fr.username404.snowygui.gui.feature.ButtonInfo.Companion.Type
|
||||||
|
|
||||||
@Serializable
|
|
||||||
@ButtonInfo(Category.MACROS, kind = Type.CLICK)
|
@ButtonInfo(Category.MACROS, kind = Type.CLICK)
|
||||||
data class Macro(
|
data class Macro(
|
||||||
private val command: String,
|
@Expose private val command: String,
|
||||||
override val title: String = command
|
@Expose override val title: String = command
|
||||||
): ButtonImpl() {
|
): ButtonImpl() {
|
||||||
override fun execAction() = Minecraft.getInstance().player!!.chat("/$command")
|
override fun execAction() = Minecraft.getInstance().player!!.chat("/$command")
|
||||||
}
|
}
|
|
@ -9,8 +9,7 @@ dependencies {
|
||||||
implementation("thedarkcolour:kotlinforforge:${rootProject.property("kotlinforforge")}.0")
|
implementation("thedarkcolour:kotlinforforge:${rootProject.property("kotlinforforge")}.0")
|
||||||
implementation(project(path = ":common")) { isTransitive = false }
|
implementation(project(path = ":common")) { isTransitive = false }
|
||||||
add("developmentForge", project(path = ":common")) { isTransitive = false }
|
add("developmentForge", project(path = ":common")) { isTransitive = false }
|
||||||
shadowC("org.jetbrains.kotlinx:kotlinx-serialization-core:$serializationVer") { isTransitive = false }
|
shadowC("org.jetbrains.kotlinx:kotlinx-serialization-core:$serializationVer") { isTransitive = false } // Needed for kotlinx-datetime
|
||||||
shadowC("org.jetbrains.kotlinx:kotlinx-serialization-json:$serializationVer") { isTransitive = false }
|
|
||||||
shadowC(project(path = ":common", configuration = "transformProductionForge")) { isTransitive = false }
|
shadowC(project(path = ":common", configuration = "transformProductionForge")) { isTransitive = false }
|
||||||
}; loom {
|
}; loom {
|
||||||
useFabricMixin = true
|
useFabricMixin = true
|
||||||
|
|
|
@ -42,7 +42,7 @@ class ForgeInit: Snowy() {
|
||||||
(data!!.javaClass.getDeclaredField("clazz").apply { isAccessible = true }.get(data) as Type).className.let { classname ->
|
(data!!.javaClass.getDeclaredField("clazz").apply { isAccessible = true }.get(data) as Type).className.let { classname ->
|
||||||
classname.startsWith(FeaturePackage).let {
|
classname.startsWith(FeaturePackage).let {
|
||||||
it && with(Class.forName(classname)) {
|
it && with(Class.forName(classname)) {
|
||||||
(!kotlin.isAbstract || !kotlin.isData) && declaredAnnotations.any { annotation ->
|
(!(kotlin.isAbstract || kotlin.isData)) && declaredAnnotations.any { annotation ->
|
||||||
annotation is ButtonInfo
|
annotation is ButtonInfo
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue