Resolved crash in unit civilopedia lines that depended on unitType being initialized

This commit is contained in:
yairm210 2021-09-22 18:31:13 +03:00
parent 5e4aff90e9
commit 5d6765a879

View File

@ -116,7 +116,7 @@ class BaseUnit : INamed, INonPerpetualConstruction, ICivilopediaText {
stats += "$rangedStrength${Fonts.rangedStrength}"
stats += "$range${Fonts.range}"
}
if (movement != 0 && !movesLikeAirUnits()) stats += "$movement${Fonts.movement}"
if (movement != 0 && ruleset.unitTypes[unitType]?.isAirUnit() != true) stats += "$movement${Fonts.movement}"
if (stats.isNotEmpty())
textList += FormattedLine(stats.joinToString(", "))
@ -143,28 +143,39 @@ class BaseUnit : INamed, INonPerpetualConstruction, ICivilopediaText {
for ((resource, amount) in resourceRequirements) {
textList += FormattedLine(
if (amount == 1) "Consumes 1 [$resource]" else "Consumes [$amount] [$resource]",
link="Resource/$resource", color="#F42")
link = "Resource/$resource", color = "#F42"
)
}
}
if (uniqueTo != null) {
textList += FormattedLine()
textList += FormattedLine("Unique to [$uniqueTo]", link="Nation/$uniqueTo")
textList += FormattedLine("Unique to [$uniqueTo]", link = "Nation/$uniqueTo")
if (replaces != null)
textList += FormattedLine("Replaces [$replaces]", link="Unit/$replaces", indent=1)
textList += FormattedLine(
"Replaces [$replaces]",
link = "Unit/$replaces",
indent = 1
)
}
if (requiredTech != null || upgradesTo != null || obsoleteTech != null) textList += FormattedLine()
if (requiredTech != null) textList += FormattedLine("Required tech: [$requiredTech]", link="Technology/$requiredTech")
if (requiredTech != null) textList += FormattedLine(
"Required tech: [$requiredTech]",
link = "Technology/$requiredTech"
)
val canUpgradeFrom = ruleset.units
.filterValues {
(it.upgradesTo == name || it.upgradesTo != null && it.upgradesTo == replaces)
&& (it.uniqueTo == uniqueTo || it.uniqueTo == null)
&& (it.uniqueTo == uniqueTo || it.uniqueTo == null)
}.keys
if (canUpgradeFrom.isNotEmpty()) {
if (canUpgradeFrom.size == 1)
textList += FormattedLine("Can upgrade from [${canUpgradeFrom.first()}]", link = "Unit/${canUpgradeFrom.first()}")
textList += FormattedLine(
"Can upgrade from [${canUpgradeFrom.first()}]",
link = "Unit/${canUpgradeFrom.first()}"
)
else {
textList += FormattedLine()
textList += FormattedLine("Can upgrade from:")
@ -174,28 +185,35 @@ class BaseUnit : INamed, INonPerpetualConstruction, ICivilopediaText {
}
}
if (upgradesTo != null) textList += FormattedLine("Upgrades to [$upgradesTo]", link="Unit/$upgradesTo")
if (obsoleteTech != null) textList += FormattedLine("Obsolete with [$obsoleteTech]", link="Technology/$obsoleteTech")
if (upgradesTo != null) textList += FormattedLine(
"Upgrades to [$upgradesTo]",
link = "Unit/$upgradesTo"
)
if (obsoleteTech != null) textList += FormattedLine(
"Obsolete with [$obsoleteTech]",
link = "Technology/$obsoleteTech"
)
if (promotions.isNotEmpty()) {
textList += FormattedLine()
promotions.withIndex().forEach {
textList += FormattedLine(
when {
promotions.size == 1 -> "{Free promotion:} "
it.index == 0 -> "{Free promotions:} "
else -> ""
} + "{${it.value}}" +
(if (promotions.size == 1 || it.index == promotions.size - 1) "" else ","),
link="Promotions/${it.value}",
indent=if(it.index==0) 0 else 1)
when {
promotions.size == 1 -> "{Free promotion:} "
it.index == 0 -> "{Free promotions:} "
else -> ""
} + "{${it.value}}" +
(if (promotions.size == 1 || it.index == promotions.size - 1) "" else ","),
link = "Promotions/${it.value}",
indent = if (it.index == 0) 0 else 1
)
}
}
val seeAlso = ArrayList<FormattedLine>()
for ((other, unit) in ruleset.units) {
if (unit.replaces == name || uniques.contains("[$name]") ) {
seeAlso += FormattedLine(other, link="Unit/$other", indent=1)
if (unit.replaces == name || uniques.contains("[$name]")) {
seeAlso += FormattedLine(other, link = "Unit/$other", indent = 1)
}
}
if (seeAlso.isNotEmpty()) {