mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-04 07:17:50 +07:00
Show json parsing errors for mods in the options menu
This commit is contained in:
@ -729,7 +729,8 @@ class Ruleset {
|
||||
* save all of the loaded rulesets somewhere for later use
|
||||
* */
|
||||
object RulesetCache : HashMap<String,Ruleset>() {
|
||||
fun loadRulesets(consoleMode: Boolean = false, printOutput: Boolean = false, noMods: Boolean = false) {
|
||||
/** Returns error lines from loading the rulesets, so we can display the errors to users */
|
||||
fun loadRulesets(consoleMode: Boolean = false, printOutput: Boolean = false, noMods: Boolean = false) :List<String> {
|
||||
clear()
|
||||
for (ruleset in BaseRuleset.values()) {
|
||||
val fileName = "jsons/${ruleset.fullName}"
|
||||
@ -742,11 +743,12 @@ object RulesetCache : HashMap<String,Ruleset>() {
|
||||
}
|
||||
}
|
||||
|
||||
if (noMods) return
|
||||
if (noMods) return listOf()
|
||||
|
||||
val modsHandles = if (consoleMode) FileHandle("mods").list()
|
||||
else Gdx.files.local("mods").list()
|
||||
|
||||
val errorLines = ArrayList<String>()
|
||||
for (modFolder in modsHandles) {
|
||||
if (modFolder.name().startsWith('.')) continue
|
||||
if (!modFolder.isDirectory) continue
|
||||
@ -761,13 +763,13 @@ object RulesetCache : HashMap<String,Ruleset>() {
|
||||
println(modRuleset.checkModLinks().getErrorText())
|
||||
}
|
||||
} catch (ex: Exception) {
|
||||
if (printOutput) {
|
||||
println("Exception loading mod '${modFolder.name()}':")
|
||||
println(" ${ex.localizedMessage}")
|
||||
println(" ${ex.cause?.localizedMessage}")
|
||||
}
|
||||
errorLines += "Exception loading mod '${modFolder.name()}':"
|
||||
errorLines += " ${ex.localizedMessage}"
|
||||
errorLines += " ${ex.cause?.localizedMessage}"
|
||||
}
|
||||
}
|
||||
if (printOutput) for (line in errorLines) println(line)
|
||||
return errorLines
|
||||
}
|
||||
|
||||
|
||||
|
@ -264,7 +264,6 @@ class OptionsPopup(val previousScreen: BaseScreen) : Popup(previousScreen) {
|
||||
private fun getModCheckTab() = Table(BaseScreen.skin).apply {
|
||||
defaults().pad(10f).align(Align.top)
|
||||
val reloadModsButton = "Reload mods".toTextButton().onClick {
|
||||
RulesetCache.loadRulesets()
|
||||
runModChecker(modCheckCheckBox!!.isChecked)
|
||||
}
|
||||
add(reloadModsButton).row()
|
||||
@ -277,10 +276,20 @@ class OptionsPopup(val previousScreen: BaseScreen) : Popup(previousScreen) {
|
||||
}
|
||||
|
||||
private fun runModChecker(complex: Boolean = false) {
|
||||
|
||||
modCheckFirstRun = false
|
||||
if (modCheckCheckBox == null) return
|
||||
|
||||
modCheckResultTable.clear()
|
||||
|
||||
val rulesetErrors = RulesetCache.loadRulesets()
|
||||
if (rulesetErrors.isNotEmpty()) {
|
||||
val errorTable = Table().apply { defaults().pad(2f) }
|
||||
for (rulesetError in rulesetErrors)
|
||||
errorTable.add(rulesetError.toLabel()).width(stage.width / 2).row()
|
||||
modCheckResultTable.add(errorTable)
|
||||
}
|
||||
|
||||
modCheckResultTable.add("Checking mods for errors...".toLabel()).row()
|
||||
modCheckCheckBox!!.disable()
|
||||
|
||||
@ -437,7 +446,6 @@ class OptionsPopup(val previousScreen: BaseScreen) : Popup(previousScreen) {
|
||||
}
|
||||
val toastText = "Uniques updated!"
|
||||
ToastPopup(toastText, screen).open(true)
|
||||
RulesetCache.loadRulesets()
|
||||
runModChecker()
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user