mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-16 05:24:06 +09:00
changed lightboxes so that (de)serialiser won't complain; world/actor json will will write game version it saved
This commit is contained in:
@@ -46,7 +46,7 @@ object Common {
|
||||
|
||||
// install custom (de)serialiser
|
||||
init {
|
||||
// jsoner.ignoreUnknownFields = true
|
||||
jsoner.ignoreUnknownFields = true
|
||||
jsoner.setUsePrototypes(false)
|
||||
jsoner.setIgnoreDeprecated(false)
|
||||
|
||||
|
||||
@@ -21,16 +21,17 @@ import java.util.*
|
||||
*/
|
||||
object WriteActor {
|
||||
|
||||
// genver must be found on fixed location of the JSON string
|
||||
operator fun invoke(actor: Actor): String {
|
||||
val s = Common.jsoner.toJson(actor, actor.javaClass)
|
||||
return """{"class":"${actor.javaClass.canonicalName}",${s.substring(1)}"""
|
||||
return """{"genver":${Common.GENVER},"class":"${actor.javaClass.canonicalName}",${s.substring(1)}"""
|
||||
}
|
||||
|
||||
fun encodeToByteArray64(actor: Actor): ByteArray64 {
|
||||
val baw = ByteArray64Writer(Common.CHARSET)
|
||||
|
||||
val classDef = """{"class":"${actor.javaClass.canonicalName}""""
|
||||
baw.write(classDef)
|
||||
val header = """{"genver":${Common.GENVER},"class":"${actor.javaClass.canonicalName}""""
|
||||
baw.write(header)
|
||||
Common.jsoner.toJson(actor, actor.javaClass, baw)
|
||||
baw.flush(); baw.close()
|
||||
// by this moment, contents of the baw will be:
|
||||
@@ -39,7 +40,7 @@ object WriteActor {
|
||||
// and we want to turn it into this:
|
||||
// {"class":"some.class.Name","actorValue":{},......}
|
||||
val ba = baw.toByteArray64()
|
||||
ba[classDef.toByteArray(Common.CHARSET).size.toLong()] = ','.code.toByte()
|
||||
ba[header.toByteArray(Common.CHARSET).size.toLong()] = ','.code.toByte()
|
||||
|
||||
return ba
|
||||
}
|
||||
@@ -90,6 +91,7 @@ object WritePlayer {
|
||||
|
||||
|
||||
val actorJson = WriteActor.encodeToByteArray64(player)
|
||||
|
||||
val adl = player.animDesc!!.getRawADL()
|
||||
val adlGlow = player.animDescGlow?.getRawADL() // NULLABLE!
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ object WriteWorld {
|
||||
val world = ingame.world
|
||||
val currentPlayTime_t = time_t - ingame.loadedTime_t
|
||||
|
||||
world.genver = Common.GENVER
|
||||
// world.genver = Common.GENVER
|
||||
world.comp = Common.COMP_GZIP
|
||||
world.lastPlayTime = time_t
|
||||
world.totalPlayTime += currentPlayTime_t
|
||||
@@ -56,17 +56,28 @@ object WriteWorld {
|
||||
return world
|
||||
}
|
||||
|
||||
// genver must be found on fixed location of the JSON string
|
||||
operator fun invoke(ingame: TerrarumIngame, time_t: Long, actorsList: List<Actor>, playersList: List<IngamePlayer>): String {
|
||||
return Common.jsoner.toJson(preWrite(ingame, time_t, actorsList, playersList))
|
||||
val s = Common.jsoner.toJson(preWrite(ingame, time_t, actorsList, playersList))
|
||||
return """{"genver":${Common.GENVER},${s.substring(1)}"""
|
||||
}
|
||||
|
||||
fun encodeToByteArray64(ingame: TerrarumIngame, time_t: Long, actorsList: List<Actor>, playersList: List<IngamePlayer>): ByteArray64 {
|
||||
val baw = ByteArray64Writer(Common.CHARSET)
|
||||
|
||||
val header = """{"genver":${Common.GENVER}"""
|
||||
baw.write(header)
|
||||
Common.jsoner.toJson(preWrite(ingame, time_t, actorsList, playersList), baw)
|
||||
baw.flush(); baw.close()
|
||||
// by this moment, contents of the baw will be:
|
||||
// {"genver":123456{"actorValue":{},......}
|
||||
// (note that first bracket is not closed, and another open bracket after "genver" property)
|
||||
// and we want to turn it into this:
|
||||
// {"genver":123456,"actorValue":{},......}
|
||||
val ba = baw.toByteArray64()
|
||||
ba[header.toByteArray(Common.CHARSET).size.toLong()] = ','.code.toByte()
|
||||
|
||||
return baw.toByteArray64()
|
||||
return ba
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user