mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 12:21:52 +09:00
saved game will not be loaded if it's newer than the current version
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
{
|
||||
"ERROR_FILE_NOT_FOUND": "File not found.",
|
||||
"ERROR_SAVE_IS_FROM_NEWER_VERSION": "Saved game is newer than the current game version.",
|
||||
"GAME_32BIT_WARNING1": "It looks like you’re running a 32-Bit version of Java.",
|
||||
"GAME_32BIT_WARNING2": "Please download and install the latest 64-Bit Java at:",
|
||||
"GAME_32BIT_WARNING3": "https://www.java.com/en/download/",
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
{
|
||||
"ERROR_FILE_NOT_FOUND": "파일을 찾을 수 없습니다.",
|
||||
"ERROR_SAVE_IS_FROM_NEWER_VERSION": "저장된 게임이 현재 게임보다 더 최신입니다.",
|
||||
"GAME_32BIT_WARNING1": "32비트 버전의 Java를 사용중인 것 같습니다.",
|
||||
"GAME_32BIT_WARNING2": "아래 링크에서 최신 64비트 Java를 내려받아 설치해주세요.",
|
||||
"GAME_32BIT_WARNING3": "https://www.java.com/ko/download/",
|
||||
|
||||
@@ -115,4 +115,8 @@ data class Snapshot(var revision: Int) {
|
||||
revision = (b[0].toUint() ushr 7 shl 2) or b[1].toUint().and(3)
|
||||
update()
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
return year.shl(24) or week.shl(16) or revision
|
||||
}
|
||||
}
|
||||
@@ -37,6 +37,7 @@ import net.torvald.terrarum.ui.UIItem
|
||||
import net.torvald.terrarum.utils.JsonFetcher
|
||||
import net.torvald.terrarum.utils.forEachSiblings
|
||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||
import java.math.BigInteger
|
||||
import java.time.Instant
|
||||
import java.time.format.DateTimeFormatter
|
||||
import java.util.*
|
||||
@@ -508,6 +509,7 @@ class UIItemPlayerCells(
|
||||
private var lastPlayTime: String = "????-??-?? --:--:--"
|
||||
private var totalPlayTime: String = "--h--m--s"
|
||||
private var versionString: String = "0.0.0"
|
||||
var isNewerVersion = false; private set
|
||||
|
||||
// lateinit var playerUUID: UUID; private set
|
||||
lateinit var worldUUID: UUID; private set
|
||||
@@ -526,18 +528,29 @@ class UIItemPlayerCells(
|
||||
loadable.rebuild()
|
||||
loadable.getFile(SAVEGAMEINFO)?.bytes?.let {
|
||||
var lastPlayTime0 = 0L
|
||||
var genverLong = 0L
|
||||
var genver = ""
|
||||
|
||||
JsonFetcher.readFromJsonString(ByteArray64Reader(it, Common.CHARSET)).forEachSiblings { name, value ->
|
||||
if (name == "worldCurrentlyPlaying") worldUUID = UUID.fromString(value.asString())
|
||||
if (name == "totalPlayTime") totalPlayTime = parseDuration(value.asLong())
|
||||
if (name == "lastPlayTime") lastPlayTime0 = value.asLong()
|
||||
if (name == "genver") genver = value.asLong().let { "${it.ushr(48)}.${it.ushr(24).and(0xFFFFFF)}.${it.and(0xFFFFFF)}" }
|
||||
if (name == "genver") {
|
||||
genverLong = value.asLong()
|
||||
genver = genverLong.let { "${it.ushr(48)}.${it.ushr(24).and(0xFFFFFF)}.${it.and(0xFFFFFF)}" }
|
||||
}
|
||||
}
|
||||
|
||||
val snap = loadable.getSaveSnapshotVersion()
|
||||
versionString = genver + (if (snap != null) "-$snap" else "")
|
||||
|
||||
val savegameVersionNum = // 0x GGGG GGGGGG GGGGGG YY WW RR
|
||||
BigInteger(genverLong.toString()) * BigInteger("16777216") + BigInteger(snap?.hashCode()?.toString() ?: "16777215")
|
||||
val thisVersionNum =
|
||||
BigInteger(TerrarumAppConfiguration.VERSION_RAW.toString()) * BigInteger("16777216") + BigInteger(TerrarumAppConfiguration.VERSION_SNAPSHOT?.hashCode()?.toString() ?: "16777215")
|
||||
|
||||
isNewerVersion = (savegameVersionNum > thisVersionNum)
|
||||
|
||||
App.savegamePlayersName[playerUUID]?.let { if (it.isNotBlank()) playerName = it else "(name)" }
|
||||
App.savegameWorldsName[worldUUID]?.let { if (it.isNotBlank()) worldName = it }
|
||||
lastPlayTime = Instant.ofEpochSecond(lastPlayTime0)
|
||||
@@ -617,12 +630,14 @@ class UIItemPlayerCells(
|
||||
Toolkit.drawBoxBorder(batch, x + avatarViewWidth + 9, y - 1, width - avatarViewWidth - 8, height + 2)
|
||||
|
||||
// texts
|
||||
batch.color = if (isNewerVersion) Toolkit.Theme.COL_RED else highlightTextCol
|
||||
App.fontGame.draw(batch, versionString, x + avatarViewWidth + 40f, line4)
|
||||
|
||||
batch.color = highlightTextCol
|
||||
val playTimeTextLen = App.fontGame.getWidth(totalPlayTime)
|
||||
App.fontGame.draw(batch, playerName, x + avatarViewWidth + 40f, line1)
|
||||
App.fontGame.draw(batch, worldName, x + avatarViewWidth + 40f, line2)
|
||||
App.fontGame.draw(batch, lastPlayTime, x + avatarViewWidth + 40f, line3)
|
||||
App.fontGame.draw(batch, versionString, x + avatarViewWidth + 40f, line4)
|
||||
App.fontGame.draw(batch, totalPlayTime, x + width - 5f - playTimeTextLen, line4)
|
||||
// icons
|
||||
batch.draw(icons.get(24,0), x + avatarViewWidth + 14f - 0, line1 + 2f) // player name
|
||||
|
||||
@@ -92,6 +92,21 @@ class UILoadManage(val full: UILoadSavegame) : UICanvas() {
|
||||
{ Lang["ERROR_SAVE_CORRUPTED"].replace(".","") }, buttonX1third, buttonRowY2, buttonWidth * 3 + buttonGap * 2, alignment = UIItemTextButton.Companion.Alignment.CENTRE, hasBorder = true).also {
|
||||
it.isEnabled = false
|
||||
}
|
||||
private val mainNoGoButtonSaveFromNewerVersion = UIItemTextButton(this,
|
||||
{ if (altDown && savegameIsNotNew) Lang["MENU_LABEL_PREV_SAVES"] else Lang["ERROR_SAVE_IS_FROM_NEWER_VERSION"].replace(".","") }, buttonX1third, buttonRowY2, buttonWidth * 3 + buttonGap * 2, alignment = UIItemTextButton.Companion.Alignment.CENTRE, hasBorder = true).also {
|
||||
it.isEnabled = false
|
||||
it.clickOnceListener = { _,_ ->
|
||||
App.printdbg(this, "Load playerUUID: ${UILoadGovernor.playerUUID}, worldUUID: ${UILoadGovernor.worldUUID}")
|
||||
|
||||
if (altDown && savegameIsNotNew) {
|
||||
mode = MODE_PREV_SAVES
|
||||
loadPrevGameInfo()
|
||||
}
|
||||
}
|
||||
it.updateListener = { _ ->
|
||||
it.isEnabled = altDown
|
||||
}
|
||||
}
|
||||
private val mainImportedPlayerCreateNewWorldButton = UIItemTextButton(this,
|
||||
{ Lang["CONTEXT_WORLD_NEW"].replace(".","") }, buttonX1third, buttonRowY2, buttonWidth * 3 + buttonGap * 2, alignment = UIItemTextButton.Companion.Alignment.CENTRE, hasBorder = true).also {
|
||||
it.clickOnceListener = { _,_ ->
|
||||
@@ -179,7 +194,8 @@ class UILoadManage(val full: UILoadSavegame) : UICanvas() {
|
||||
private var mode = 0
|
||||
|
||||
private var mainButtons0 = listOf(mainGoButton, mainBackButton, mainRenameButton, mainDeleteButton)
|
||||
private var mainButtons1 = listOf(mainNoGoButton, mainBackButton, mainRenameButton, mainDeleteButton)
|
||||
private var mainButtonsNoGoSaveCorrupted = listOf(mainNoGoButton, mainBackButton, mainRenameButton, mainDeleteButton)
|
||||
private var mainButtonsNoGoSaveFromNewer = listOf(mainNoGoButtonSaveFromNewerVersion, mainBackButton, mainRenameButton, mainDeleteButton)
|
||||
private var mainButtons2 = listOf(mainImportedPlayerCreateNewWorldButton, mainBackButton, mainRenameButton, mainDeleteButton)
|
||||
private var delButtons = listOf(confirmCancelButton, confirmDeleteButton)
|
||||
private var renameButtons = listOf(renameRenameButton, renameCancelButton)
|
||||
@@ -190,7 +206,15 @@ class UILoadManage(val full: UILoadSavegame) : UICanvas() {
|
||||
get() = full.loadables.saveAvaliable()
|
||||
|
||||
private val mainButtons: List<UIItemTextButton>
|
||||
get() = if (full.loadables.saveAvaliable()) mainButtons0 else if (full.loadables.isImported) mainButtons2 else mainButtons1
|
||||
get() =
|
||||
if (full.playerButtonSelected?.isNewerVersion == true)
|
||||
mainButtonsNoGoSaveFromNewer
|
||||
else if (full.loadables.saveAvaliable())
|
||||
mainButtons0
|
||||
else if (full.loadables.isImported)
|
||||
mainButtons2
|
||||
else
|
||||
mainButtonsNoGoSaveCorrupted
|
||||
|
||||
private val MODE_INIT = 0
|
||||
private val MODE_DELETE = 16 // are you sure?
|
||||
|
||||
Reference in New Issue
Block a user