moved Codices out of the singleton so they can be serialised

This commit is contained in:
minjaesong
2021-09-04 17:55:37 +09:00
parent 57e4b83649
commit 6bea9c9f07
42 changed files with 180 additions and 98 deletions

View File

@@ -8,10 +8,7 @@ import net.torvald.terrarum.modulecomputers.virtualcomputer.tvd.ByteArray64
import net.torvald.terrarum.modulecomputers.virtualcomputer.tvd.ByteArray64Reader
import net.torvald.terrarum.modulecomputers.virtualcomputer.tvd.EntryFile
import net.torvald.terrarum.modulecomputers.virtualcomputer.tvd.VirtualDisk
import net.torvald.terrarum.utils.MetaModuleCSVPair
import net.torvald.terrarum.utils.ZipCodedStr
import net.torvald.terrarum.weather.WeatherMixer
import java.io.StringReader
/**
* Created by minjaesong on 2021-08-23.
@@ -33,26 +30,6 @@ object WriteMeta {
creation_t = world.creationTime,
lastplay_t = world.lastPlayTime,
playtime_t = world.totalPlayTime + currentPlayTime_t,
blocks = ModMgr.getFilesFromEveryMod("blocks/blocks.csv").fold(MetaModuleCSVPair()) {
map, (modname, file) ->
map[modname] = ZipCodedStr(file.readText ())
/*return*/map
},
items = ModMgr.getFilesFromEveryMod("items/itemid.csv").fold(MetaModuleCSVPair()) {
map, (modname, file) ->
map[modname] = ZipCodedStr(file.readText ())
/*return*/map
},
wires = ModMgr.getFilesFromEveryMod("wires/wires.csv").fold(MetaModuleCSVPair()) {
map, (modname, file) ->
map[modname] = ZipCodedStr(file.readText ())
/*return*/map
},
materials = ModMgr.getFilesFromEveryMod("materials/materials.csv").fold(MetaModuleCSVPair()) {
map, (modname, file) ->
map[modname] = ZipCodedStr(file.readText ())
/*return*/map
},
loadorder = ModMgr.loadOrder.toTypedArray(),
worlds = ingame.gameworldIndices.toTypedArray()
)
@@ -78,13 +55,10 @@ object WriteMeta {
val creation_t: Long = 0,
val lastplay_t: Long = 0,
val playtime_t: Long = 0,
val blocks: MetaModuleCSVPair = MetaModuleCSVPair(),
val items: MetaModuleCSVPair = MetaModuleCSVPair(),
val wires: MetaModuleCSVPair = MetaModuleCSVPair(),
val materials: MetaModuleCSVPair = MetaModuleCSVPair(),
val loadorder: Array<String> = arrayOf(), // do not use list; Could not instantiate instance of class: java.util.Collections$SingletonList
val worlds: Array<Int> = arrayOf() // do not use list; Could not instantiate instance of class: java.util.Collections$SingletonList
) {
override fun equals(other: Any?): Boolean {
throw UnsupportedOperationException()
}

View File

@@ -1,8 +1,8 @@
package net.torvald.terrarum.serialise
import net.torvald.terrarum.*
import net.torvald.terrarum.gameactors.Actor
import net.torvald.terrarum.gameactors.BlockMarkerActor
import net.torvald.terrarum.AppLoader
import net.torvald.terrarum.SanicLoadScreen
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.modulebasegame.TerrarumIngame
import net.torvald.terrarum.modulebasegame.gameactors.IngamePlayer
import net.torvald.terrarum.modulecomputers.virtualcomputer.tvd.*
@@ -37,6 +37,26 @@ object WriteSavegame {
val meta = DiskEntry(-1, 0, "savegame".toByteArray(), creation_t, time_t, metaContent)
addFile(disk, meta)
// Write BlockCodex//
/*val blockCodexContent = EntryFile(ByteArray64.fromByteArray(Common.jsoner.toJson(BlockCodex, BlockCodex.javaClass).toByteArray(Common.CHARSET)))
val blocks = DiskEntry(-16, 0, "blocks".toByteArray(), creation_t, time_t, blockCodexContent)
addFile(disk, blocks)
// Write ItemCodex//
val itemCodexContent = EntryFile(ByteArray64.fromByteArray(Common.jsoner.toJson(ItemCodex, ItemCodex.javaClass).toByteArray(Common.CHARSET)))
val items = DiskEntry(-17, 0, "items".toByteArray(), creation_t, time_t, itemCodexContent)
addFile(disk, items)
// Write WireCodex//
val wireCodexContent = EntryFile(ByteArray64.fromByteArray(Common.jsoner.toJson(WireCodex, WireCodex.javaClass).toByteArray(Common.CHARSET)))
val wires = DiskEntry(-18, 0, "wires".toByteArray(), creation_t, time_t, wireCodexContent)
addFile(disk, wires)
// Write MaterialCodex//
val materialCodexContent = EntryFile(ByteArray64.fromByteArray(Common.jsoner.toJson(MaterialCodex, MaterialCodex.javaClass).toByteArray(Common.CHARSET)))
val materials = DiskEntry(-19, 0, "materials".toByteArray(), creation_t, time_t, materialCodexContent)
addFile(disk, materials)*/
// Write World //
val worldNum = ingame.world.worldIndex
val worldContent = EntryFile(WriteWorld.encodeToByteArray64(ingame))