recording and retrieving timestamps for save meta and world

This commit is contained in:
minjaesong
2021-09-11 22:24:13 +09:00
parent 4e0d1e0c9d
commit 784f5fd2ec
10 changed files with 57 additions and 31 deletions

View File

@@ -65,7 +65,7 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
private val timeNow = System.currentTimeMillis() / 1000
val gameWorld = GameWorld(1, 1024, 256, timeNow, timeNow, 0)
val gameWorld = GameWorld(1, 1024, 256, timeNow, timeNow)
init {
// ghetto world for building

View File

@@ -295,7 +295,7 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
// init map as chosen size
val timeNow = App.getTIME_T()
world = GameWorld(1, worldParams.width, worldParams.height, timeNow, timeNow, 0) // new game, so the creation time is right now
world = GameWorld(1, worldParams.width, worldParams.height, timeNow, timeNow) // new game, so the creation time is right now
world.generatorSeed = worldParams.worldGenSeed
gameworldIndices.add(world.worldIndex)
world.extraFields["basegame.economy"] = GameEconomy()

View File

@@ -18,8 +18,7 @@ import java.io.IOException
object ExportMeta : ConsoleCommand {
override fun execute(args: Array<String>) {
try {
val currentPlayTime_t = App.getTIME_T() - ingame!!.loadedTime_t
val str = WriteMeta(ingame!! as TerrarumIngame, currentPlayTime_t)
val str = WriteMeta(ingame!! as TerrarumIngame, App.getTIME_T())
val writer = java.io.FileWriter(App.defaultDir + "/Exports/savegame.json", false)
writer.write(str)
writer.close()
@@ -40,7 +39,7 @@ object ExportWorld : ConsoleCommand {
override fun execute(args: Array<String>) {
if (args.size == 2) {
try {
val str = WriteWorld(ingame!! as TerrarumIngame)
val str = WriteWorld(ingame!! as TerrarumIngame, App.getTIME_T())
val writer = java.io.FileWriter(App.defaultDir + "/Exports/${args[1]}.json", false)
writer.write(str)
writer.close()

View File

@@ -45,8 +45,9 @@ class UILoadDemoSavefiles : UICanvas() {
}
catch (e: Throwable) {
e.printStackTrace()
null
}
}.sortedByDescending { (it as VirtualDisk).entries[0]!!.modificationDate }.forEachIndexed { index, disk ->
}.filter { it != null }.sortedByDescending { (it as VirtualDisk).entries[0]!!.modificationDate }.forEachIndexed { index, disk ->
val x = (width - UIItemDemoSaveCells.WIDTH) / 2
val y = 144 + (24 + UIItemDemoSaveCells.HEIGHT) * index
addUIitem(UIItemDemoSaveCells(this, x, y, disk as VirtualDisk))
@@ -102,9 +103,21 @@ class UIItemDemoSaveCells(
private val x = initialX.toFloat()
private val y = initialY.toFloat()
private fun parseDuration(seconds: Long): String {
val s = seconds % 60
val m = (seconds / 60) % 60
val h = (seconds / 3600) % 24
val d = seconds / 86400
return if (d == 0L)
"${h.toString().padStart(2,'0')}h${m.toString().padStart(2,'0')}m${s.toString().padStart(2,'0')}s"
else
"${d}d${h.toString().padStart(2,'0')}h${m.toString().padStart(2,'0')}m${s.toString().padStart(2,'0')}s"
}
private val lastPlayedTimestamp = Instant.ofEpochSecond(meta.lastplay_t)
.atZone(TimeZone.getDefault().toZoneId())
.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))
.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")) +
"/${parseDuration(meta.playtime_t)}"
init {
try {