mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-14 12:34:05 +09:00
completely abolishing GSON; new save format impl wip
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user