mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-26 21:35:14 -04:00
Refactor UncivShowableException (#6899)
This commit is contained in:
parent
3754108391
commit
740886c890
@ -1437,6 +1437,12 @@ Invisible to others =
|
|||||||
Bison =
|
Bison =
|
||||||
Cocoa =
|
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
|
# 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
|
# may not turn into valid sentences. Therefore we have the following two translations to determine
|
||||||
@ -1467,5 +1473,3 @@ ConditionalsPlacement =
|
|||||||
|
|
||||||
|
|
||||||
########################### AUTOMATICALLY GENERATED TRANSLATABLE STRINGS ###########################
|
########################### AUTOMATICALLY GENERATED TRANSLATABLE STRINGS ###########################
|
||||||
|
|
||||||
|
|
||||||
|
@ -22,9 +22,6 @@ import com.unciv.ui.audio.MusicTrackChooserFlags
|
|||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
|
|
||||||
class MissingModsException(val missingMods: String) : UncivShowableException("Missing mods: [$missingMods]")
|
|
||||||
open class UncivShowableException(errorText: String) : Exception(errorText)
|
|
||||||
|
|
||||||
class GameInfo {
|
class GameInfo {
|
||||||
//region Fields - Serialized
|
//region Fields - Serialized
|
||||||
var civilizations = mutableListOf<CivilizationInfo>()
|
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) {
|
for (building in buildings.values) {
|
||||||
if (building.cost == 0 && !building.hasUnique(UniqueType.Unbuildable)) {
|
if (building.cost == 0 && !building.hasUnique(UniqueType.Unbuildable)) {
|
||||||
val column = technologies[building.requiredTech]?.column
|
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
|
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
|
// This happens if a building is dependent on a tech not in the base ruleset
|
||||||
// because newRuleset.updateBuildingCosts() in getComplexRuleset() throws an error
|
// because newRuleset.updateBuildingCosts() in getComplexRuleset() throws an error
|
||||||
Ruleset.RulesetErrorList()
|
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)
|
val rulesetIncompatibilities = map.getRulesetIncompatibility(ruleset)
|
||||||
if (rulesetIncompatibilities.isNotEmpty()) {
|
if (rulesetIncompatibilities.isNotEmpty()) {
|
||||||
map.removeMissingTerrainModReferences(ruleset)
|
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() } +
|
rulesetIncompatibilities.sorted().joinToString("\n") { it.tr() } +
|
||||||
"\n\n{The incompatible elements have been removed.}"
|
"\n\n{The incompatible elements have been removed.}"
|
||||||
ToastPopup(message, editorScreen, 4000L)
|
ToastPopup(message, editorScreen, 4000L)
|
||||||
@ -134,7 +134,7 @@ class MapEditorLoadTab(
|
|||||||
} catch (ex: Throwable) {
|
} catch (ex: Throwable) {
|
||||||
needPopup = false
|
needPopup = false
|
||||||
popup?.close()
|
popup?.close()
|
||||||
println("Error displaying map \"$chosenMap\": ${ex.localizedMessage}")
|
println("Error displaying map \"$chosenMap\": ${ex.message}")
|
||||||
Gdx.input.inputProcessor = editorScreen.stage
|
Gdx.input.inputProcessor = editorScreen.stage
|
||||||
ToastPopup("Error loading map!", editorScreen)
|
ToastPopup("Error loading map!", editorScreen)
|
||||||
}
|
}
|
||||||
@ -143,9 +143,9 @@ class MapEditorLoadTab(
|
|||||||
needPopup = false
|
needPopup = false
|
||||||
Gdx.app.postRunnable {
|
Gdx.app.postRunnable {
|
||||||
popup?.close()
|
popup?.close()
|
||||||
println("Error loading map \"$chosenMap\": ${ex.localizedMessage}")
|
println("Error loading map \"$chosenMap\": ${ex.message}")
|
||||||
ToastPopup("Error loading map!".tr() +
|
ToastPopup("{Error loading map!}" +
|
||||||
(if (ex is UncivShowableException) "\n" + ex.message else ""), editorScreen)
|
(if (ex is UncivShowableException) "\n{${ex.message}}" else ""), editorScreen)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user