mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-13 20:14:05 +09:00
csvs are compressed within savegame
This commit is contained in:
@@ -3,9 +3,12 @@ package net.torvald.terrarum.serialise
|
|||||||
import com.badlogic.gdx.utils.Json
|
import com.badlogic.gdx.utils.Json
|
||||||
import com.badlogic.gdx.utils.JsonWriter
|
import com.badlogic.gdx.utils.JsonWriter
|
||||||
import net.torvald.terrarum.ModMgr
|
import net.torvald.terrarum.ModMgr
|
||||||
|
import net.torvald.terrarum.gameworld.BlockLayer
|
||||||
import net.torvald.terrarum.modulebasegame.TerrarumIngame
|
import net.torvald.terrarum.modulebasegame.TerrarumIngame
|
||||||
import net.torvald.terrarum.modulebasegame.worldgenerator.RoguelikeRandomiser
|
import net.torvald.terrarum.modulebasegame.worldgenerator.RoguelikeRandomiser
|
||||||
|
import net.torvald.terrarum.modulecomputers.virtualcomputer.tvd.ByteArray64GrowableOutputStream
|
||||||
import net.torvald.terrarum.weather.WeatherMixer
|
import net.torvald.terrarum.weather.WeatherMixer
|
||||||
|
import java.util.zip.GZIPOutputStream
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by minjaesong on 2021-08-23.
|
* Created by minjaesong on 2021-08-23.
|
||||||
@@ -34,7 +37,7 @@ open class WriteMeta(val ingame: TerrarumIngame) {
|
|||||||
it.append("\n\n## module: $modname ##\n\n")
|
it.append("\n\n## module: $modname ##\n\n")
|
||||||
it.append(file.readText())
|
it.append(file.readText())
|
||||||
}
|
}
|
||||||
it.toString()
|
bytesToZipdStr(it.toString().toByteArray())
|
||||||
},
|
},
|
||||||
|
|
||||||
"items" to StringBuilder().let {
|
"items" to StringBuilder().let {
|
||||||
@@ -42,7 +45,7 @@ open class WriteMeta(val ingame: TerrarumIngame) {
|
|||||||
it.append("\n\n## module: $modname ##\n\n")
|
it.append("\n\n## module: $modname ##\n\n")
|
||||||
it.append(file.readText())
|
it.append(file.readText())
|
||||||
}
|
}
|
||||||
it.toString()
|
bytesToZipdStr(it.toString().toByteArray())
|
||||||
},
|
},
|
||||||
|
|
||||||
"wires" to StringBuilder().let {
|
"wires" to StringBuilder().let {
|
||||||
@@ -50,7 +53,7 @@ open class WriteMeta(val ingame: TerrarumIngame) {
|
|||||||
it.append("\n\n## module: $modname ##\n\n")
|
it.append("\n\n## module: $modname ##\n\n")
|
||||||
it.append(file.readText())
|
it.append(file.readText())
|
||||||
}
|
}
|
||||||
it.toString()
|
bytesToZipdStr(it.toString().toByteArray())
|
||||||
},
|
},
|
||||||
|
|
||||||
// TODO fluids
|
// TODO fluids
|
||||||
@@ -59,7 +62,7 @@ open class WriteMeta(val ingame: TerrarumIngame) {
|
|||||||
it.append("\n\n## module: $modname ##\n\n")
|
it.append("\n\n## module: $modname ##\n\n")
|
||||||
it.append(file.readText())
|
it.append(file.readText())
|
||||||
}
|
}
|
||||||
it.toString()
|
bytesToZipdStr(it.toString().toByteArray())
|
||||||
},
|
},
|
||||||
|
|
||||||
"loadorder" to ModMgr.loadOrder,
|
"loadorder" to ModMgr.loadOrder,
|
||||||
@@ -69,4 +72,33 @@ open class WriteMeta(val ingame: TerrarumIngame) {
|
|||||||
return Json(JsonWriter.OutputType.json).toJson(props)
|
return Json(JsonWriter.OutputType.json).toJson(props)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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)
|
||||||
|
|
||||||
|
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[bai % 4] = it.toInt() and 255
|
||||||
|
|
||||||
|
bai += 1
|
||||||
|
}; sb.append(Ascii85.encode(buf[0], buf[1], buf[2], buf[3]))
|
||||||
|
|
||||||
|
return sb.toString()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -17,7 +17,7 @@ class WriteWorld {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param b a BlockLayer
|
* @param b a BlockLayer
|
||||||
* @return Bytes in BlockLayer, GZip'd then Ascii85-encoded
|
* @return Bytes in [b] which are GZip'd then Ascii85-encoded
|
||||||
*/
|
*/
|
||||||
private fun blockLayerToStr(b: BlockLayer): String {
|
private fun blockLayerToStr(b: BlockLayer): String {
|
||||||
val sb = StringBuilder()
|
val sb = StringBuilder()
|
||||||
|
|||||||
Reference in New Issue
Block a user