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 += "$rangedStrength${Fonts.rangedStrength}"
stats += "$range${Fonts.range}" 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()) if (stats.isNotEmpty())
textList += FormattedLine(stats.joinToString(", ")) textList += FormattedLine(stats.joinToString(", "))
@ -143,7 +143,8 @@ class BaseUnit : INamed, INonPerpetualConstruction, ICivilopediaText {
for ((resource, amount) in resourceRequirements) { for ((resource, amount) in resourceRequirements) {
textList += FormattedLine( textList += FormattedLine(
if (amount == 1) "Consumes 1 [$resource]" else "Consumes [$amount] [$resource]", if (amount == 1) "Consumes 1 [$resource]" else "Consumes [$amount] [$resource]",
link="Resource/$resource", color="#F42") link = "Resource/$resource", color = "#F42"
)
} }
} }
@ -151,11 +152,18 @@ class BaseUnit : INamed, INonPerpetualConstruction, ICivilopediaText {
textList += FormattedLine() textList += FormattedLine()
textList += FormattedLine("Unique to [$uniqueTo]", link = "Nation/$uniqueTo") textList += FormattedLine("Unique to [$uniqueTo]", link = "Nation/$uniqueTo")
if (replaces != null) 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 || 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 val canUpgradeFrom = ruleset.units
.filterValues { .filterValues {
@ -164,7 +172,10 @@ class BaseUnit : INamed, INonPerpetualConstruction, ICivilopediaText {
}.keys }.keys
if (canUpgradeFrom.isNotEmpty()) { if (canUpgradeFrom.isNotEmpty()) {
if (canUpgradeFrom.size == 1) 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 { else {
textList += FormattedLine() textList += FormattedLine()
textList += FormattedLine("Can upgrade from:") textList += FormattedLine("Can upgrade from:")
@ -174,8 +185,14 @@ class BaseUnit : INamed, INonPerpetualConstruction, ICivilopediaText {
} }
} }
if (upgradesTo != null) textList += FormattedLine("Upgrades to [$upgradesTo]", link="Unit/$upgradesTo") if (upgradesTo != null) textList += FormattedLine(
if (obsoleteTech != null) textList += FormattedLine("Obsolete with [$obsoleteTech]", link="Technology/$obsoleteTech") "Upgrades to [$upgradesTo]",
link = "Unit/$upgradesTo"
)
if (obsoleteTech != null) textList += FormattedLine(
"Obsolete with [$obsoleteTech]",
link = "Technology/$obsoleteTech"
)
if (promotions.isNotEmpty()) { if (promotions.isNotEmpty()) {
textList += FormattedLine() textList += FormattedLine()
@ -188,7 +205,8 @@ class BaseUnit : INamed, INonPerpetualConstruction, ICivilopediaText {
} + "{${it.value}}" + } + "{${it.value}}" +
(if (promotions.size == 1 || it.index == promotions.size - 1) "" else ","), (if (promotions.size == 1 || it.index == promotions.size - 1) "" else ","),
link = "Promotions/${it.value}", link = "Promotions/${it.value}",
indent=if(it.index==0) 0 else 1) indent = if (it.index == 0) 0 else 1
)
} }
} }