mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-16 21:44:05 +09:00
serialiser for world
This commit is contained in:
@@ -65,35 +65,35 @@ open class WriteMeta(val ingame: TerrarumIngame) {
|
||||
|
||||
return json
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param b a ByteArray
|
||||
* @return Bytes in [b] which are GZip'd then Ascii85-encoded
|
||||
*/
|
||||
private fun bytesToZipdStr(b: ByteArray): String {
|
||||
val sb = StringBuilder()
|
||||
val bo = ByteArray64GrowableOutputStream()
|
||||
val zo = GZIPOutputStream(bo)
|
||||
/**
|
||||
* @param b a ByteArray
|
||||
* @return Bytes in [b] which are GZip'd then Ascii85-encoded
|
||||
*/
|
||||
fun bytesToZipdStr(b: ByteArray): String {
|
||||
val sb = StringBuilder()
|
||||
val bo = ByteArray64GrowableOutputStream()
|
||||
val zo = GZIPOutputStream(bo)
|
||||
|
||||
b.forEach {
|
||||
zo.write(it.toInt())
|
||||
}
|
||||
zo.flush(); zo.close()
|
||||
|
||||
val ba = bo.toByteArray64()
|
||||
var bai = 0
|
||||
val buf = IntArray(4) { Ascii85.PAD_BYTE }
|
||||
ba.forEach {
|
||||
if (bai > 0 && bai % 4 == 0) {
|
||||
sb.append(Ascii85.encode(buf[0], buf[1], buf[2], buf[3]))
|
||||
buf.fill(Ascii85.PAD_BYTE)
|
||||
}
|
||||
|
||||
buf[bai % 4] = it.toInt() and 255
|
||||
|
||||
bai += 1
|
||||
}; sb.append(Ascii85.encode(buf[0], buf[1], buf[2], buf[3]))
|
||||
|
||||
return sb.toString()
|
||||
b.forEach {
|
||||
zo.write(it.toInt())
|
||||
}
|
||||
zo.flush(); zo.close()
|
||||
|
||||
val ba = bo.toByteArray64()
|
||||
var bai = 0
|
||||
val buf = IntArray(4) { Ascii85.PAD_BYTE }
|
||||
ba.forEach {
|
||||
if (bai > 0 && bai % 4 == 0) {
|
||||
sb.append(Ascii85.encode(buf[0], buf[1], buf[2], buf[3]))
|
||||
buf.fill(Ascii85.PAD_BYTE)
|
||||
}
|
||||
|
||||
buf[bai % 4] = it.toInt() and 255
|
||||
|
||||
bai += 1
|
||||
}; sb.append(Ascii85.encode(buf[0], buf[1], buf[2], buf[3]))
|
||||
|
||||
return sb.toString()
|
||||
}
|
||||
@@ -1,49 +1,21 @@
|
||||
package net.torvald.terrarum.serialise
|
||||
|
||||
import com.badlogic.gdx.utils.Json
|
||||
import com.badlogic.gdx.utils.JsonWriter
|
||||
import net.torvald.terrarum.gameworld.BlockLayer
|
||||
import net.torvald.terrarum.modulebasegame.TerrarumIngame
|
||||
import net.torvald.terrarum.modulecomputers.virtualcomputer.tvd.ByteArray64GrowableOutputStream
|
||||
import java.util.zip.GZIPOutputStream
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2021-08-23.
|
||||
*/
|
||||
class WriteWorld {
|
||||
class WriteWorld(val ingame: TerrarumIngame) {
|
||||
|
||||
open fun invoke(): String {
|
||||
|
||||
|
||||
return ""
|
||||
val world = ingame.world
|
||||
return "{${world.getJsonFields().joinToString(",\n")}}"
|
||||
}
|
||||
|
||||
/**
|
||||
* @param b a BlockLayer
|
||||
* @return Bytes in [b] which are GZip'd then Ascii85-encoded
|
||||
*/
|
||||
private fun blockLayerToStr(b: BlockLayer): String {
|
||||
val sb = StringBuilder()
|
||||
val bo = ByteArray64GrowableOutputStream()
|
||||
val zo = GZIPOutputStream(bo)
|
||||
|
||||
b.bytesIterator().forEachRemaining {
|
||||
zo.write(it.toInt())
|
||||
}
|
||||
zo.flush(); zo.close()
|
||||
|
||||
val ba = bo.toByteArray64()
|
||||
var bai = 0
|
||||
val buf = IntArray(4) { Ascii85.PAD_BYTE }
|
||||
ba.forEach {
|
||||
if (bai > 0 && bai % 4 == 0) {
|
||||
sb.append(Ascii85.encode(buf[0], buf[1], buf[2], buf[3]))
|
||||
buf.fill(Ascii85.PAD_BYTE)
|
||||
}
|
||||
|
||||
buf[bai % 4] = it.toInt() and 255
|
||||
|
||||
bai += 1
|
||||
}; sb.append(Ascii85.encode(buf[0], buf[1], buf[2], buf[3]))
|
||||
|
||||
return sb.toString()
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user