mirror of
https://github.com/yairm210/Unciv.git
synced 2025-03-13 11:30:31 +07:00
Skipping turns for a game now correctly updates the MP screen
This commit is contained in:
parent
eadc7b24a2
commit
6265e160e6
@ -151,8 +151,12 @@ class Multiplayer {
|
||||
val preview = game.preview ?: throw game.error!!
|
||||
// download to work with the latest game state
|
||||
val gameInfo = multiplayerServer.tryDownloadGame(preview.gameId)
|
||||
if (gameInfo.currentTurnStartTime != preview.currentTurnStartTime)
|
||||
return false // Game was updated since we tried
|
||||
|
||||
|
||||
if (gameInfo.currentPlayer != preview.currentPlayer) {
|
||||
game.doManualUpdate(gameInfo.asPreview())
|
||||
return false
|
||||
}
|
||||
|
||||
val playerCiv = gameInfo.getCurrentPlayerCivilization()
|
||||
|
||||
@ -177,13 +181,23 @@ class Multiplayer {
|
||||
return true
|
||||
}
|
||||
|
||||
/** Returns false if game was not up to date */
|
||||
suspend fun skipCurrentPlayerTurn(game: MultiplayerGame): Boolean {
|
||||
val preview = game.preview ?: throw game.error!!
|
||||
/** Returns false if game was not up to date
|
||||
* Returned value indicates an error string - will be null if successful */
|
||||
suspend fun skipCurrentPlayerTurn(game: MultiplayerGame): String? {
|
||||
val preview = game.preview ?: return game.error!!.message
|
||||
// download to work with the latest game state
|
||||
val gameInfo = multiplayerServer.tryDownloadGame(preview.gameId)
|
||||
if (gameInfo.currentTurnStartTime != preview.currentTurnStartTime)
|
||||
return false // Game was updated since we tried
|
||||
val gameInfo: GameInfo
|
||||
try {
|
||||
gameInfo = multiplayerServer.tryDownloadGame(preview.gameId)
|
||||
}
|
||||
catch (ex: Exception){
|
||||
return ex.message
|
||||
}
|
||||
|
||||
if (gameInfo.currentPlayer != preview.currentPlayer) {
|
||||
game.doManualUpdate(gameInfo.asPreview())
|
||||
return "Could not pass turn - current player has been updated!"
|
||||
}
|
||||
|
||||
val playerCiv = gameInfo.getCurrentPlayerCivilization()
|
||||
NextTurnAutomation.automateCivMoves(playerCiv, false)
|
||||
@ -193,7 +207,7 @@ class Multiplayer {
|
||||
multiplayerFiles.files.saveGame(newPreview, game.fileHandle)
|
||||
multiplayerServer.tryUploadGame(gameInfo, withPreview = true)
|
||||
game.doManualUpdate(newPreview)
|
||||
return true
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -222,14 +222,15 @@ class MultiplayerScreen : PickerScreen() {
|
||||
|
||||
Concurrency.runOnNonDaemonThreadPool("Skip turn") {
|
||||
try {
|
||||
val skipTurnSuccess = game.onlineMultiplayer.skipCurrentPlayerTurn(multiplayerGame)
|
||||
val skipTurnErrorMessage = game.onlineMultiplayer.skipCurrentPlayerTurn(multiplayerGame)
|
||||
|
||||
launchOnGLThread {
|
||||
if (skipTurnSuccess) {
|
||||
if (skipTurnErrorMessage == null) {
|
||||
popup.close()
|
||||
} else {
|
||||
popup.reuseWith("You can only resign if it's your turn", true)
|
||||
popup.reuseWith(skipTurnErrorMessage, true)
|
||||
}
|
||||
gameList.update()
|
||||
}
|
||||
} catch (ex: Exception) {
|
||||
val (message) = LoadGameScreen.getLoadExceptionMessage(ex)
|
||||
|
Loading…
Reference in New Issue
Block a user