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