Keep track of what mod each ruleset object comes from, for debug and civilopedia purposes

This commit is contained in:
Yair Morgenstern 2023-07-05 21:55:52 +03:00
parent 6a6a8a0c94
commit 103234a6b8
6 changed files with 25 additions and 19 deletions

View File

@ -112,8 +112,10 @@ class Ruleset {
private fun <T : INamed> createHashmap(items: Array<T>): LinkedHashMap<String, T> {
val hashMap = LinkedHashMap<String, T>(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<String,Ruleset>() {
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<String,Ruleset>() {
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)

View File

@ -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<String>() // Can not be a hashset as that would remove doubles
@delegate:Transient
override val uniqueObjects: List<Unique> 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<String>() // Can not be a hashset as that would remove doubles
@delegate:Transient
override val uniqueObjects: List<Unique> by lazy {

View File

@ -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<RulesetError> {
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 {

View File

@ -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()

View File

@ -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)