mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-11 02:54:04 +09:00
game load wip
This commit is contained in:
@@ -3,6 +3,7 @@ package net.torvald.terrarum.modulebasegame.console
|
||||
import com.badlogic.gdx.utils.Json
|
||||
import net.torvald.terrarum.AppLoader
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.Terrarum.ingame
|
||||
import net.torvald.terrarum.console.ConsoleCommand
|
||||
import net.torvald.terrarum.console.Echo
|
||||
import net.torvald.terrarum.modulebasegame.TerrarumIngame
|
||||
@@ -19,7 +20,8 @@ import java.io.IOException
|
||||
object ExportMeta : ConsoleCommand {
|
||||
override fun execute(args: Array<String>) {
|
||||
try {
|
||||
val str = WriteMeta(Terrarum.ingame!! as TerrarumIngame).invoke()
|
||||
val currentPlayTime_t = AppLoader.getTIME_T() - ingame!!.loadedTime_t
|
||||
val str = WriteMeta(ingame!! as TerrarumIngame, currentPlayTime_t)
|
||||
val writer = java.io.FileWriter(AppLoader.defaultDir + "/Exports/savegame.json", false)
|
||||
writer.write(str)
|
||||
writer.close()
|
||||
@@ -40,7 +42,7 @@ object ExportWorld : ConsoleCommand {
|
||||
override fun execute(args: Array<String>) {
|
||||
if (args.size == 2) {
|
||||
try {
|
||||
val str = WriteWorld(Terrarum.ingame!! as TerrarumIngame).invoke()
|
||||
val str = WriteWorld(ingame!! as TerrarumIngame)
|
||||
val writer = java.io.FileWriter(AppLoader.defaultDir + "/Exports/${args[1]}.json", false)
|
||||
writer.write(str)
|
||||
writer.close()
|
||||
|
||||
@@ -18,7 +18,7 @@ object ImportWorld : ConsoleCommand {
|
||||
if (args.size == 2) {
|
||||
try {
|
||||
val reader = java.io.FileReader(AppLoader.defaultDir + "/Exports/${args[1]}.json")
|
||||
ReadWorld(Terrarum.ingame!! as TerrarumIngame).invoke(reader)
|
||||
ReadWorld(Terrarum.ingame!! as TerrarumIngame, reader)
|
||||
Echo("Importworld: imported a world from ${args[1]}.json")
|
||||
}
|
||||
catch (e: IOException) {
|
||||
@@ -41,7 +41,7 @@ object ImportActor : ConsoleCommand {
|
||||
if (args.size == 2) {
|
||||
try {
|
||||
val reader = java.io.FileReader(AppLoader.defaultDir + "/Exports/${args[1]}.json")
|
||||
ReadActor(Terrarum.ingame!! as TerrarumIngame).invoke(reader)
|
||||
ReadActor(Terrarum.ingame!! as TerrarumIngame, reader)
|
||||
Echo("Importactor: imported an actor from ${args[1]}.json")
|
||||
}
|
||||
catch (e: IOException) {
|
||||
|
||||
@@ -23,17 +23,9 @@ object Load : ConsoleCommand {
|
||||
val charset = Common.CHARSET
|
||||
val file = File(AppLoader.defaultDir + "/Exports/${args[1]}")
|
||||
val disk = VDUtil.readDiskArchive(file, charset = charset)
|
||||
val meta = ReadMeta(disk)
|
||||
|
||||
val metaFile = disk.entries[-1]!!
|
||||
|
||||
val metaReader = ByteArray64Reader((metaFile.contents as EntryFile).getContent(), Common.CHARSET)
|
||||
val meta = Common.jsoner.fromJson(WriteMeta.WorldMeta::class.java, metaReader)
|
||||
|
||||
WriteMeta.WorldMeta::class.declaredMemberProperties.forEach {
|
||||
println("${it.name} = ${it.get(meta)}")
|
||||
}
|
||||
|
||||
println(WriteMeta.unasciiAndUnzipStr(meta.blocks))
|
||||
meta.blocks.forEach { s, str -> println("Module $s\n"); println(str.doc) }
|
||||
println(meta.loadorder.joinToString())
|
||||
}
|
||||
catch (e: IOException) {
|
||||
|
||||
@@ -11,10 +11,7 @@ import net.torvald.terrarum.gameactors.Actor
|
||||
import net.torvald.terrarum.gameactors.BlockMarkerActor
|
||||
import net.torvald.terrarum.modulebasegame.TerrarumIngame
|
||||
import net.torvald.terrarum.modulecomputers.virtualcomputer.tvd.*
|
||||
import net.torvald.terrarum.serialise.Common
|
||||
import net.torvald.terrarum.serialise.WriteActor
|
||||
import net.torvald.terrarum.serialise.WriteMeta
|
||||
import net.torvald.terrarum.serialise.WriteWorld
|
||||
import net.torvald.terrarum.serialise.*
|
||||
import java.io.File
|
||||
import java.io.IOException
|
||||
|
||||
@@ -40,33 +37,11 @@ object Save : ConsoleCommand {
|
||||
try {
|
||||
val ingame = Terrarum.ingame!! as TerrarumIngame
|
||||
val savename = args[1].trim()
|
||||
val creation_t = VDUtil.currentUnixtime
|
||||
val time_t = VDUtil.currentUnixtime
|
||||
|
||||
val disk = VDUtil.createNewDisk(1L shl 60, savename, Common.CHARSET)
|
||||
val file = File(AppLoader.defaultDir + "/Exports/${args[1]}")
|
||||
|
||||
// NOTE: don't bother with the entryID of DiskEntries; it will be overwritten anyway
|
||||
|
||||
val metaContent = EntryFile(WriteMeta(ingame).encodeToByteArray64())
|
||||
val meta = DiskEntry(-1, 0, "savegame".toByteArray(), creation_t, time_t, metaContent)
|
||||
addFile(disk, meta)
|
||||
|
||||
val worldContent = EntryFile(WriteWorld(ingame).encodeToByteArray64())
|
||||
val world = DiskEntry(ingame.world.worldIndex, 0, "world${ingame.world.worldIndex}".toByteArray(), creation_t, time_t, worldContent)
|
||||
addFile(disk, world)
|
||||
|
||||
listOf(ingame.actorContainerActive, ingame.actorContainerInactive).forEach { actors ->
|
||||
actors.forEach {
|
||||
if (acceptable(it)) {
|
||||
val actorContent = EntryFile(WriteActor.encodeToByteArray64(it))
|
||||
val actor = DiskEntry(it.referenceID, 0, "actor${it.referenceID}".toByteArray(), creation_t, time_t, actorContent)
|
||||
addFile(disk, actor)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
disk.capacity = 0
|
||||
VDUtil.dumpToRealMachine(disk, File(AppLoader.defaultDir + "/Exports/${args[1]}"))
|
||||
WriteSavegame(disk, file, ingame)
|
||||
}
|
||||
catch (e: IOException) {
|
||||
Echo("Save: IOException raised.")
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
package net.torvald.terrarum.modulebasegame.console
|
||||
|
||||
import net.torvald.terrarum.console.ConsoleCommand
|
||||
import net.torvald.terrarum.console.Echo
|
||||
import net.torvald.terrarum.console.EchoError
|
||||
import net.torvald.terrarum.serialise.SavegameWriter
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2019-02-22.
|
||||
*/
|
||||
internal object SavegameWriterTest: ConsoleCommand {
|
||||
|
||||
override fun execute(args: Array<String>) {
|
||||
val r = SavegameWriter.invoke(args.getOrNull(1))
|
||||
if (!r) {
|
||||
EchoError("Saving failed")
|
||||
}
|
||||
}
|
||||
|
||||
override fun printUsage() {
|
||||
Echo("savetest [optional out name}")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user