mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-28 06:16:37 -04:00
GameInfoPreview upload as Metadata (#5584)
* Added Upload and Download functionality * Add preview upload where gameInfo is uploaded
This commit is contained in:
parent
d8bb60f06c
commit
defc9262c2
@ -90,6 +90,10 @@ object GameSaver {
|
||||
return game
|
||||
}
|
||||
|
||||
fun gameInfoPreviewFromString(gameData: String): GameInfoPreview {
|
||||
return json().fromJson(GameInfoPreview::class.java, gameData)
|
||||
}
|
||||
|
||||
/**
|
||||
* WARNING! transitive GameInfo data not initialized
|
||||
* The returned GameInfo can not be used for most circumstances because its not initialized!
|
||||
|
@ -105,7 +105,8 @@ class EditMultiplayerGameInfoScreen(val gameInfo: GameInfoPreview?, gameName: St
|
||||
//save game so multiplayer list stays up to date but do not override multiplayer settings
|
||||
val updatedSave = this.gameInfo!!.updateCurrentTurn(gameInfo)
|
||||
GameSaver.saveGame(updatedSave, gameName)
|
||||
OnlineMultiplayer().tryUploadGame(gameInfo)
|
||||
OnlineMultiplayer().tryUploadGame(gameInfo, withPreview = true)
|
||||
|
||||
Gdx.app.postRunnable {
|
||||
popup.close()
|
||||
//go back to the MultiplayerScreen
|
||||
|
@ -197,7 +197,7 @@ class NewGameScreen(
|
||||
if (newGame != null && gameSetupInfo.gameParameters.isOnlineMultiplayer) {
|
||||
newGame!!.isUpToDate = true // So we don't try to download it from dropbox the second after we upload it - the file is not yet ready for loading!
|
||||
try {
|
||||
OnlineMultiplayer().tryUploadGame(newGame!!)
|
||||
OnlineMultiplayer().tryUploadGame(newGame!!, withPreview = true)
|
||||
|
||||
// Save gameId to clipboard because you have to do it anyway.
|
||||
Gdx.app.clipboard.contents = newGame!!.gameId
|
||||
|
@ -610,7 +610,7 @@ class WorldScreen(val gameInfo: GameInfo, val viewingCiv:CivilizationInfo) : Cam
|
||||
|
||||
if (gameInfo.gameParameters.isOnlineMultiplayer) {
|
||||
try {
|
||||
OnlineMultiplayer().tryUploadGame(gameInfoClone)
|
||||
OnlineMultiplayer().tryUploadGame(gameInfoClone, withPreview = true)
|
||||
} catch (ex: Exception) {
|
||||
Gdx.app.postRunnable { // Since we're changing the UI, that should be done on the main thread
|
||||
val cantUploadNewGamePopup = Popup(this)
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.unciv.ui.worldscreen.mainmenu
|
||||
|
||||
import com.unciv.logic.GameInfo
|
||||
import com.unciv.logic.GameInfoPreview
|
||||
import com.unciv.logic.GameSaver
|
||||
import com.unciv.ui.saves.Gzip
|
||||
import java.io.*
|
||||
@ -113,16 +114,38 @@ object DropBox {
|
||||
class OnlineMultiplayer {
|
||||
fun getGameLocation(gameId: String) = "/MultiplayerGames/$gameId"
|
||||
|
||||
fun tryUploadGame(gameInfo: GameInfo){
|
||||
fun tryUploadGame(gameInfo: GameInfo, withPreview: Boolean){
|
||||
// We upload the gamePreview before we upload the game as this
|
||||
// seems to be necessary for the kick functionality
|
||||
if (withPreview) {
|
||||
tryUploadGamePreview(gameInfo.asPreview())
|
||||
}
|
||||
|
||||
val zippedGameInfo = Gzip.zip(GameSaver.json().toJson(gameInfo))
|
||||
DropBox.uploadFile(getGameLocation(gameInfo.gameId), zippedGameInfo, true)
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to upload only the preview of a game. If the preview is uploaded together with (before/after)
|
||||
* the gameInfo, it is recommended to use tryUploadGame(gameInfo, withPreview = true)
|
||||
* @see tryUploadGame
|
||||
* @see GameInfo.asPreview
|
||||
*/
|
||||
fun tryUploadGamePreview(gameInfo: GameInfoPreview){
|
||||
val zippedGameInfo = Gzip.zip(GameSaver.json().toJson(gameInfo))
|
||||
DropBox.uploadFile("${getGameLocation(gameInfo.gameId)}_Preview", zippedGameInfo, true)
|
||||
}
|
||||
|
||||
fun tryDownloadGame(gameId: String): GameInfo {
|
||||
val zippedGameInfo = DropBox.downloadFileAsString(getGameLocation(gameId))
|
||||
return GameSaver.gameInfoFromString(Gzip.unzip(zippedGameInfo))
|
||||
}
|
||||
|
||||
fun tryDownloadGamePreview(gameId: String): GameInfoPreview {
|
||||
val zippedGameInfo = DropBox.downloadFileAsString("${getGameLocation(gameId)}_Preview")
|
||||
return GameSaver.gameInfoPreviewFromString(Gzip.unzip(zippedGameInfo))
|
||||
}
|
||||
|
||||
/**
|
||||
* WARNING!
|
||||
* Does not initialize transitive GameInfo data.
|
||||
|
Loading…
x
Reference in New Issue
Block a user