still working on the new savegame scheme

main game works fine, saving/loading will not be possible
This commit is contained in:
minjaesong
2021-10-07 17:43:23 +09:00
parent 6d8a7520ac
commit 3f9b41fd29
23 changed files with 200 additions and 86 deletions

View File

@@ -4,7 +4,14 @@ import com.badlogic.gdx.Gdx
import com.badlogic.gdx.graphics.Pixmap
import com.badlogic.gdx.utils.GdxRuntimeException
import net.torvald.terrarum.linearSearch
import net.torvald.terrarum.serialise.Common
import net.torvald.terrarum.tvda.ByteArray64InputStream
import net.torvald.terrarum.tvda.ByteArray64Reader
import net.torvald.terrarum.tvda.SimpleFileSystem
import java.io.InputStream
import java.util.*
import kotlin.collections.ArrayList
import kotlin.collections.HashMap
/**
* Assembles the single frame of the animation, outputs GDX Pixmap.
@@ -15,14 +22,10 @@ import java.io.InputStream
*/
object AssembleSheetPixmap {
operator fun invoke(properties: ADProperties): Pixmap {
private fun drawAndGetCanvas(properties: ADProperties, fileGetter: (String) -> InputStream): Pixmap {
val canvas = Pixmap(properties.cols * properties.frameWidth, properties.rows * properties.frameHeight, Pixmap.Format.RGBA8888)
canvas.blending = Pixmap.Blending.SourceOver
val fileGetter = { path: String ->
Gdx.files.internal(path).read()
}
// actually draw
properties.transforms.forEach { t, _ ->
drawThisFrame(t, canvas, properties, fileGetter)
@@ -31,6 +34,21 @@ object AssembleSheetPixmap {
return canvas
}
fun fromAssetsDir(properties: ADProperties) = drawAndGetCanvas(properties) { partName: String ->
Gdx.files.internal("assets/${properties.toFilename(partName)}").read()
}
fun fromVirtualDisk(disk: SimpleFileSystem, properties: ADProperties): Pixmap {
val bodypartMapping = Properties()
bodypartMapping.load(ByteArray64Reader(disk.getFile(-1025L)!!.bytes, Common.CHARSET))
val fileGetter = { partName: String ->
ByteArray64InputStream(disk.getFile(bodypartMapping[partName] as Long)!!.bytes)
}
return drawAndGetCanvas(properties, fileGetter)
}
private fun drawThisFrame(frameName: String,
canvas: Pixmap,
properties: ADProperties,
@@ -42,7 +60,7 @@ object AssembleSheetPixmap {
val bodypartOrigins = properties.bodyparts
val bodypartImages = properties.bodyparts.keys.map {
try {
val bytes = fileGetter("assets/${properties.toFilename(it)}").readAllBytes()
val bytes = fileGetter(it).readAllBytes()
it to Pixmap(bytes, 0, bytes.size)
}
catch (e: GdxRuntimeException) {

View File

@@ -298,7 +298,7 @@ class SpriteAssemblerPreview: Game() {
}
private fun assembleImage(prop: ADProperties) {
image = AssembleSheetPixmap(prop)
image = AssembleSheetPixmap.fromAssetsDir(prop)
}
// TODO rename to requestAssembly