mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-22 10:54:19 -04:00
Ruleset validation: Catch "building required for victory milestone but does not exist" errors
This commit is contained in:
parent
6e389de4b2
commit
2b65d59e77
@ -7,11 +7,7 @@ import com.unciv.json.fromJsonFile
|
|||||||
import com.unciv.json.json
|
import com.unciv.json.json
|
||||||
import com.unciv.logic.map.tile.RoadStatus
|
import com.unciv.logic.map.tile.RoadStatus
|
||||||
import com.unciv.models.metadata.BaseRuleset
|
import com.unciv.models.metadata.BaseRuleset
|
||||||
import com.unciv.models.ruleset.BeliefType
|
import com.unciv.models.ruleset.*
|
||||||
import com.unciv.models.ruleset.Building
|
|
||||||
import com.unciv.models.ruleset.IRulesetObject
|
|
||||||
import com.unciv.models.ruleset.Ruleset
|
|
||||||
import com.unciv.models.ruleset.RulesetCache
|
|
||||||
import com.unciv.models.ruleset.nation.Nation
|
import com.unciv.models.ruleset.nation.Nation
|
||||||
import com.unciv.models.ruleset.nation.getContrastRatio
|
import com.unciv.models.ruleset.nation.getContrastRatio
|
||||||
import com.unciv.models.ruleset.nation.getRelativeLuminance
|
import com.unciv.models.ruleset.nation.getRelativeLuminance
|
||||||
@ -58,8 +54,8 @@ class RulesetValidator(val ruleset: Ruleset) {
|
|||||||
|
|
||||||
// Tileset tests - e.g. json configs complete and parseable
|
// Tileset tests - e.g. json configs complete and parseable
|
||||||
checkTilesetSanity(lines) // relies on textureNamesCache
|
checkTilesetSanity(lines) // relies on textureNamesCache
|
||||||
|
|
||||||
checkCivilopediaText(lines) // relies on textureNamesCache
|
checkCivilopediaText(lines) // relies on textureNamesCache
|
||||||
|
checkFiles(lines)
|
||||||
|
|
||||||
return lines
|
return lines
|
||||||
}
|
}
|
||||||
@ -104,10 +100,21 @@ class RulesetValidator(val ruleset: Ruleset) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
checkCivilopediaText(lines)
|
checkCivilopediaText(lines)
|
||||||
|
checkFiles(lines)
|
||||||
|
|
||||||
return lines
|
return lines
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private fun checkFiles(lines: RulesetErrorList) {
|
||||||
|
val folder = ruleset.folderLocation ?: return
|
||||||
|
for (child in folder.list()){
|
||||||
|
if (child.name().endsWith("json"))
|
||||||
|
lines.add("File ${child.name()} is located in the root folder - it should be moved to a 'jsons' folder")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun addModOptionsErrors(lines: RulesetErrorList, tryFixUnknownUniques: Boolean) {
|
private fun addModOptionsErrors(lines: RulesetErrorList, tryFixUnknownUniques: Boolean) {
|
||||||
// Basic Unique validation (type, target, parameters) should always run.
|
// Basic Unique validation (type, target, parameters) should always run.
|
||||||
// Using reportRulesetSpecificErrors=true as ModOptions never should use Uniques depending on objects from a base ruleset anyway.
|
// Using reportRulesetSpecificErrors=true as ModOptions never should use Uniques depending on objects from a base ruleset anyway.
|
||||||
@ -192,12 +199,19 @@ class RulesetValidator(val ruleset: Ruleset) {
|
|||||||
"Victory type ${victoryType.name} requires adding the non-existant unit $requiredUnit to the capital to win!",
|
"Victory type ${victoryType.name} requires adding the non-existant unit $requiredUnit to the capital to win!",
|
||||||
RulesetErrorSeverity.Warning, sourceObject = null
|
RulesetErrorSeverity.Warning, sourceObject = null
|
||||||
)
|
)
|
||||||
for (milestone in victoryType.milestoneObjects)
|
for (milestone in victoryType.milestoneObjects) {
|
||||||
if (milestone.type == null)
|
if (milestone.type == null)
|
||||||
lines.add(
|
lines.add(
|
||||||
"Victory type ${victoryType.name} has milestone ${milestone.uniqueDescription} that is of an unknown type!",
|
"Victory type ${victoryType.name} has milestone \"${milestone.uniqueDescription}\" that is of an unknown type!",
|
||||||
RulesetErrorSeverity.Error, sourceObject = null
|
RulesetErrorSeverity.Error, sourceObject = null
|
||||||
)
|
)
|
||||||
|
if (milestone.type in listOf(MilestoneType.BuiltBuilding, MilestoneType.BuildingBuiltGlobally)
|
||||||
|
&& milestone.params[0] !in ruleset.buildings)
|
||||||
|
lines.add(
|
||||||
|
"Victory type ${victoryType.name} has milestone \"${milestone.uniqueDescription}\" that references an unknown building ${milestone.params[0]}!",
|
||||||
|
RulesetErrorSeverity.Error,
|
||||||
|
)
|
||||||
|
}
|
||||||
for (victory in ruleset.victories.values)
|
for (victory in ruleset.victories.values)
|
||||||
if (victory.name != victoryType.name && victory.milestones == victoryType.milestones)
|
if (victory.name != victoryType.name && victory.milestones == victoryType.milestones)
|
||||||
lines.add(
|
lines.add(
|
||||||
@ -442,7 +456,7 @@ class RulesetValidator(val ruleset: Ruleset) {
|
|||||||
&& !improvement.hasUnique(UniqueType.CanOnlyImproveResource)
|
&& !improvement.hasUnique(UniqueType.CanOnlyImproveResource)
|
||||||
&& !improvement.hasUnique(UniqueType.Unbuildable)
|
&& !improvement.hasUnique(UniqueType.Unbuildable)
|
||||||
&& !improvement.name.startsWith(Constants.remove)
|
&& !improvement.name.startsWith(Constants.remove)
|
||||||
&& improvement.name !in RoadStatus.values().map { it.removeAction }
|
&& improvement.name !in RoadStatus.entries.map { it.removeAction }
|
||||||
&& improvement.name != Constants.cancelImprovementOrder
|
&& improvement.name != Constants.cancelImprovementOrder
|
||||||
) {
|
) {
|
||||||
lines.add(
|
lines.add(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user