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
This commit is contained in:
OptimizedForDensity
2022-07-01 02:36:54 -04:00
committed by GitHub
parent 64ab79faf3
commit 437f0f90b9

View File

@ -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<MapUnit>.tryGetUnitEraSprite(unit: MapUnit, specificUnitIconLocation: String): ImageAttempter<MapUnit> {
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