From 103234a6b8837fab5978ebab812b453b2c83980e Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Wed, 5 Jul 2023 21:55:52 +0300 Subject: [PATCH] Keep track of what mod each ruleset object comes from, for debug and civilopedia purposes --- core/src/com/unciv/models/ruleset/Ruleset.kt | 12 +++++++----- core/src/com/unciv/models/ruleset/RulesetObject.kt | 6 +++++- .../src/com/unciv/models/ruleset/RulesetValidator.kt | 10 +++++----- core/src/com/unciv/models/ruleset/unique/Unique.kt | 2 +- core/src/com/unciv/ui/popups/options/ModCheckTab.kt | 12 ++++++------ docs/Modders/Creating-a-UI-skin.md | 2 +- 6 files changed, 25 insertions(+), 19 deletions(-) diff --git a/core/src/com/unciv/models/ruleset/Ruleset.kt b/core/src/com/unciv/models/ruleset/Ruleset.kt index 833e2e8a7f..f59e2d8a65 100644 --- a/core/src/com/unciv/models/ruleset/Ruleset.kt +++ b/core/src/com/unciv/models/ruleset/Ruleset.kt @@ -112,8 +112,10 @@ class Ruleset { private fun createHashmap(items: Array): LinkedHashMap { val hashMap = LinkedHashMap(items.size) - for (item in items) + for (item in items) { hashMap[item.name] = item + (item as? IRulesetObject)?.originRuleset = name + } return hashMap } @@ -406,7 +408,7 @@ class Ruleset { RulesetValidator(this@Ruleset).checkUnique( Unique(it), false, - "", + cityStateType, UniqueType.UniqueComplianceErrorSeverity.RulesetSpecific ).isEmpty() }) @@ -414,7 +416,7 @@ class Ruleset { RulesetValidator(this@Ruleset).checkUnique( Unique(it), false, - "", + cityStateType, UniqueType.UniqueComplianceErrorSeverity.RulesetSpecific ).isEmpty() }) @@ -484,8 +486,8 @@ object RulesetCache : HashMap() { if (consoleMode) FileHandle(fileName) else Gdx.files.internal(fileName) newRulesets[ruleset.fullName] = Ruleset().apply { - load(fileHandle) name = ruleset.fullName + load(fileHandle) } } this.putAll(newRulesets) @@ -500,8 +502,8 @@ object RulesetCache : HashMap() { if (!modFolder.isDirectory) continue try { val modRuleset = Ruleset() - modRuleset.load(modFolder.child("jsons")) modRuleset.name = modFolder.name() + modRuleset.load(modFolder.child("jsons")) modRuleset.folderLocation = modFolder newRulesets[modRuleset.name] = modRuleset debug("Mod loaded successfully: %s", modRuleset.name) diff --git a/core/src/com/unciv/models/ruleset/RulesetObject.kt b/core/src/com/unciv/models/ruleset/RulesetObject.kt index fa25fd542f..ff559df120 100644 --- a/core/src/com/unciv/models/ruleset/RulesetObject.kt +++ b/core/src/com/unciv/models/ruleset/RulesetObject.kt @@ -8,10 +8,13 @@ import com.unciv.models.stats.NamedStats import com.unciv.ui.screens.civilopediascreen.FormattedLine import com.unciv.ui.screens.civilopediascreen.ICivilopediaText -interface IRulesetObject: INamed, IHasUniques, ICivilopediaText +interface IRulesetObject: INamed, IHasUniques, ICivilopediaText{ + var originRuleset:String +} abstract class RulesetObject: IRulesetObject { override var name = "" + override var originRuleset = "" override var uniques = ArrayList() // Can not be a hashset as that would remove doubles @delegate:Transient override val uniqueObjects: List by lazy { @@ -32,6 +35,7 @@ abstract class RulesetObject: IRulesetObject { // Same, but inherits from NamedStats - I couldn't find a way to unify the declarations but this is fine abstract class RulesetStatsObject: NamedStats(), IRulesetObject { + override var originRuleset = "" override var uniques = ArrayList() // Can not be a hashset as that would remove doubles @delegate:Transient override val uniqueObjects: List by lazy { diff --git a/core/src/com/unciv/models/ruleset/RulesetValidator.kt b/core/src/com/unciv/models/ruleset/RulesetValidator.kt index ca8f5b5d92..fb82b06274 100644 --- a/core/src/com/unciv/models/ruleset/RulesetValidator.kt +++ b/core/src/com/unciv/models/ruleset/RulesetValidator.kt @@ -418,7 +418,7 @@ class RulesetValidator(val ruleset: Ruleset) { val errors = checkUnique( unique, tryFixUnknownUniques, - cityStateType.name, + cityStateType, rulesetSpecific ) lines.addAll(errors) @@ -453,13 +453,11 @@ class RulesetValidator(val ruleset: Ruleset) { severityToReport: UniqueType.UniqueComplianceErrorSeverity, tryFixUnknownUniques: Boolean ) { - val name = if (uniqueContainer is INamed) uniqueContainer.name else "" - for (unique in uniqueContainer.uniqueObjects) { val errors = checkUnique( unique, tryFixUnknownUniques, - name, + uniqueContainer as? INamed, severityToReport ) lines.addAll(errors) @@ -469,9 +467,11 @@ class RulesetValidator(val ruleset: Ruleset) { fun checkUnique( unique: Unique, tryFixUnknownUniques: Boolean, - name: String, + namedObj: INamed?, severityToReport: UniqueType.UniqueComplianceErrorSeverity ): List { + var name = namedObj?.name ?: "" + if (namedObj!=null && namedObj is IRulesetObject) name = "${namedObj.originRuleset}: $name" if (unique.type == null) { if (!tryFixUnknownUniques) return emptyList() val similarUniques = UniqueType.values().filter { diff --git a/core/src/com/unciv/models/ruleset/unique/Unique.kt b/core/src/com/unciv/models/ruleset/unique/Unique.kt index 86808e817a..db1a700c5d 100644 --- a/core/src/com/unciv/models/ruleset/unique/Unique.kt +++ b/core/src/com/unciv/models/ruleset/unique/Unique.kt @@ -116,7 +116,7 @@ class Unique(val text: String, val sourceObjectType: UniqueTarget? = null, val s val uniquesWithNoErrors = finalPossibleUniques.filter { val unique = Unique(it) val errors = RulesetValidator(ruleset).checkUnique( - unique, true, "", + unique, true, null, UniqueType.UniqueComplianceErrorSeverity.RulesetSpecific ) errors.isEmpty() diff --git a/core/src/com/unciv/ui/popups/options/ModCheckTab.kt b/core/src/com/unciv/ui/popups/options/ModCheckTab.kt index a5b1786645..92ad598823 100644 --- a/core/src/com/unciv/ui/popups/options/ModCheckTab.kt +++ b/core/src/com/unciv/ui/popups/options/ModCheckTab.kt @@ -15,19 +15,19 @@ import com.unciv.models.ruleset.unique.UniqueType import com.unciv.models.translations.tr import com.unciv.ui.components.ExpanderTab import com.unciv.ui.components.TabbedPager -import com.unciv.ui.components.input.onChange -import com.unciv.ui.components.input.onClick import com.unciv.ui.components.extensions.surroundWithCircle import com.unciv.ui.components.extensions.toLabel import com.unciv.ui.components.extensions.toTextButton +import com.unciv.ui.components.input.onChange +import com.unciv.ui.components.input.onClick import com.unciv.ui.images.ImageGetter import com.unciv.ui.popups.ToastPopup import com.unciv.ui.screens.basescreen.BaseScreen import com.unciv.ui.screens.newgamescreen.TranslatedSelectBox -import com.unciv.utils.Log import com.unciv.utils.Concurrency -import com.unciv.utils.launchOnGLThread +import com.unciv.utils.Log import com.unciv.utils.debug +import com.unciv.utils.launchOnGLThread private const val MOD_CHECK_WITHOUT_BASE = "-none-" @@ -203,7 +203,7 @@ class ModCheckTab( val modInvariantErrors = RulesetValidator(mod).checkUnique( replacementUnique, false, - "", + null, UniqueType.UniqueComplianceErrorSeverity.RulesetInvariant ) for (error in modInvariantErrors) @@ -214,7 +214,7 @@ class ModCheckTab( val modSpecificErrors = RulesetValidator(mod).checkUnique( replacementUnique, false, - "", + null, UniqueType.UniqueComplianceErrorSeverity.RulesetInvariant ) for (error in modSpecificErrors) diff --git a/docs/Modders/Creating-a-UI-skin.md b/docs/Modders/Creating-a-UI-skin.md index 056e97a9d5..2b3b07c989 100644 --- a/docs/Modders/Creating-a-UI-skin.md +++ b/docs/Modders/Creating-a-UI-skin.md @@ -201,4 +201,4 @@ The color this UI element should have. A float value. Default value: null -The alpha this UI element should have. Overwrites the alpha value of tint if specified. +The alpha this UI element should have. Overwrites the alpha value of tint if specified. \ No newline at end of file