writeworldinfo tested to be working

This commit is contained in:
minjaesong
2018-10-08 18:15:05 +09:00
parent 783313a4ae
commit d435ec4ebb
10 changed files with 27 additions and 19 deletions

View File

@@ -20,6 +20,8 @@ open class GameWorld {
val creationTime: Long val creationTime: Long
var lastPlayTime: Long var lastPlayTime: Long
internal set // there's a case of save-and-continue-playing internal set // there's a case of save-and-continue-playing
var totalPlayTime: Int
internal set
/** Used to calculate play time */ /** Used to calculate play time */
val loadTime: Long = System.currentTimeMillis() / 1000L val loadTime: Long = System.currentTimeMillis() / 1000L
@@ -56,7 +58,7 @@ open class GameWorld {
internal set 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.worldIndex = worldIndex
this.width = width this.width = width
this.height = height this.height = height
@@ -82,9 +84,10 @@ open class GameWorld {
creationTime = creationTIME_T creationTime = creationTIME_T
lastPlayTime = lastPlayTIME_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 this.worldIndex = worldIndex
layerTerrain = layerData.layerTerrain layerTerrain = layerData.layerTerrain
@@ -105,6 +108,7 @@ open class GameWorld {
creationTime = creationTIME_T creationTime = creationTIME_T
lastPlayTime = lastPlayTIME_T lastPlayTime = lastPlayTIME_T
this.totalPlayTime = totalPlayTime
} }

View File

@@ -23,7 +23,9 @@ import kotlin.system.measureNanoTime
*/ */
class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) { 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 { init {
// ghetto world for building // ghetto world for building

View File

@@ -231,7 +231,8 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
// init map as chosen size // 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++ gameworldCount++
world = gameworld as GameWorld world = gameworld as GameWorld

View File

@@ -5,6 +5,7 @@ import net.torvald.terrarum.console.Echo
import net.torvald.terrarum.console.EchoError import net.torvald.terrarum.console.EchoError
import net.torvald.terrarum.serialise.WriteLayerDataLzma import net.torvald.terrarum.serialise.WriteLayerDataLzma
import net.torvald.terrarum.serialise.WriteLayerDataZip import net.torvald.terrarum.serialise.WriteLayerDataZip
import net.torvald.terrarum.serialise.WriteWorldInfo
/** /**
* Created by minjaesong on 2017-07-18. * Created by minjaesong on 2017-07-18.
@@ -12,7 +13,8 @@ import net.torvald.terrarum.serialise.WriteLayerDataZip
object ExportLayerData : ConsoleCommand { object ExportLayerData : ConsoleCommand {
override fun execute(args: Array<String>) { override fun execute(args: Array<String>) {
try { try {
val outfile = WriteLayerDataLzma() val outfile = WriteLayerDataZip()
WriteWorldInfo()
Echo("Layer data exported to ${outfile!!.canonicalPath}") Echo("Layer data exported to ${outfile!!.canonicalPath}")
} }
catch (e: Exception) { catch (e: Exception) {

View File

@@ -22,7 +22,7 @@ object ImportLayerData : ConsoleCommand {
val layerData = ReadLayerDataLzma(file) 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!!.actorNowPlaying?.setPosition(
(Terrarum.ingame!!.world).spawnY * FeaturesDrawer.TILE_SIZE.toDouble(), (Terrarum.ingame!!.world).spawnY * FeaturesDrawer.TILE_SIZE.toDouble(),
(Terrarum.ingame!!.world).spawnX * FeaturesDrawer.TILE_SIZE.toDouble() (Terrarum.ingame!!.world).spawnX * FeaturesDrawer.TILE_SIZE.toDouble()

View File

@@ -8,8 +8,8 @@ import net.torvald.terrarum.serialise.ReadLayerDataLzma
*/ */
class GameWorldExtension: GameWorld { class GameWorldExtension: GameWorld {
constructor(worldIndex: Int, width: Int, height: Int) : super(worldIndex, width, height) 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) : super(worldIndex, layerData) 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 val time: WorldTime

View File

@@ -27,11 +27,11 @@ class UITitleCharactersList : UICanvas() {
override var height = Terrarum.HEIGHT - moduleAreaHMargin * 2 override var height = Terrarum.HEIGHT - moduleAreaHMargin * 2
private val moduleInfoCells = ArrayList<UIItemSavegameInfoCell>() private val moduleInfoCells = ArrayList<UIItemSavegameInfoCell>()
// build module list // build characters list
init { init {
SavegameLedger.getSavefileList()?.forEachIndexed { index, file -> //SavegameLedger.getSavefileList()?.forEachIndexed { index, file ->
//
} //}
} }
private val mouduleArea = UIItemList<UIItemSavegameInfoCell>( private val mouduleArea = UIItemList<UIItemSavegameInfoCell>(

View File

@@ -66,7 +66,7 @@ internal object ReadLayerData {
// create world out of tiles data // 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.layerTerrain.data = terrainLayerMSB
retWorld.layerWall.data = wallLayerMSB retWorld.layerWall.data = wallLayerMSB

View File

@@ -15,8 +15,6 @@ import java.io.FileOutputStream
object WriteWorldInfo { object WriteWorldInfo {
// FIXME UNTESTED
val META_MAGIC = "TESV".toByteArray(Charsets.UTF_8) val META_MAGIC = "TESV".toByteArray(Charsets.UTF_8)
val NULL = 0.toByte() val NULL = 0.toByte()
@@ -108,9 +106,10 @@ object WriteWorldInfo {
metaOut.write(timeNow.toLittle48()) metaOut.write(timeNow.toLittle48())
// get playtime and save it // get playtime and save it
val timeToAdd = timeNow - world.loadTime val timeToAdd = (timeNow - world.loadTime).toInt()
metaOut.write(world.lastPlayTime.plus(timeToAdd).toInt().toLittle()) metaOut.write((world.totalPlayTime + timeToAdd).toLittle())
world.lastPlayTime = timeNow world.lastPlayTime = timeNow
world.totalPlayTime += timeToAdd