From 3bbfb0100cadaf460562729b9694aad507b82601 Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Sat, 12 Feb 2022 20:03:24 +0200 Subject: [PATCH] Finishing off #6133 - autoreplace cycles through deprecation replacements until it reaches a non-deprecated text This is guaranteed to not cycle endlessly thanks to the added test Checked by having 2 uniques' deprecation text reference each other and it failed as expected --- .../unciv/ui/worldscreen/mainmenu/OptionsPopup.kt | 5 +++++ tests/src/com/unciv/testing/BasicTests.kt | 13 +++++++++++++ 2 files changed, 18 insertions(+) diff --git a/core/src/com/unciv/ui/worldscreen/mainmenu/OptionsPopup.kt b/core/src/com/unciv/ui/worldscreen/mainmenu/OptionsPopup.kt index 8bf5f74746..8140c6c018 100644 --- a/core/src/com/unciv/ui/worldscreen/mainmenu/OptionsPopup.kt +++ b/core/src/com/unciv/ui/worldscreen/mainmenu/OptionsPopup.kt @@ -372,7 +372,12 @@ class OptionsPopup(val previousScreen: BaseScreen) : Popup(previousScreen) { allDeprecatedUniques.add(deprecatedUnique.text) // note that this replacement does not contain conditionals attached to the original! + + var uniqueReplacementText = deprecatedUnique.getReplacementText() + while (Unique(uniqueReplacementText).getDeprecationAnnotation() != null) + uniqueReplacementText = Unique(uniqueReplacementText).getReplacementText() + for (conditional in deprecatedUnique.conditionals) uniqueReplacementText += " <${conditional.text}>" val replacementUnique = Unique(uniqueReplacementText) diff --git a/tests/src/com/unciv/testing/BasicTests.kt b/tests/src/com/unciv/testing/BasicTests.kt index 55bdee345f..99b6b9b9f3 100644 --- a/tests/src/com/unciv/testing/BasicTests.kt +++ b/tests/src/com/unciv/testing/BasicTests.kt @@ -144,6 +144,19 @@ class BasicTests { allOK = false } } + + var iteration = 1 + var replacementUnique = Unique(uniqueType.placeholderText) + while (replacementUnique.getDeprecationAnnotation() != null) { + if (iteration == 10) { + allOK = false + println("${uniqueType.name}'s deprecation text never references an undeprecated unique!") + break + } + iteration++ + replacementUnique = Unique(replacementUnique.getReplacementText()) + } + } Assert.assertTrue("This test succeeds only if all deprecated uniques have a replaceWith text that matches an existing type", allOK) }