From 437f0f90b9c37a378712e33eb61c43f5b5acdaa4 Mon Sep 17 00:00:00 2001 From: OptimizedForDensity <105244635+OptimizedForDensity@users.noreply.github.com> Date: Fri, 1 Jul 2022 02:36:54 -0400 Subject: [PATCH] Add support for era-specific unit sprites (#7293) * Add era specific unit sprites * Check era numbers instead of names * Reset atlas * Reset * Code deduplication * More consistent function name * Use lambda expression instead of function * Get rid of gross kludge * Use era names instead of numbers --- core/src/com/unciv/ui/tilegroups/TileGroup.kt | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/core/src/com/unciv/ui/tilegroups/TileGroup.kt b/core/src/com/unciv/ui/tilegroups/TileGroup.kt index a1590abd13..ff9380e700 100644 --- a/core/src/com/unciv/ui/tilegroups/TileGroup.kt +++ b/core/src/com/unciv/ui/tilegroups/TileGroup.kt @@ -699,8 +699,8 @@ open class TileGroup( val specificUnitIconLocation = this.unitsLocation + militaryUnit.name return ImageAttempter(militaryUnit) .forceImage { if (!UncivGame.Current.settings.showPixelUnits) "" else null } - .tryImage { if (civInfo.nation.style.isEmpty()) specificUnitIconLocation else null } - .tryImage { "$specificUnitIconLocation-${civInfo.nation.style}" } + .tryGetUnitEraSprite(militaryUnit, specificUnitIconLocation) + .tryImage { if (civInfo.nation.style.isNotEmpty()) "$specificUnitIconLocation-${civInfo.nation.style}" else null } .tryImage { specificUnitIconLocation } .tryImage { if (baseUnit.replaces != null) "$unitsLocation${baseUnit.replaces}" else null } .tryImages( @@ -744,6 +744,7 @@ open class TileGroup( val specificUnitIconLocation = this.unitsLocation + civilianUnit.name return ImageAttempter(civilianUnit) .forceImage { if (!UncivGame.Current.settings.showPixelUnits) "" else null } + .tryGetUnitEraSprite(civilianUnit, specificUnitIconLocation) .tryImage { if (civInfo.nation.style.isNotEmpty()) "$specificUnitIconLocation-${civInfo.nation.style}" else null } .tryImage { specificUnitIconLocation } .tryImage { civilianLandUnit } @@ -767,6 +768,20 @@ open class TileGroup( } } + private fun ImageAttempter.tryGetUnitEraSprite(unit: MapUnit, specificUnitIconLocation: String): ImageAttempter { + return this.tryImages( + // iterate in reverse order to get the most recent era-specific image + (unit.civInfo.getEraNumber() downTo 0).asSequence().map { + { + val era = civInfo.gameInfo.ruleSet.eras.keys.elementAt(it) + if (civInfo.nation.style.isNotEmpty()) + "$specificUnitIconLocation-${civInfo.nation.style}-$era" + else + "$specificUnitIconLocation-$era" + } + } + ) + } private var bottomRightRiverImage :Image?=null private var bottomRiverImage :Image?=null