mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-11 11:04:05 +09:00
new savegame loader is not quite working yet
This commit is contained in:
@@ -7,6 +7,7 @@ import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import net.torvald.terrarum.App
|
||||
import net.torvald.terrarum.CommonResourcePool
|
||||
import net.torvald.terrarum.INGAME
|
||||
import net.torvald.terrarum.ceilInt
|
||||
import net.torvald.terrarum.langpack.Lang
|
||||
import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull.Companion.CELL_COL
|
||||
|
||||
@@ -57,6 +57,11 @@ val SAVE_CELL_HEIGHT = 120
|
||||
* WARNING: the values are not guaranteed to reset when the selector UI is closed!
|
||||
*/
|
||||
object UILoadGovernor {
|
||||
// used by the default save loader
|
||||
var playerUUID: UUID? = null
|
||||
var worldUUID: UUID? = null
|
||||
var previousSaveWasLoaded = false
|
||||
// used by the debug save loader
|
||||
var playerDisk: DiskSkimmer? = null
|
||||
set(value) {
|
||||
printdbg(this, "Player selected: ${value?.diskFile?.name}")
|
||||
@@ -73,6 +78,10 @@ object UILoadGovernor {
|
||||
printdbg(this, "Resetting player and world selection")
|
||||
playerDisk = null
|
||||
worldDisk = null
|
||||
|
||||
playerUUID = null
|
||||
worldUUID = null
|
||||
previousSaveWasLoaded = false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -486,6 +495,8 @@ class UIItemPlayerCells(
|
||||
|
||||
override var clickOnceListener: ((Int, Int) -> Unit)? = { _: Int, _: Int ->
|
||||
UILoadGovernor.playerDisk = skimmer
|
||||
UILoadGovernor.playerUUID = playerUUID
|
||||
UILoadGovernor.worldUUID = worldUUID
|
||||
parent.advanceMode()
|
||||
}
|
||||
|
||||
@@ -494,12 +505,11 @@ class UIItemPlayerCells(
|
||||
private var lastPlayTime: String = "????-??-?? --:--:--"
|
||||
private var totalPlayTime: String = "--h--m--s"
|
||||
|
||||
private var playerUUID: UUID? = null
|
||||
private lateinit var playerUUID: UUID
|
||||
private lateinit var worldUUID: UUID
|
||||
|
||||
init {
|
||||
skimmer.getFile(SAVEGAMEINFO)?.bytes?.let {
|
||||
var playerUUID: UUID? = null
|
||||
var worldUUID: UUID? = null
|
||||
var lastPlayTime0 = 0L
|
||||
|
||||
JsonFetcher.readFromJsonString(ByteArray64Reader(it, Common.CHARSET)).forEachSiblings { name, value ->
|
||||
|
||||
@@ -134,17 +134,30 @@ class UILoadSavegame(val remoCon: UIRemoCon) : Advanceable() {
|
||||
|
||||
// look for recently played world
|
||||
if (mode == 1) {
|
||||
UILoadGovernor.playerDisk!!.getFile(SAVEGAMEINFO)?.bytes?.let {
|
||||
var worldUUID: UUID? = null
|
||||
JsonFetcher.readFromJsonString(ByteArray64Reader(it, Common.CHARSET)).forEachSiblings { name, value ->
|
||||
if (name == "worldCurrentlyPlaying") worldUUID = UUID.fromString(value.asString())
|
||||
}
|
||||
|
||||
// TODO select the most recent loadable save by comparing manual and autosaves, NOT JUST going with loadable()
|
||||
UILoadGovernor.worldDisk = App.savegameWorlds[worldUUID!!]!!.loadable()
|
||||
// select the most recent loadable save by comparing manual and autosaves, NOT JUST going with loadable()
|
||||
printdbg(this, "Load playerUUID: ${UILoadGovernor.playerUUID}, worldUUID: ${UILoadGovernor.worldUUID}")
|
||||
val loadables = SavegameCollectionPair(App.savegamePlayers[UILoadGovernor.playerUUID], App.savegameWorlds[UILoadGovernor.worldUUID])
|
||||
|
||||
var loadAuto = false
|
||||
if (loadables.moreRecentAutosaveAvailable()) {
|
||||
// TODO make choice for load manual or auto, if available
|
||||
|
||||
mode += 1
|
||||
}
|
||||
else if (!loadables.saveAvaliable()) {
|
||||
// TODO show save is damaged and cannot be loaded
|
||||
return
|
||||
}
|
||||
|
||||
val (p, w) = if (loadAuto) loadables.getAutoSave()!! else loadables.getManualSave()!!
|
||||
UILoadGovernor.playerDisk = p; UILoadGovernor.worldDisk = w
|
||||
|
||||
if (loadables.newerSaveIsDamaged) {
|
||||
// TODO queue message: GAME_PREV_SAVE_WAS_LOADED
|
||||
}
|
||||
|
||||
mode += 1
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user