mirror of
https://github.com/yairm210/Unciv.git
synced 2025-08-03 08:39:37 +07:00
perf: Don't re-substring multiplayer file name every time you do anything, dammit
This commit is contained in:
@ -302,7 +302,7 @@ class OnlineMultiplayer {
|
|||||||
fun changeGameName(game: OnlineMultiplayerGame, newName: String, onException: (Exception?)->Unit) {
|
fun changeGameName(game: OnlineMultiplayerGame, newName: String, onException: (Exception?)->Unit) {
|
||||||
debug("Changing name of game %s to", game.name, newName)
|
debug("Changing name of game %s to", game.name, newName)
|
||||||
val oldPreview = game.preview ?: throw game.error!!
|
val oldPreview = game.preview ?: throw game.error!!
|
||||||
val oldLastUpdate = game.lastUpdate
|
val oldLastUpdate = game.getLastUpdate()
|
||||||
val oldName = game.name
|
val oldName = game.name
|
||||||
|
|
||||||
val newFileHandle = files.saveGame(oldPreview, newName, onException)
|
val newFileHandle = files.saveGame(oldPreview, newName, onException)
|
||||||
|
@ -30,17 +30,16 @@ class OnlineMultiplayerGame(
|
|||||||
lastOnlineUpdate: Instant? = null
|
lastOnlineUpdate: Instant? = null
|
||||||
) {
|
) {
|
||||||
private val lastOnlineUpdate: AtomicReference<Instant?> = AtomicReference(lastOnlineUpdate)
|
private val lastOnlineUpdate: AtomicReference<Instant?> = AtomicReference(lastOnlineUpdate)
|
||||||
val lastUpdate: Instant
|
fun getLastUpdate(): Instant {
|
||||||
get() {
|
val lastFileUpdateTime = Instant.ofEpochMilli(fileHandle.lastModified())
|
||||||
val lastFileUpdateTime = Instant.ofEpochMilli(fileHandle.lastModified())
|
val lastOnlineUpdateTime = lastOnlineUpdate.get()
|
||||||
val lastOnlineUpdateTime = lastOnlineUpdate.get()
|
return if (lastOnlineUpdateTime == null || lastFileUpdateTime.isLargerThan(lastOnlineUpdateTime)) {
|
||||||
return if (lastOnlineUpdateTime == null || lastFileUpdateTime.isLargerThan(lastOnlineUpdateTime)) {
|
lastFileUpdateTime
|
||||||
lastFileUpdateTime
|
} else {
|
||||||
} else {
|
lastOnlineUpdateTime
|
||||||
lastOnlineUpdateTime
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
val name get() = fileHandle.name()
|
}
|
||||||
|
val name = fileHandle.name()
|
||||||
var error: Exception? = null
|
var error: Exception? = null
|
||||||
|
|
||||||
init {
|
init {
|
||||||
|
@ -42,7 +42,7 @@ object MultiplayerHelpers {
|
|||||||
val (message) = LoadGameScreen.getLoadExceptionMessage(ex, "Error while refreshing:")
|
val (message) = LoadGameScreen.getLoadExceptionMessage(ex, "Error while refreshing:")
|
||||||
descriptionText.appendLine(message)
|
descriptionText.appendLine(message)
|
||||||
}
|
}
|
||||||
val lastUpdate = multiplayerGame.lastUpdate
|
val lastUpdate = multiplayerGame.getLastUpdate()
|
||||||
descriptionText.appendLine("Last refresh: [${Duration.between(lastUpdate, Instant.now()).formatShort()}] ago".tr())
|
descriptionText.appendLine("Last refresh: [${Duration.between(lastUpdate, Instant.now()).formatShort()}] ago".tr())
|
||||||
val preview = multiplayerGame.preview
|
val preview = multiplayerGame.preview
|
||||||
if (preview?.currentPlayer != null) {
|
if (preview?.currentPlayer != null) {
|
||||||
|
Reference in New Issue
Block a user