mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-19 15:04:05 +09:00
loading works but not quite
This commit is contained in:
@@ -310,13 +310,20 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
// overwrite player's props with world's for multiplayer
|
||||
// see comments on IngamePlayer.unauthorisedPlayerProps to know why this is necessary.
|
||||
codices.player.backupPlayerProps(isMultiplayer) // backup first!
|
||||
world.playersLastStatus[codices.player.uuid]?.let { // if nothing was saved, nothing would happen and we still keep the backup, which WriteActor looks for it
|
||||
world.playersLastStatus[codices.player.uuid].let { // regardless of the null-ness, we still keep the backup, which WriteActor looks for it
|
||||
// if the world has some saved values, use them
|
||||
if (it != null) {
|
||||
codices.player.setPosition(it.physics.position)
|
||||
if (isMultiplayer) {
|
||||
codices.player.actorValue = it.actorValue!!
|
||||
codices.player.inventory = it.inventory!!
|
||||
}
|
||||
}
|
||||
// if not, move player to the spawn point
|
||||
else {
|
||||
codices.player.setPosition(world.spawnX * TILE_SIZED, world.spawnY * TILE_SIZED)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// by doing this, whatever the "possession" the player had will be broken by the game load
|
||||
|
||||
@@ -19,6 +19,7 @@ import net.torvald.terrarum.App.printdbg
|
||||
import net.torvald.terrarum.langpack.Lang
|
||||
import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull.Companion.CELL_COL
|
||||
import net.torvald.terrarum.serialise.Common
|
||||
import net.torvald.terrarum.serialise.LoadSavegame
|
||||
import net.torvald.terrarum.serialise.ReadPlayer
|
||||
import net.torvald.terrarum.tvda.ByteArray64InputStream
|
||||
import net.torvald.terrarum.tvda.ByteArray64Reader
|
||||
@@ -113,11 +114,20 @@ class UILoadDemoSavefiles : UICanvas() {
|
||||
private val worldCells = ArrayList<UIItemWorldCells>()
|
||||
private val playerCells = ArrayList<UIItemPlayerCells>()
|
||||
|
||||
var mode = 0 // 0: show players, 1: show worlds
|
||||
var mode = 0; private set// 0: show players, 1: show worlds
|
||||
|
||||
fun advanceMode() {
|
||||
mode += 1
|
||||
uiScroll = 0f
|
||||
scrollFrom = 0
|
||||
scrollTarget = 0
|
||||
scrollAnimCounter = 0f
|
||||
loadFired = 0
|
||||
|
||||
println("savelist mode: $mode")
|
||||
}
|
||||
|
||||
override fun show() {
|
||||
printdbg(this, "savefiles show()")
|
||||
|
||||
try {
|
||||
val remoCon = (App.getCurrentScreen() as TitleScreen).uiRemoCon
|
||||
|
||||
@@ -171,9 +181,11 @@ class UILoadDemoSavefiles : UICanvas() {
|
||||
}
|
||||
|
||||
private fun getCells() = if (mode == 0) playerCells else worldCells
|
||||
private var loadFired = 0
|
||||
|
||||
override fun updateUI(delta: Float) {
|
||||
|
||||
if (mode < 2) {
|
||||
if (scrollTarget != listScroll) {
|
||||
if (scrollAnimCounter < scrollAnimLen) {
|
||||
scrollAnimCounter += delta
|
||||
@@ -193,6 +205,8 @@ class UILoadDemoSavefiles : UICanvas() {
|
||||
val cells = getCells()
|
||||
|
||||
for (index in 0 until cells.size) {
|
||||
|
||||
|
||||
val it = cells[index]
|
||||
if (index in listScroll - 2 until listScroll + savesVisible + 2) {
|
||||
// re-position
|
||||
@@ -201,11 +215,20 @@ class UILoadDemoSavefiles : UICanvas() {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun renderUI(batch: SpriteBatch, camera: Camera) {
|
||||
|
||||
if (mode == 2) {
|
||||
loadFired += 1
|
||||
// to hide the "flipped skybox" artefact
|
||||
gdxClearAndSetBlend(.094f, .094f, .094f, 0f)
|
||||
|
||||
|
||||
if (loadFired == 2) {
|
||||
LoadSavegame(playerDisk!!, worldDisk)
|
||||
}
|
||||
}
|
||||
else {
|
||||
batch.end()
|
||||
|
||||
val cells = getCells()
|
||||
@@ -274,6 +297,7 @@ class UILoadDemoSavefiles : UICanvas() {
|
||||
|
||||
batch.begin()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
override fun keyDown(keycode: Int): Boolean {
|
||||
@@ -294,6 +318,16 @@ class UILoadDemoSavefiles : UICanvas() {
|
||||
return true
|
||||
}
|
||||
|
||||
override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
|
||||
getCells().forEach { it.touchDown(screenX, screenY, pointer, button) }
|
||||
return true
|
||||
}
|
||||
|
||||
override fun touchUp(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
|
||||
getCells().forEach { it.touchUp(screenX, screenY, pointer, button) }
|
||||
return true
|
||||
}
|
||||
|
||||
override fun scrolled(amountX: Float, amountY: Float): Boolean {
|
||||
if (this.isVisible) {
|
||||
val cells = getCells()
|
||||
@@ -370,6 +404,7 @@ class UIItemPlayerCells(
|
||||
|
||||
override var clickOnceListener: ((Int, Int, Int) -> Unit)? = { _: Int, _: Int, _: Int ->
|
||||
parent.playerDisk = skimmer
|
||||
parent.advanceMode()
|
||||
}
|
||||
|
||||
private var playerName: String = "$EMDASH"
|
||||
@@ -559,7 +594,7 @@ class UIItemWorldCells(
|
||||
|
||||
override var clickOnceListener: ((Int, Int, Int) -> Unit)? = { _: Int, _: Int, _: Int ->
|
||||
parent.worldDisk = skimmer
|
||||
TODO()
|
||||
parent.advanceMode()
|
||||
}
|
||||
|
||||
internal var hasTexture = false
|
||||
|
||||
@@ -44,6 +44,8 @@ import net.torvald.terrarum.Terrarum
|
||||
* As mentioned in [UICanvas], UIItems must be added to the Canvas to make listeners work without implementing
|
||||
* everything by yourself.
|
||||
*
|
||||
* PROTIP: if [clickOnceListener] does not seem to work, make sure your parent UI is handling touchDown() and touchUp() events!
|
||||
*
|
||||
* @param initialX initial position of the item. Useful for making transition that requires the item to be moved
|
||||
* @param initialY initial position of the item. Useful for making transition that requires the item to be moved
|
||||
*
|
||||
@@ -113,7 +115,10 @@ abstract class UIItem(var parentUI: UICanvas, val initialX: Int, val initialY: I
|
||||
open var touchUpListener: ((Int, Int, Int, Int) -> Unit)? = null
|
||||
/** Parameters: amountX, amountY */
|
||||
open var scrolledListener: ((Float, Float) -> Unit)? = null
|
||||
/** Parameters: relative mouseX, relative mouseY, button */
|
||||
/** Parameters: relative mouseX, relative mouseY, button
|
||||
*
|
||||
* PROTIP: if clickOnceListener does not seem to work, make sure your parent UI is handling touchDown() and touchUp() events!
|
||||
*/
|
||||
open var clickOnceListener: ((Int, Int, Int) -> Unit)? = null
|
||||
open var clickOnceListenerFired = false
|
||||
|
||||
|
||||
Reference in New Issue
Block a user