completely abolishing GSON; new save format impl wip

This commit is contained in:
minjaesong
2021-08-23 16:55:51 +09:00
parent df1ebdf93d
commit e15d5c9b05
58 changed files with 421 additions and 2101 deletions

View File

@@ -1,5 +1,7 @@
package net.torvald.terrarum.utils
import com.badlogic.gdx.utils.JsonReader
import com.badlogic.gdx.utils.JsonValue
import net.torvald.terrarum.AppLoader.printdbg
/**
@@ -10,7 +12,7 @@ object JsonFetcher {
private var jsonString: StringBuffer? = null
@Throws(java.nio.file.NoSuchFileException::class)
operator fun invoke(jsonFilePath: String): com.google.gson.JsonObject {
operator fun invoke(jsonFilePath: String): JsonValue {
jsonString = StringBuffer() // reset buffer every time it called
readJsonFileAsString(jsonFilePath)
@@ -20,14 +22,11 @@ object JsonFetcher {
throw Error("[JsonFetcher] jsonString is null!")
}
val jsonParser = com.google.gson.JsonParser()
val jsonObj = jsonParser.parse(jsonString.toString()).asJsonObject
return jsonObj
return JsonReader().parse(jsonString.toString())
}
@Throws(java.nio.file.NoSuchFileException::class)
operator fun invoke(jsonFile: java.io.File): com.google.gson.JsonObject {
operator fun invoke(jsonFile: java.io.File): JsonValue {
jsonString = StringBuffer() // reset buffer every time it called
readJsonFileAsString(jsonFile.canonicalPath)
@@ -37,10 +36,7 @@ object JsonFetcher {
throw Error("[JsonFetcher] jsonString is null!")
}
val jsonParser = com.google.gson.JsonParser()
val jsonObj = jsonParser.parse(jsonString.toString()).asJsonObject
return jsonObj
return JsonReader().parse(jsonString.toString())
}
@Throws(java.nio.file.NoSuchFileException::class)
@@ -50,4 +46,14 @@ object JsonFetcher {
) // JSON does not require line break
}
fun forEach(map: JsonValue, action: (String, JsonValue) -> Unit) {
var counter = 0
var entry = map.child
while (entry != null) {
action(entry.name ?: "(arrayindex $counter)", entry)
entry = entry.next
counter += 1
}
}
}