forked from yairm210/Unciv
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Encapsulate Undo functionality * Fix Ruins-Undo exploit * Reorg RuinsManager candidate determination * Deep RuinsManager clone * Revert "Fix Ruins-Undo exploit" This reverts commit 6df6a1a.
- Loading branch information
1 parent
c8365b8
commit 1110811
Showing
9 changed files
with
95 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.unciv.ui.screens.worldscreen | ||
|
||
import com.unciv.utils.Concurrency | ||
|
||
/** Encapsulates the Undo functionality. | ||
* | ||
* Implementation is based on actively saving GameInfo clones and restoring them when needed. | ||
* For now, there's only one single Undo level (but the class signature could easily support more). | ||
*/ | ||
class UndoHandler(private val worldScreen: WorldScreen) { | ||
private var preActionGameInfo = worldScreen.gameInfo | ||
|
||
fun canUndo() = preActionGameInfo != worldScreen.gameInfo && worldScreen.canChangeState | ||
|
||
fun recordCheckpoint() { | ||
preActionGameInfo = worldScreen.gameInfo.clone() | ||
} | ||
|
||
fun restoreCheckpoint() { | ||
Concurrency.run { | ||
// Most of the time we won't load this, so we only set transients once we see it's relevant | ||
preActionGameInfo.setTransients() | ||
preActionGameInfo.isUpToDate = worldScreen.gameInfo.isUpToDate // Multiplayer! | ||
worldScreen.game.loadGame(preActionGameInfo) | ||
} | ||
} | ||
|
||
fun clearCheckpoints() { | ||
preActionGameInfo = worldScreen.gameInfo | ||
} | ||
|
||
/** Simple readability proxies so the caller can pretend the interface exists directly on WorldScreen (imports ugly but calls neat) */ | ||
companion object { | ||
fun WorldScreen.canUndo() = undoHandler.canUndo() | ||
fun WorldScreen.recordUndoCheckpoint() = undoHandler.recordCheckpoint() | ||
fun WorldScreen.restoreUndoCheckpoint() = undoHandler.restoreCheckpoint() | ||
fun WorldScreen.clearUndoCheckpoints() = undoHandler.clearCheckpoints() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters