mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-04 23:40:01 +07:00
Refactor UncivShowableException (#6899)
This commit is contained in:
@ -1437,6 +1437,12 @@ Invisible to others =
|
||||
Bison =
|
||||
Cocoa =
|
||||
|
||||
# Exceptions that _may_ be shown to the user
|
||||
|
||||
Building '[buildingName]' is buildable and therefore must either have an explicit cost or reference an existing tech. =
|
||||
Nation [nationName] is not found! =
|
||||
Unit [unitName] doesn't seem to exist! =
|
||||
|
||||
|
||||
# In English we just paste all these conditionals at the end of each unique, but in your language that
|
||||
# may not turn into valid sentences. Therefore we have the following two translations to determine
|
||||
@ -1467,5 +1473,3 @@ ConditionalsPlacement =
|
||||
|
||||
|
||||
########################### AUTOMATICALLY GENERATED TRANSLATABLE STRINGS ###########################
|
||||
|
||||
|
||||
|
@ -22,9 +22,6 @@ import com.unciv.ui.audio.MusicTrackChooserFlags
|
||||
import java.util.*
|
||||
|
||||
|
||||
class MissingModsException(val missingMods: String) : UncivShowableException("Missing mods: [$missingMods]")
|
||||
open class UncivShowableException(errorText: String) : Exception(errorText)
|
||||
|
||||
class GameInfo {
|
||||
//region Fields - Serialized
|
||||
var civilizations = mutableListOf<CivilizationInfo>()
|
||||
|
24
core/src/com/unciv/logic/UncivExceptions.kt
Normal file
24
core/src/com/unciv/logic/UncivExceptions.kt
Normal file
@ -0,0 +1,24 @@
|
||||
package com.unciv.logic
|
||||
|
||||
import com.unciv.models.translations.tr
|
||||
|
||||
/**
|
||||
* An [Exception] wrapper marking an Exception as suitable to be shown to the user.
|
||||
*
|
||||
* @param [errorText] should be the _**untranslated**_ error message.
|
||||
* Use [getLocalizedMessage] to get the translated [message], _**or**_ use auto-translating helpers like .toLabel() or FormattedLine().
|
||||
* Usual formatting (`[] or {}`) applies, as does the need to include the text in templates.properties.
|
||||
*/
|
||||
open class UncivShowableException(
|
||||
errorText: String,
|
||||
override val cause: Throwable? = null
|
||||
) : Exception(errorText) {
|
||||
// override because we _definitely_ have a non-null message from [errorText]
|
||||
override val message: String
|
||||
get() = super.message!!
|
||||
override fun getLocalizedMessage() = message.tr()
|
||||
}
|
||||
|
||||
class MissingModsException(
|
||||
val missingMods: String
|
||||
) : UncivShowableException("Missing mods: [$missingMods]")
|
@ -355,7 +355,7 @@ class Ruleset {
|
||||
for (building in buildings.values) {
|
||||
if (building.cost == 0 && !building.hasUnique(UniqueType.Unbuildable)) {
|
||||
val column = technologies[building.requiredTech]?.column
|
||||
?: throw UncivShowableException("Building (${building.name}) is buildable and therefore must either have an explicit cost or reference an existing tech")
|
||||
?: throw UncivShowableException("Building '[${building.name}]' is buildable and therefore must either have an explicit cost or reference an existing tech.")
|
||||
building.cost = if (building.isAnyWonder()) column.wonderCost else column.buildingCost
|
||||
}
|
||||
}
|
||||
@ -982,7 +982,7 @@ object RulesetCache : HashMap<String,Ruleset>() {
|
||||
// This happens if a building is dependent on a tech not in the base ruleset
|
||||
// because newRuleset.updateBuildingCosts() in getComplexRuleset() throws an error
|
||||
Ruleset.RulesetErrorList()
|
||||
.apply { add(ex.message!!.tr(), Ruleset.RulesetErrorSeverity.Error) }
|
||||
.apply { add(ex.message, Ruleset.RulesetErrorSeverity.Error) }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -122,7 +122,7 @@ class MapEditorLoadTab(
|
||||
val rulesetIncompatibilities = map.getRulesetIncompatibility(ruleset)
|
||||
if (rulesetIncompatibilities.isNotEmpty()) {
|
||||
map.removeMissingTerrainModReferences(ruleset)
|
||||
val message = "{This map has errors:}\n\n".tr() +
|
||||
val message = "{This map has errors:}\n\n" +
|
||||
rulesetIncompatibilities.sorted().joinToString("\n") { it.tr() } +
|
||||
"\n\n{The incompatible elements have been removed.}"
|
||||
ToastPopup(message, editorScreen, 4000L)
|
||||
@ -134,7 +134,7 @@ class MapEditorLoadTab(
|
||||
} catch (ex: Throwable) {
|
||||
needPopup = false
|
||||
popup?.close()
|
||||
println("Error displaying map \"$chosenMap\": ${ex.localizedMessage}")
|
||||
println("Error displaying map \"$chosenMap\": ${ex.message}")
|
||||
Gdx.input.inputProcessor = editorScreen.stage
|
||||
ToastPopup("Error loading map!", editorScreen)
|
||||
}
|
||||
@ -143,9 +143,9 @@ class MapEditorLoadTab(
|
||||
needPopup = false
|
||||
Gdx.app.postRunnable {
|
||||
popup?.close()
|
||||
println("Error loading map \"$chosenMap\": ${ex.localizedMessage}")
|
||||
ToastPopup("Error loading map!".tr() +
|
||||
(if (ex is UncivShowableException) "\n" + ex.message else ""), editorScreen)
|
||||
println("Error loading map \"$chosenMap\": ${ex.message}")
|
||||
ToastPopup("{Error loading map!}" +
|
||||
(if (ex is UncivShowableException) "\n{${ex.message}}" else ""), editorScreen)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user