multiple game support for TurnChecker (#3540)

* TurnChecker now checks every multiplayer game

Not just the currently open game

* Adding game saving to turn checker

so multiplayerScreen stays up to date

* remove unused imports

* removing unused functions
This commit is contained in:
GGGuenni
2021-01-24 15:12:44 +01:00
committed by GitHub
parent 93a6286512
commit 3037ce4141
3 changed files with 65 additions and 13 deletions

View File

@ -77,6 +77,15 @@ object GameSaver {
return game
}
/**
* WARNING! transitive GameInfo data not initialized
* The returned GameInfo can not be used for most circumstances because its not initialized!
* It is therefore stateless and save to call for Multiplayer Turn Notifier, unlike gameInfoFromString().
*/
fun gameInfoFromStringWithoutTransients(gameData: String): GameInfo {
return json().fromJson(GameInfo::class.java, gameData)
}
fun deleteSave(GameName: String, multiplayer: Boolean = false){
getSave(GameName, multiplayer).delete()
}
@ -155,13 +164,12 @@ object GameSaver {
}
/**
* Returns current turn's player from GameInfo JSON-String for multiplayer.
* Returns the gameId from a GameInfo which was saved as JSON for multiplayer
* Does not initialize transitive GameInfo data.
* It is therefore stateless and save to call for Multiplayer Turn Notifier, unlike gameInfoFromString().
* It is therefore stateless and save to call for Multiplayer Turn Notifier.
*/
fun currentTurnCivFromString(gameData: String): CivilizationInfo {
val game = json().fromJson(GameInfo::class.java, gameData)
return game.getCivilization(game.currentPlayer)
fun getGameIdFromFile(gameFile: FileHandle): String {
return json().fromJson(GameInfo::class.java, gameFile).gameId
}
}

View File

@ -127,13 +127,13 @@ class OnlineMultiplayer {
}
/**
* Returns current turn's player.
* WARNING!
* Does not initialize transitive GameInfo data.
* It is therefore stateless and save to call for Multiplayer Turn Notifier, unlike tryDownloadGame().
*/
fun tryDownloadCurrentTurnCiv(gameId: String): CivilizationInfo {
fun tryDownloadGameUninitialized(gameId: String): GameInfo {
val zippedGameInfo = DropBox.downloadFileAsString(getGameLocation(gameId))
return GameSaver.currentTurnCivFromString(Gzip.unzip(zippedGameInfo))
return GameSaver.gameInfoFromStringWithoutTransients(Gzip.unzip(zippedGameInfo))
}
}