new world screen for loading imported players

This commit is contained in:
minjaesong
2023-08-25 16:47:00 +09:00
parent a4672a131d
commit 72029ed458
10 changed files with 44 additions and 18 deletions

Binary file not shown.

View File

@@ -347,6 +347,10 @@ class SavegameCollectionPair(private val player: SavegameCollection?, private va
return if (status == 0) null
else DiskPair(playerDisk!!, worldDisk!!)
}
fun getImportedPlayer(): DiskSkimmer? {
return if (isImported) player!!.loadable() else null
}
}
data class DiskPair(val player: DiskSkimmer, val world: DiskSkimmer) {

View File

@@ -39,6 +39,7 @@ class PlayerSavingThread(
disk.saveMode = 2 * isAuto.toInt() // no quick
disk.saveKind = VDSaveKind.PLAYER_DATA
disk.saveOrigin = disk.saveOrigin and 15 // remove flag "imported" if applicable
disk.capacity = 0L
WriteSavegame.saveProgress = 0f

View File

@@ -149,6 +149,7 @@ class QuickSingleplayerWorldSavingThread(
skimmer.injectDiskCRC(disk.hashCode())
skimmer.setSaveMode(1 + 2 * isAuto.toInt())
skimmer.setSaveKind(VDSaveKind.WORLD_DATA)
skimmer.setSaveOrigin(skimmer.getSaveOrigin() and 15) // remove flag "imported" if applicable
printdbg(this, "Game saved with size of ${outFile.length()} bytes")

View File

@@ -41,6 +41,7 @@ class WorldSavingThread(
disk.saveMode = 2 * isAuto.toInt() // no quick
disk.saveKind = VDSaveKind.WORLD_DATA
disk.saveOrigin = disk.saveOrigin and 15 // remove flag "imported" if applicable
// wait for screencap
var emergencyStopCnt = 0

View File

@@ -74,7 +74,6 @@ object WritePlayer {
player.lastPlayTime = time_t
player.totalPlayTime += time_t - (ingame?.loadedTime_t ?: time_t)
// restore player prop backup created on load-time for multiplayer
if (ingame?.isMultiplayer == true) {
player.setPosition(player.unauthorisedPlayerProps.physics.position)

View File

@@ -66,6 +66,13 @@ 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 mainImportedPlayerCreateNewWorldButton = UIItemTextButton(this,
{ Lang["CONTEXT_WORLD_NEW"].replace(".","") }, buttonX1third, buttonRowY2, buttonWidth * 3 + buttonGap * 2, alignment = UIItemTextButton.Companion.Alignment.CENTRE, hasBorder = true).also {
it.clickOnceListener = { _,_ ->
val playerDisk = full.loadables.getImportedPlayer()!!
full.remoCon.openUI(UINewWorld(full.remoCon, playerDisk))
}
}
private val mainRenameButton = UIItemTextButton(this,
{ Lang["MENU_LABEL_RENAME"] }, buttonX1third, buttonRowY, buttonWidth, alignment = UIItemTextButton.Companion.Alignment.CENTRE, hasBorder = true).also {
it.clickOnceListener = { _,_ ->
@@ -134,11 +141,12 @@ class UILoadManage(val full: UILoadSavegame) : UICanvas() {
private var mainButtons0 = listOf(mainGoButton, mainBackButton, mainRenameButton, mainDeleteButton)
private var mainButtons1 = listOf(mainNoGoButton, mainBackButton, mainRenameButton, mainDeleteButton)
private var mainButtons2 = listOf(mainImportedPlayerCreateNewWorldButton, mainBackButton, mainRenameButton, mainDeleteButton)
private var delButtons = listOf(confirmCancelButton, confirmDeleteButton)
private var renameButtons = listOf(renameRenameButton, renameCancelButton)
private val mainButtons: List<UIItemTextButton>
get() = if (full.loadables.saveAvaliable()) mainButtons0 else mainButtons1
get() = if (full.loadables.saveAvaliable()) mainButtons0 else if (full.loadables.isImported) mainButtons2 else mainButtons1
private val MODE_INIT = 0
private val MODE_DELETE = 16 // are you sure?
@@ -212,18 +220,20 @@ class UILoadManage(val full: UILoadSavegame) : UICanvas() {
val tex = screencap ?: CommonResourcePool.getAsTextureRegion("terrarum-defaultsavegamethumb")
val tx = (Toolkit.drawWidth - screencapW) / 2
val tys = full.titleTopGradEnd + SAVE_CELL_HEIGHT + buttonGap
val tye = buttonRowY2 - buttonGap
val ty = tys + (tye - tys - SAVE_THUMBNAIL_MAIN_HEIGHT) / 2
if (full.loadables.saveAvaliable()) {
val tx = (Toolkit.drawWidth - screencapW) / 2
val tys = full.titleTopGradEnd + SAVE_CELL_HEIGHT + buttonGap
val tye = buttonRowY2 - buttonGap
val ty = tys + (tye - tys - SAVE_THUMBNAIL_MAIN_HEIGHT) / 2
batch.color = Toolkit.Theme.COL_INACTIVE
Toolkit.drawBoxBorder(batch, tx - 1, ty - 1, screencapW + 2, screencapH + 2)
batch.color = UIInventoryFull.CELL_COL
Toolkit.fillArea(batch, tx, ty, screencapW, screencapH)
batch.color = Toolkit.Theme.COL_INACTIVE
Toolkit.drawBoxBorder(batch, tx - 1, ty - 1, screencapW + 2, screencapH + 2)
batch.color = UIInventoryFull.CELL_COL
Toolkit.fillArea(batch, tx, ty, screencapW, screencapH)
batch.color = Color.WHITE
batch.draw(tex, tx.toFloat(), ty.toFloat(), screencapW.toFloat(), screencapH.toFloat())
batch.color = Color.WHITE
batch.draw(tex, tx.toFloat(), ty.toFloat(), screencapW.toFloat(), screencapH.toFloat())
}
}
MODE_DELETE -> {

View File

@@ -15,6 +15,7 @@ import net.torvald.terrarum.savegame.VirtualDisk
import net.torvald.terrarum.serialise.Common
import net.torvald.terrarum.modulebasegame.serialise.LoadSavegame
import net.torvald.terrarum.modulebasegame.serialise.WritePlayer
import net.torvald.terrarum.savegame.VDSaveOrigin
import net.torvald.terrarum.ui.*
import net.torvald.terrarum.utils.RandomWordsName
import java.io.File
@@ -71,6 +72,7 @@ class UINewCharacter(val remoCon: UIRemoCon) : UICanvas() {
disk.saveMode = 2 // auto, no quick
disk.capacity = 0L
disk.saveOrigin = VDSaveOrigin.INGAME
WritePlayer(player, disk, null, time_t)
VDUtil.dumpToRealMachine(disk, outFile)

View File

@@ -18,6 +18,7 @@ import net.torvald.terrarum.savegame.ByteArray64Reader
import net.torvald.terrarum.savegame.VirtualDisk
import net.torvald.terrarum.serialise.Common
import net.torvald.terrarum.modulebasegame.serialise.ReadActor
import net.torvald.terrarum.savegame.DiskSkimmer
import net.torvald.terrarum.savegame.VDFileID.SAVEGAMEINFO
import net.torvald.terrarum.ui.*
import net.torvald.terrarum.utils.RandomWordsName
@@ -28,11 +29,16 @@ import net.torvald.terrarum.utils.RandomWordsName
class UINewWorld(val remoCon: UIRemoCon) : UICanvas() {
private var newPlayerCreationThread = Thread {}
private var existingPlayer: DiskSkimmer? = null
constructor(remoCon: UIRemoCon, playerCreationThread: Thread) : this(remoCon) {
newPlayerCreationThread = playerCreationThread
}
constructor(remoCon: UIRemoCon, importedPlayer: DiskSkimmer) : this(remoCon) {
existingPlayer = importedPlayer
}
private val hugeTex = TextureRegion(Texture(ModMgr.getGdxFile("basegame", "gui/huge.png")))
private val largeTex = TextureRegion(Texture(ModMgr.getGdxFile("basegame", "gui/large.png")))
private val normalTex = TextureRegion(Texture(ModMgr.getGdxFile("basegame", "gui/normal.png")))
@@ -98,14 +104,16 @@ class UINewWorld(val remoCon: UIRemoCon) : UICanvas() {
goButton.clickOnceListener = { _, _ ->
// after the save is complete, proceed to new world generation
newPlayerCreationThread.start()
newPlayerCreationThread.join()
if (existingPlayer == null) {
newPlayerCreationThread.start()
newPlayerCreationThread.join()
}
printdbg(this, "generate! Size=${sizeSelector.selection}, Name=${nameInput.getTextOrPlaceholder()}, Seed=${seedInput.getTextOrPlaceholder()}")
val ingame = TerrarumIngame(App.batch)
val playerDisk = App.savegamePlayers[UILoadGovernor.playerUUID]!!.loadable()
val playerDisk = existingPlayer ?: App.savegamePlayers[UILoadGovernor.playerUUID]!!.loadable()
val player = ReadActor.invoke(playerDisk, ByteArray64Reader(playerDisk.getFile(SAVEGAMEINFO)!!.bytes, Common.CHARSET)) as IngamePlayer
val seed = try {
seedInput.getTextOrPlaceholder().toLong()

View File

@@ -76,9 +76,9 @@ Version 254 is a customised version of TEVD tailored to be used as a savegame fo
0: Undefined (or very old version of the game)
1: Player Data
2: World Data
Int8 Savefile Origin Flags
Int8 Savefile Origin Flags (lower nybble: persistent, upper nybble: can be removed if conditions are met)
0: Created in-game
16: Imported
16: Imported (will be removed once the file is loaded by the player and saved in-game)
Int8[12] Extra info bytes reserved for future usage
-- END extraInfoBytes --
UInt8[236] Rest of the long disk name (268 bytes total)