mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 20:31:51 +09:00
writeworldinfo tested to be working
This commit is contained in:
@@ -20,6 +20,8 @@ open class GameWorld {
|
||||
val creationTime: Long
|
||||
var lastPlayTime: Long
|
||||
internal set // there's a case of save-and-continue-playing
|
||||
var totalPlayTime: Int
|
||||
internal set
|
||||
|
||||
/** Used to calculate play time */
|
||||
val loadTime: Long = System.currentTimeMillis() / 1000L
|
||||
@@ -56,7 +58,7 @@ open class GameWorld {
|
||||
internal set
|
||||
|
||||
|
||||
constructor(worldIndex: Int, width: Int, height: Int, creationTIME_T: Long, lastPlayTIME_T: Long = creationTIME_T) {
|
||||
constructor(worldIndex: Int, width: Int, height: Int, creationTIME_T: Long, lastPlayTIME_T: Long, totalPlayTime: Int) {
|
||||
this.worldIndex = worldIndex
|
||||
this.width = width
|
||||
this.height = height
|
||||
@@ -82,9 +84,10 @@ open class GameWorld {
|
||||
|
||||
creationTime = creationTIME_T
|
||||
lastPlayTime = lastPlayTIME_T
|
||||
this.totalPlayTime = totalPlayTime
|
||||
}
|
||||
|
||||
internal constructor(worldIndex: Int, layerData: ReadLayerDataLzma.LayerData, creationTIME_T: Long, lastPlayTIME_T: Long = creationTIME_T) {
|
||||
internal constructor(worldIndex: Int, layerData: ReadLayerDataLzma.LayerData, creationTIME_T: Long, lastPlayTIME_T: Long, totalPlayTime: Int) {
|
||||
this.worldIndex = worldIndex
|
||||
|
||||
layerTerrain = layerData.layerTerrain
|
||||
@@ -105,6 +108,7 @@ open class GameWorld {
|
||||
|
||||
creationTime = creationTIME_T
|
||||
lastPlayTime = lastPlayTIME_T
|
||||
this.totalPlayTime = totalPlayTime
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -23,7 +23,9 @@ import kotlin.system.measureNanoTime
|
||||
*/
|
||||
class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
|
||||
val gameWorld = GameWorldExtension(1, 1024, 256)
|
||||
private val timeNow = System.currentTimeMillis() / 1000
|
||||
|
||||
val gameWorld = GameWorldExtension(1, 1024, 256, timeNow, timeNow, 0)
|
||||
|
||||
init {
|
||||
// ghetto world for building
|
||||
|
||||
@@ -231,7 +231,8 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
|
||||
|
||||
// init map as chosen size
|
||||
gameworld = GameWorldExtension(1, worldParams.width, worldParams.height)
|
||||
val timeNow = System.currentTimeMillis() / 1000
|
||||
gameworld = GameWorldExtension(1, worldParams.width, worldParams.height, timeNow, timeNow, 0) // new game, so the creation time is right now
|
||||
gameworldCount++
|
||||
world = gameworld as GameWorld
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import net.torvald.terrarum.console.Echo
|
||||
import net.torvald.terrarum.console.EchoError
|
||||
import net.torvald.terrarum.serialise.WriteLayerDataLzma
|
||||
import net.torvald.terrarum.serialise.WriteLayerDataZip
|
||||
import net.torvald.terrarum.serialise.WriteWorldInfo
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2017-07-18.
|
||||
@@ -12,7 +13,8 @@ import net.torvald.terrarum.serialise.WriteLayerDataZip
|
||||
object ExportLayerData : ConsoleCommand {
|
||||
override fun execute(args: Array<String>) {
|
||||
try {
|
||||
val outfile = WriteLayerDataLzma()
|
||||
val outfile = WriteLayerDataZip()
|
||||
WriteWorldInfo()
|
||||
Echo("Layer data exported to ${outfile!!.canonicalPath}")
|
||||
}
|
||||
catch (e: Exception) {
|
||||
|
||||
@@ -22,7 +22,7 @@ object ImportLayerData : ConsoleCommand {
|
||||
val layerData = ReadLayerDataLzma(file)
|
||||
|
||||
|
||||
Terrarum.ingame!!.world = GameWorldExtension(1, layerData)
|
||||
Terrarum.ingame!!.world = GameWorldExtension(1, layerData, 0, 0, 0) // FIXME null TIME_T for the (partial) test to pass
|
||||
Terrarum.ingame!!.actorNowPlaying?.setPosition(
|
||||
(Terrarum.ingame!!.world).spawnY * FeaturesDrawer.TILE_SIZE.toDouble(),
|
||||
(Terrarum.ingame!!.world).spawnX * FeaturesDrawer.TILE_SIZE.toDouble()
|
||||
|
||||
@@ -8,8 +8,8 @@ import net.torvald.terrarum.serialise.ReadLayerDataLzma
|
||||
*/
|
||||
class GameWorldExtension: GameWorld {
|
||||
|
||||
constructor(worldIndex: Int, width: Int, height: Int) : super(worldIndex, width, height)
|
||||
internal constructor(worldIndex: Int, layerData: ReadLayerDataLzma.LayerData) : super(worldIndex, layerData)
|
||||
constructor(worldIndex: Int, width: Int, height: Int, creationTIME_T: Long, lastPlayTIME_T: Long, totalPlayTime: Int) : super(worldIndex, width, height, creationTIME_T, lastPlayTIME_T, totalPlayTime)
|
||||
internal constructor(worldIndex: Int, layerData: ReadLayerDataLzma.LayerData, creationTIME_T: Long, lastPlayTIME_T: Long, totalPlayTime: Int) : super(worldIndex, layerData, creationTIME_T, lastPlayTIME_T, totalPlayTime)
|
||||
|
||||
|
||||
val time: WorldTime
|
||||
|
||||
@@ -27,11 +27,11 @@ class UITitleCharactersList : UICanvas() {
|
||||
override var height = Terrarum.HEIGHT - moduleAreaHMargin * 2
|
||||
|
||||
private val moduleInfoCells = ArrayList<UIItemSavegameInfoCell>()
|
||||
// build module list
|
||||
// build characters list
|
||||
init {
|
||||
SavegameLedger.getSavefileList()?.forEachIndexed { index, file ->
|
||||
|
||||
}
|
||||
//SavegameLedger.getSavefileList()?.forEachIndexed { index, file ->
|
||||
//
|
||||
//}
|
||||
}
|
||||
|
||||
private val mouduleArea = UIItemList<UIItemSavegameInfoCell>(
|
||||
|
||||
@@ -66,7 +66,7 @@ internal object ReadLayerData {
|
||||
|
||||
// create world out of tiles data
|
||||
|
||||
val retWorld = inWorld ?: GameWorldExtension(1, worldWidth, worldHeight)
|
||||
val retWorld = inWorld ?: GameWorldExtension(1, worldWidth, worldHeight, 0, 0, 0) // FIXME null TIME_T for the (partial) test to pass
|
||||
|
||||
retWorld.layerTerrain.data = terrainLayerMSB
|
||||
retWorld.layerWall.data = wallLayerMSB
|
||||
|
||||
@@ -15,8 +15,6 @@ import java.io.FileOutputStream
|
||||
|
||||
object WriteWorldInfo {
|
||||
|
||||
// FIXME UNTESTED
|
||||
|
||||
val META_MAGIC = "TESV".toByteArray(Charsets.UTF_8)
|
||||
val NULL = 0.toByte()
|
||||
|
||||
@@ -108,9 +106,10 @@ object WriteWorldInfo {
|
||||
metaOut.write(timeNow.toLittle48())
|
||||
|
||||
// get playtime and save it
|
||||
val timeToAdd = timeNow - world.loadTime
|
||||
metaOut.write(world.lastPlayTime.plus(timeToAdd).toInt().toLittle())
|
||||
val timeToAdd = (timeNow - world.loadTime).toInt()
|
||||
metaOut.write((world.totalPlayTime + timeToAdd).toLittle())
|
||||
world.lastPlayTime = timeNow
|
||||
world.totalPlayTime += timeToAdd
|
||||
|
||||
|
||||
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user