mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-29 15:01:09 -04:00
Use tileset fallbacks for missing images. (#5852)
* Use tileset fallbacks for missing images. * Disable tileset fallback for FantasyHex. * Tweak docs, remove debug signature.
This commit is contained in:
parent
a1dfa53664
commit
005c465ee4
3
android/assets/jsons/TileSets/Default.json
Normal file
3
android/assets/jsons/TileSets/Default.json
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"fallbackTileSet": null,
|
||||||
|
}
|
@ -1,5 +1,6 @@
|
|||||||
{
|
{
|
||||||
"useColorAsBaseTerrain": "false",
|
"useColorAsBaseTerrain": "false",
|
||||||
|
"fallbackTileSet": null,
|
||||||
"ruleVariants": {
|
"ruleVariants": {
|
||||||
//Legacy hill support
|
//Legacy hill support
|
||||||
"Hill": ["Grassland","Hill"],
|
"Hill": ["Grassland","Hill"],
|
||||||
|
@ -26,13 +26,13 @@ object TileSetCache : HashMap<String, TileSetConfig>() {
|
|||||||
mods.addAll(ruleSetMods)
|
mods.addAll(ruleSetMods)
|
||||||
clear()
|
clear()
|
||||||
for (mod in mods.distinct()) {
|
for (mod in mods.distinct()) {
|
||||||
val entry = allConfigs.entries.firstOrNull { it.key.mod == mod } ?: continue
|
for (entry in allConfigs.entries.filter { it.key.mod == mod } ) { // Built-in tilesets all have empty strings as their `.mod`, so loop through all of them.
|
||||||
|
|
||||||
val tileSet = entry.key.tileSet
|
val tileSet = entry.key.tileSet
|
||||||
if (tileSet in this) this[tileSet]!!.updateConfig(entry.value)
|
if (tileSet in this) this[tileSet]!!.updateConfig(entry.value)
|
||||||
else this[tileSet] = entry.value
|
else this[tileSet] = entry.value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun loadTileSetConfigs(consoleMode: Boolean = false, printOutput: Boolean = false){
|
fun loadTileSetConfigs(consoleMode: Boolean = false, printOutput: Boolean = false){
|
||||||
allConfigs.clear()
|
allConfigs.clear()
|
||||||
|
@ -6,12 +6,15 @@ class TileSetConfig {
|
|||||||
var useColorAsBaseTerrain = true
|
var useColorAsBaseTerrain = true
|
||||||
var unexploredTileColor: Color = Color.DARK_GRAY
|
var unexploredTileColor: Color = Color.DARK_GRAY
|
||||||
var fogOfWarColor: Color = Color.BLACK
|
var fogOfWarColor: Color = Color.BLACK
|
||||||
|
/** Name of the tileset to use when this one is missing images. Null to disable. */
|
||||||
|
var fallbackTileSet: String? = "FantasyHex"
|
||||||
var ruleVariants: HashMap<String, Array<String>> = HashMap()
|
var ruleVariants: HashMap<String, Array<String>> = HashMap()
|
||||||
|
|
||||||
fun updateConfig(other: TileSetConfig){
|
fun updateConfig(other: TileSetConfig){
|
||||||
useColorAsBaseTerrain = other.useColorAsBaseTerrain
|
useColorAsBaseTerrain = other.useColorAsBaseTerrain
|
||||||
unexploredTileColor = other.unexploredTileColor
|
unexploredTileColor = other.unexploredTileColor
|
||||||
fogOfWarColor = other.fogOfWarColor
|
fogOfWarColor = other.fogOfWarColor
|
||||||
|
fallbackTileSet = other.fallbackTileSet
|
||||||
for ((tileSetString, renderOrder) in other.ruleVariants){
|
for ((tileSetString, renderOrder) in other.ruleVariants){
|
||||||
ruleVariants[tileSetString] = renderOrder
|
ruleVariants[tileSetString] = renderOrder
|
||||||
}
|
}
|
||||||
|
@ -120,7 +120,7 @@ open class TileGroup(var tileInfo: TileInfo, val tileSetStrings:TileSetStrings,
|
|||||||
val circleCrosshairFogLayerGroup = ActionlessGroup().apply { isTransform = false; setSize(groupSize, groupSize) }
|
val circleCrosshairFogLayerGroup = ActionlessGroup().apply { isTransform = false; setSize(groupSize, groupSize) }
|
||||||
val circleImage = ImageGetter.getCircle() // for blue and red circles on the tile
|
val circleImage = ImageGetter.getCircle() // for blue and red circles on the tile
|
||||||
private val crosshairImage = ImageGetter.getImage("OtherIcons/Crosshair") // for when a unit is targeted
|
private val crosshairImage = ImageGetter.getImage("OtherIcons/Crosshair") // for when a unit is targeted
|
||||||
private val fogImage = ImageGetter.getImage(tileSetStrings.crosshatchHexagon)
|
private val fogImage = ImageGetter.getImage(tileSetStrings.orFallback { crosshatchHexagon } )
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class for representing an arrow to add to the map at this tile.
|
* Class for representing an arrow to add to the map at this tile.
|
||||||
@ -132,7 +132,7 @@ open class TileGroup(var tileInfo: TileInfo, val tileSetStrings:TileSetStrings,
|
|||||||
private class MapArrow(val targetTile: TileInfo, val arrowType: MapArrowType, val tileSetStrings: TileSetStrings) {
|
private class MapArrow(val targetTile: TileInfo, val arrowType: MapArrowType, val tileSetStrings: TileSetStrings) {
|
||||||
/** @return An Image from a named arrow texture. */
|
/** @return An Image from a named arrow texture. */
|
||||||
private fun getArrow(imageName: String): Image {
|
private fun getArrow(imageName: String): Image {
|
||||||
val imagePath = tileSetStrings.getString(tileSetStrings.tileSetLocation, "Arrows/", imageName)
|
val imagePath = tileSetStrings.orFallback { getString(tileSetLocation, "Arrows/", imageName) }
|
||||||
return ImageGetter.getImage(imagePath)
|
return ImageGetter.getImage(imagePath)
|
||||||
}
|
}
|
||||||
/** @return An actor for the arrow, based on the type of the arrow. */
|
/** @return An actor for the arrow, based on the type of the arrow. */
|
||||||
@ -206,8 +206,8 @@ open class TileGroup(var tileInfo: TileInfo, val tileSetStrings:TileSetStrings,
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun getTileBaseImageLocations(viewingCiv: CivilizationInfo?): List<String> {
|
private fun getTileBaseImageLocations(viewingCiv: CivilizationInfo?): List<String> {
|
||||||
if (viewingCiv == null && !showEntireMap) return listOf(tileSetStrings.hexagon)
|
if (viewingCiv == null && !showEntireMap) return listOf(tileSetStrings.orFallback { hexagon } )
|
||||||
if (tileInfo.naturalWonder != null) return listOf(tileSetStrings.getTile(tileInfo.naturalWonder!!))
|
if (tileInfo.naturalWonder != null) return listOf(tileSetStrings.orFallback { getTile(tileInfo.naturalWonder!!) })
|
||||||
|
|
||||||
val shownImprovement = tileInfo.getShownImprovement(viewingCiv)
|
val shownImprovement = tileInfo.getShownImprovement(viewingCiv)
|
||||||
val shouldShowImprovement = (shownImprovement != null && UncivGame.Current.settings.showPixelImprovements)
|
val shouldShowImprovement = (shownImprovement != null && UncivGame.Current.settings.showPixelImprovements)
|
||||||
@ -237,13 +237,13 @@ open class TileGroup(var tileInfo: TileInfo, val tileSetStrings:TileSetStrings,
|
|||||||
return tileSetStrings.tileSetConfig.ruleVariants[allTerrains]!!.map { tileSetStrings.getTile(it) }
|
return tileSetStrings.tileSetConfig.ruleVariants[allTerrains]!!.map { tileSetStrings.getTile(it) }
|
||||||
val allTerrainTile = tileSetStrings.getTile(allTerrains)
|
val allTerrainTile = tileSetStrings.getTile(allTerrains)
|
||||||
return if (ImageGetter.imageExists(allTerrainTile)) listOf(allTerrainTile)
|
return if (ImageGetter.imageExists(allTerrainTile)) listOf(allTerrainTile)
|
||||||
else terrainSequence.map { tileSetStrings.getTile(it) }.toList()
|
else terrainSequence.map { tileSetStrings.orFallback { getTile(it) } }.toList()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getImprovementAndResourceImages(resourceAndImprovementSequence: Sequence<String>): List<String> {
|
private fun getImprovementAndResourceImages(resourceAndImprovementSequence: Sequence<String>): List<String> {
|
||||||
val altogether = resourceAndImprovementSequence.joinToString("+").let { tileSetStrings.getTile(it) }
|
val altogether = resourceAndImprovementSequence.joinToString("+").let { tileSetStrings.getTile(it) }
|
||||||
return if (ImageGetter.imageExists(altogether)) listOf(altogether)
|
return if (ImageGetter.imageExists(altogether)) listOf(altogether)
|
||||||
else resourceAndImprovementSequence.map { tileSetStrings.getTile(it) }.toList()
|
else resourceAndImprovementSequence.map { tileSetStrings.orFallback { getTile(it) } }.toList()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Used for both the underlying tile and unit overlays, perhaps for other things in the future
|
// Used for both the underlying tile and unit overlays, perhaps for other things in the future
|
||||||
@ -297,7 +297,7 @@ open class TileGroup(var tileInfo: TileInfo, val tileSetStrings:TileSetStrings,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (tileBaseImages.isEmpty()) { // Absolutely nothing! This is for the 'default' tileset
|
if (tileBaseImages.isEmpty()) { // Absolutely nothing! This is for the 'default' tileset
|
||||||
val image = ImageGetter.getImage(tileSetStrings.hexagon)
|
val image = ImageGetter.getImage(tileSetStrings.orFallback { hexagon })
|
||||||
tileBaseImages.add(image)
|
tileBaseImages.add(image)
|
||||||
baseLayerGroup.addActor(image)
|
baseLayerGroup.addActor(image)
|
||||||
setHexagonImageSize(image)
|
setHexagonImageSize(image)
|
||||||
@ -381,7 +381,7 @@ open class TileGroup(var tileInfo: TileInfo, val tileSetStrings:TileSetStrings,
|
|||||||
baseTerrainOverlayImage = null
|
baseTerrainOverlayImage = null
|
||||||
}
|
}
|
||||||
|
|
||||||
val imagePath = tileSetStrings.getBaseTerrainOverlay(baseTerrain)
|
val imagePath = tileSetStrings.orFallback { getBaseTerrainOverlay(baseTerrain) }
|
||||||
if (!ImageGetter.imageExists(imagePath)) return
|
if (!ImageGetter.imageExists(imagePath)) return
|
||||||
baseTerrainOverlayImage = ImageGetter.getImage(imagePath)
|
baseTerrainOverlayImage = ImageGetter.getImage(imagePath)
|
||||||
baseTerrainOverlayImage!!.run {
|
baseTerrainOverlayImage!!.run {
|
||||||
@ -606,7 +606,7 @@ open class TileGroup(var tileInfo: TileInfo, val tileSetStrings:TileSetStrings,
|
|||||||
}
|
}
|
||||||
if (roadStatus == RoadStatus.None) continue // no road image
|
if (roadStatus == RoadStatus.None) continue // no road image
|
||||||
|
|
||||||
val image = ImageGetter.getImage(tileSetStrings.roadsMap[roadStatus]!!)
|
val image = ImageGetter.getImage(tileSetStrings.orFallback { roadsMap[roadStatus]!! })
|
||||||
roadImage.image = image
|
roadImage.image = image
|
||||||
|
|
||||||
val relativeWorldPosition = tileInfo.tileMap.getNeighborTilePositionAsWorldCoords(tileInfo, neighbor)
|
val relativeWorldPosition = tileInfo.tileMap.getNeighborTilePositionAsWorldCoords(tileInfo, neighbor)
|
||||||
@ -644,7 +644,7 @@ open class TileGroup(var tileInfo: TileInfo, val tileSetStrings:TileSetStrings,
|
|||||||
terrainFeatureOverlayImage = null
|
terrainFeatureOverlayImage = null
|
||||||
|
|
||||||
for (terrainFeature in terrainFeatures) {
|
for (terrainFeature in terrainFeatures) {
|
||||||
val terrainFeatureOverlayLocation = tileSetStrings.getTerrainFeatureOverlay(terrainFeature)
|
val terrainFeatureOverlayLocation = tileSetStrings.orFallback { getTerrainFeatureOverlay(terrainFeature) }
|
||||||
if (!ImageGetter.imageExists(terrainFeatureOverlayLocation)) return
|
if (!ImageGetter.imageExists(terrainFeatureOverlayLocation)) return
|
||||||
terrainFeatureOverlayImage = ImageGetter.getImage(terrainFeatureOverlayLocation)
|
terrainFeatureOverlayImage = ImageGetter.getImage(terrainFeatureOverlayLocation)
|
||||||
terrainFeatureLayerGroup.addActor(terrainFeatureOverlayImage)
|
terrainFeatureLayerGroup.addActor(terrainFeatureOverlayImage)
|
||||||
@ -662,8 +662,9 @@ open class TileGroup(var tileInfo: TileInfo, val tileSetStrings:TileSetStrings,
|
|||||||
val militaryUnit = tileInfo.militaryUnit
|
val militaryUnit = tileInfo.militaryUnit
|
||||||
if (militaryUnit != null && showMilitaryUnit) {
|
if (militaryUnit != null && showMilitaryUnit) {
|
||||||
val unitType = militaryUnit.type
|
val unitType = militaryUnit.type
|
||||||
val specificUnitIconLocation = tileSetStrings.unitsLocation + militaryUnit.name
|
fun TileSetStrings.getThisUnit(): String? {
|
||||||
newImageLocation = when {
|
val specificUnitIconLocation = this.unitsLocation + militaryUnit.name
|
||||||
|
return when {
|
||||||
!UncivGame.Current.settings.showPixelUnits -> ""
|
!UncivGame.Current.settings.showPixelUnits -> ""
|
||||||
militaryUnit.civInfo.nation.style=="" &&
|
militaryUnit.civInfo.nation.style=="" &&
|
||||||
ImageGetter.imageExists(specificUnitIconLocation) -> specificUnitIconLocation
|
ImageGetter.imageExists(specificUnitIconLocation) -> specificUnitIconLocation
|
||||||
@ -671,23 +672,25 @@ open class TileGroup(var tileInfo: TileInfo, val tileSetStrings:TileSetStrings,
|
|||||||
specificUnitIconLocation + "-" + militaryUnit.civInfo.nation.style
|
specificUnitIconLocation + "-" + militaryUnit.civInfo.nation.style
|
||||||
ImageGetter.imageExists(specificUnitIconLocation) -> specificUnitIconLocation
|
ImageGetter.imageExists(specificUnitIconLocation) -> specificUnitIconLocation
|
||||||
militaryUnit.baseUnit.replaces != null &&
|
militaryUnit.baseUnit.replaces != null &&
|
||||||
ImageGetter.imageExists(tileSetStrings.unitsLocation + militaryUnit.baseUnit.replaces) ->
|
ImageGetter.imageExists(this.unitsLocation + militaryUnit.baseUnit.replaces) ->
|
||||||
tileSetStrings.unitsLocation + militaryUnit.baseUnit.replaces
|
this.unitsLocation + militaryUnit.baseUnit.replaces
|
||||||
|
|
||||||
militaryUnit.civInfo.gameInfo.ruleSet.units.values.any {
|
militaryUnit.civInfo.gameInfo.ruleSet.units.values.any {
|
||||||
it.unitType == unitType.name && ImageGetter.unitIconExists(it.name)
|
it.unitType == unitType.name && ImageGetter.imageExists(this.unitsLocation + it.name)
|
||||||
} ->
|
} ->
|
||||||
{
|
{
|
||||||
val unitWithSprite = militaryUnit.civInfo.gameInfo.ruleSet.units.values.first {
|
val unitWithSprite = militaryUnit.civInfo.gameInfo.ruleSet.units.values.first {
|
||||||
it.unitType == unitType.name && ImageGetter.unitIconExists(it.name)
|
it.unitType == unitType.name && ImageGetter.imageExists(this.unitsLocation + it.name)
|
||||||
}.name
|
}.name
|
||||||
tileSetStrings.unitsLocation + unitWithSprite
|
this.unitsLocation + unitWithSprite
|
||||||
}
|
}
|
||||||
unitType.isLandUnit() && ImageGetter.imageExists(tileSetStrings.landUnit) -> tileSetStrings.landUnit
|
unitType.isLandUnit() && ImageGetter.imageExists(this.landUnit) -> this.landUnit
|
||||||
unitType.isWaterUnit() && ImageGetter.imageExists(tileSetStrings.waterUnit) -> tileSetStrings.waterUnit
|
unitType.isWaterUnit() && ImageGetter.imageExists(this.waterUnit) -> this.waterUnit
|
||||||
else -> ""
|
else -> null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
newImageLocation = tileSetStrings.getThisUnit() ?: tileSetStrings.fallback?.getThisUnit() ?: ""
|
||||||
|
}
|
||||||
|
|
||||||
if (pixelMilitaryUnitImageLocation != newImageLocation) {
|
if (pixelMilitaryUnitImageLocation != newImageLocation) {
|
||||||
pixelMilitaryUnitGroup.clear()
|
pixelMilitaryUnitGroup.clear()
|
||||||
@ -710,17 +713,20 @@ open class TileGroup(var tileInfo: TileInfo, val tileSetStrings:TileSetStrings,
|
|||||||
val civilianUnit = tileInfo.civilianUnit
|
val civilianUnit = tileInfo.civilianUnit
|
||||||
|
|
||||||
if (civilianUnit != null && tileIsViewable) {
|
if (civilianUnit != null && tileIsViewable) {
|
||||||
val specificUnitIconLocation = tileSetStrings.unitsLocation + civilianUnit.name
|
fun TileSetStrings.getThisUnit(): String? {
|
||||||
newImageLocation = when {
|
val specificUnitIconLocation = this.unitsLocation + civilianUnit.name
|
||||||
|
return when {
|
||||||
!UncivGame.Current.settings.showPixelUnits -> ""
|
!UncivGame.Current.settings.showPixelUnits -> ""
|
||||||
civilianUnit.civInfo.nation.style=="" &&
|
civilianUnit.civInfo.nation.style=="" &&
|
||||||
ImageGetter.imageExists(specificUnitIconLocation) -> specificUnitIconLocation
|
ImageGetter.imageExists(specificUnitIconLocation) -> specificUnitIconLocation
|
||||||
ImageGetter.imageExists(specificUnitIconLocation + "-" + civilianUnit.civInfo.nation.style) ->
|
ImageGetter.imageExists(specificUnitIconLocation + "-" + civilianUnit.civInfo.nation.style) ->
|
||||||
specificUnitIconLocation + "-" + civilianUnit.civInfo.nation.style
|
specificUnitIconLocation + "-" + civilianUnit.civInfo.nation.style
|
||||||
ImageGetter.imageExists(specificUnitIconLocation) -> specificUnitIconLocation
|
ImageGetter.imageExists(specificUnitIconLocation) -> specificUnitIconLocation
|
||||||
else -> ""
|
else -> null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
newImageLocation = tileSetStrings.getThisUnit() ?: tileSetStrings.fallback?.getThisUnit() ?: ""
|
||||||
|
}
|
||||||
|
|
||||||
if (pixelCivilianUnitImageLocation != newImageLocation) {
|
if (pixelCivilianUnitImageLocation != newImageLocation) {
|
||||||
pixelCivilianUnitGroup.clear()
|
pixelCivilianUnitGroup.clear()
|
||||||
@ -743,9 +749,9 @@ open class TileGroup(var tileInfo: TileInfo, val tileSetStrings:TileSetStrings,
|
|||||||
private var bottomLeftRiverImage :Image?=null
|
private var bottomLeftRiverImage :Image?=null
|
||||||
|
|
||||||
private fun updateRivers(displayBottomRight:Boolean, displayBottom:Boolean, displayBottomLeft:Boolean){
|
private fun updateRivers(displayBottomRight:Boolean, displayBottom:Boolean, displayBottomLeft:Boolean){
|
||||||
bottomRightRiverImage = updateRiver(bottomRightRiverImage,displayBottomRight,tileSetStrings.bottomRightRiver)
|
bottomRightRiverImage = updateRiver(bottomRightRiverImage,displayBottomRight, tileSetStrings.orFallback { bottomRightRiver })
|
||||||
bottomRiverImage = updateRiver(bottomRiverImage, displayBottom, tileSetStrings.bottomRiver)
|
bottomRiverImage = updateRiver(bottomRiverImage, displayBottom, tileSetStrings.orFallback { bottomRiver })
|
||||||
bottomLeftRiverImage = updateRiver(bottomLeftRiverImage,displayBottomLeft,tileSetStrings.bottomLeftRiver)
|
bottomLeftRiverImage = updateRiver(bottomLeftRiverImage, displayBottomLeft, tileSetStrings.orFallback { bottomLeftRiver })
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateRiver(currentImage:Image?, shouldDisplay:Boolean,imageName:String): Image? {
|
private fun updateRiver(currentImage:Image?, shouldDisplay:Boolean,imageName:String): Image? {
|
||||||
|
@ -4,12 +4,18 @@ import com.unciv.UncivGame
|
|||||||
import com.unciv.logic.map.RoadStatus
|
import com.unciv.logic.map.RoadStatus
|
||||||
import com.unciv.models.tilesets.TileSetCache
|
import com.unciv.models.tilesets.TileSetCache
|
||||||
import com.unciv.models.tilesets.TileSetConfig
|
import com.unciv.models.tilesets.TileSetConfig
|
||||||
|
import com.unciv.ui.utils.ImageGetter
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param tileSet Name of the tileset. Defaults to active at time of instantiation.
|
||||||
|
* @param fallbackDepth Maximum number of fallback tilesets to try. Used to prevent infinite recursion.
|
||||||
|
* */
|
||||||
|
class TileSetStrings(tileSet: String = UncivGame.Current.settings.tileSet, fallbackDepth: Int = 1) {
|
||||||
|
|
||||||
class TileSetStrings {
|
|
||||||
// this is so that when we have 100s of TileGroups, they won't all individually come up with all these strings themselves,
|
// this is so that when we have 100s of TileGroups, they won't all individually come up with all these strings themselves,
|
||||||
// it gets pretty memory-intensive (10s of MBs which is a lot for lower-end phones)
|
// it gets pretty memory-intensive (10s of MBs which is a lot for lower-end phones)
|
||||||
val tileSetLocation = "TileSets/" + UncivGame.Current.settings.tileSet + "/"
|
val tileSetLocation = "TileSets/$tileSet/"
|
||||||
val tileSetConfig = TileSetCache[UncivGame.Current.settings.tileSet] ?: TileSetConfig()
|
val tileSetConfig = TileSetCache[tileSet] ?: TileSetConfig()
|
||||||
|
|
||||||
val hexagon = tileSetLocation + "Hexagon"
|
val hexagon = tileSetLocation + "Hexagon"
|
||||||
val crosshatchHexagon = tileSetLocation + "CrosshatchHexagon"
|
val crosshatchHexagon = tileSetLocation + "CrosshatchHexagon"
|
||||||
@ -66,4 +72,30 @@ class TileSetStrings {
|
|||||||
if (baseTerrain != null) return getString(tilesLocation, baseTerrain, "+", city)
|
if (baseTerrain != null) return getString(tilesLocation, baseTerrain, "+", city)
|
||||||
else return cityTile
|
else return cityTile
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Fallback [TileSetStrings] to use when the currently chosen tileset is missing an image. */
|
||||||
|
val fallback by lazy {
|
||||||
|
if (fallbackDepth <= 0 || tileSetConfig.fallbackTileSet == null)
|
||||||
|
null
|
||||||
|
else
|
||||||
|
TileSetStrings(tileSetConfig.fallbackTileSet!!, fallbackDepth-1)
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @param image An image path string, such as returned from an instance of [TileSetStrings].
|
||||||
|
* @param fallbackImage A lambda function that will be run with the [fallback] as its receiver if the original image does not exist according to [ImageGetter.imageExists].
|
||||||
|
* @return The original image path string if its image exists, or the return result of the [fallbackImage] lambda if the original image does not exist.
|
||||||
|
* */
|
||||||
|
fun orFallback(image: String, fallbackImage: TileSetStrings.() -> String): String {
|
||||||
|
return if (fallback == null || ImageGetter.imageExists(image))
|
||||||
|
image
|
||||||
|
else
|
||||||
|
fallback!!.run(fallbackImage)
|
||||||
|
}
|
||||||
|
/** @see orFallback */
|
||||||
|
fun orFallback(image: TileSetStrings.() -> String, fallbackImage: TileSetStrings.() -> String)
|
||||||
|
= orFallback(this.run(image), fallbackImage)
|
||||||
|
/** @see orFallback */
|
||||||
|
fun orFallback(image: TileSetStrings.() -> String)
|
||||||
|
= orFallback(image, image)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user