Adds a debug option to simulate up to some amount of turns (#6657)

* Adds a debug option to simulate up to some amount of turns
Note that the option popup only appears _after_ closing the option menu, 
which is very counterintuitive, but a direct result of how opening 
popups is implemented.
I'm fine if this PR is rejected as a result of that, but it is quite a 
useful option to have nonetheless.

* Reworked it so its just an internal text field + button

* Fixed the weird crashes and made UI interactive during simulation
This commit is contained in:
Xander Lenstra 2022-05-06 09:06:34 +02:00 committed by GitHub
parent 13eb49f55c
commit 155fbb2690
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 34 additions and 19 deletions

View File

@ -57,7 +57,7 @@ class UncivGame(parameters: UncivGameParameters) : Game() {
* Does not update World View changes until finished.
* Set to 0 to disable.
*/
val simulateUntilTurnForDebug: Int = 0
var simulateUntilTurnForDebug: Int = 0
/** Console log battles
*/

View File

@ -207,6 +207,8 @@ class GameInfo {
currentPlayerIndex = (currentPlayerIndex + 1) % civilizations.size
if (currentPlayerIndex == 0) {
turns++
if (UncivGame.Current.simulateUntilTurnForDebug != 0)
println("Starting simulation of turn $turns")
}
thisPlayer = civilizations[currentPlayerIndex]
thisPlayer.startTurn()

View File

@ -12,7 +12,7 @@ import com.unciv.ui.utils.*
* @param screen The previous screen the user was on
* @param label A line of text shown to the user
* @param icon Icon at the top, should have size 80f
* @param defaultText The text that should be in the prompt at the start
* @param defaultValue The number that should be in the prompt at the start
* @param amountButtons Buttons that when clicked will add/subtract these amounts to the number
* @param bounds The bounds in which the number must lie. Defaults to [Int.MIN_VALUE, Int.MAX_VALUE]
* @param errorText Text that will be shown when an error is detected
@ -24,7 +24,7 @@ class AskNumberPopup(
screen: BaseScreen,
label: String = "Please enter a number",
icon: IconCircleGroup = ImageGetter.getImage("OtherIcons/Pencil").apply { this.color = Color.BLACK }.surroundWithCircle(80f),
defaultText: String = "",
defaultValue: String = "",
amountButtons: List<Int> = listOf(),
bounds: IntRange = IntRange(Int.MIN_VALUE, Int.MAX_VALUE),
errorText: String = "Invalid input! Please enter a valid number.",
@ -56,7 +56,7 @@ class AskNumberPopup(
wrapper.add(label.toLabel())
add(wrapper).colspan(2).row()
val nameField = TextField(defaultText, skin)
val nameField = TextField(defaultValue, skin)
nameField.textFieldFilter = TextField.TextFieldFilter { _, char -> char.isDigit() || char == '-' }
fun isValidInt(input: String): Boolean {

View File

@ -88,7 +88,7 @@ class OfferColumnsTable(private val tradeLogic: TradeLogic, val screen: Diplomac
screen,
label = "Enter the amount of gold",
icon = ImageGetter.getStatIcon("Gold").surroundWithCircle(80f),
defaultText = offer.amount.toString(),
defaultValue = offer.amount.toString(),
amountButtons =
if (offer.type == TradeType.Gold) listOf(50, 500)
else listOf(5, 15),

View File

@ -645,7 +645,7 @@ class WorldScreen(val gameInfo: GameInfo, val viewingCiv:CivilizationInfo) : Bas
game.setWorldScreen()
}
private fun nextTurn() {
fun nextTurn() {
isPlayersTurn = false
shouldUpdate = true

View File

@ -516,9 +516,6 @@ class OptionsPopup(val previousScreen: BaseScreen) : Popup(previousScreen) {
private fun autoUpdateUniques(mod: Ruleset, replaceableUniques: HashMap<String, String>) {
if (mod.name.contains("mod"))
println("mod")
val filesToReplace = listOf(
"Beliefs.json",
"Buildings.json",
@ -552,27 +549,43 @@ class OptionsPopup(val previousScreen: BaseScreen) : Popup(previousScreen) {
defaults().pad(5f)
val game = UncivGame.Current
val simulateButton = "Simulate until turn:".toTextButton()
val simulateTextField = TextField(game.simulateUntilTurnForDebug.toString(), BaseScreen.skin)
val invalidInputLabel = "This is not a valid integer!".toLabel().also { it.isVisible = false }
simulateButton.onClick {
val simulateUntilTurns = simulateTextField.text.toIntOrNull()
if (simulateUntilTurns == null) {
invalidInputLabel.isVisible = true
return@onClick
}
game.simulateUntilTurnForDebug = simulateUntilTurns
invalidInputLabel.isVisible = false
game.worldScreen.nextTurn()
}
add(simulateButton)
add(simulateTextField).row()
add(invalidInputLabel).colspan(2).row()
add("Supercharged".toCheckBox(game.superchargedForDebug) {
game.superchargedForDebug = it
}).row()
}).colspan(2).row()
add("View entire map".toCheckBox(game.viewEntireMapForDebug) {
game.viewEntireMapForDebug = it
}).row()
}).colspan(2).row()
if (game.isGameInfoInitialized()) {
add("God mode (current game)".toCheckBox(game.gameInfo.gameParameters.godMode) {
game.gameInfo.gameParameters.godMode = it
}).row()
}).colspan(2).row()
}
add("Save maps compressed".toCheckBox(MapSaver.saveZipped) {
MapSaver.saveZipped = it
}).row()
}).colspan(2).row()
add("Gdx Scene2D debug".toCheckBox(BaseScreen.enableSceneDebug) {
BaseScreen.enableSceneDebug = it
}).row()
}).colspan(2).row()
add("Allow untyped Uniques in mod checker".toCheckBox(RulesetCache.modCheckerAllowUntypedUniques) {
RulesetCache.modCheckerAllowUntypedUniques = it
}).row()
}).colspan(2).row()
add(Table().apply {
add("Unique misspelling threshold".toLabel()).left().fillX()
@ -581,7 +594,7 @@ class OptionsPopup(val previousScreen: BaseScreen) : Popup(previousScreen) {
RulesetCache.uniqueMisspellingThreshold = it.toDouble()
}
).minWidth(120f).pad(5f)
}).row()
}).colspan(2).row()
val unlockTechsButton = "Unlock all techs".toTextButton()
unlockTechsButton.onClick {
@ -596,9 +609,9 @@ class OptionsPopup(val previousScreen: BaseScreen) : Popup(previousScreen) {
game.gameInfo.getCurrentPlayerCivilization().updateSightAndResources()
game.worldScreen.shouldUpdate = true
}
add(unlockTechsButton).row()
add(unlockTechsButton).colspan(2).row()
val giveResourcesButton = "Give all strategic resources".toTextButton()
val giveResourcesButton = "Get all strategic resources".toTextButton()
giveResourcesButton.onClick {
if (!game.isGameInfoInitialized())
return@onClick
@ -612,7 +625,7 @@ class OptionsPopup(val previousScreen: BaseScreen) : Popup(previousScreen) {
game.gameInfo.getCurrentPlayerCivilization().updateSightAndResources()
game.worldScreen.shouldUpdate = true
}
add(giveResourcesButton).row()
add(giveResourcesButton).colspan(2).row()
}
//endregion