mirror of
https://github.com/yairm210/Unciv.git
synced 2025-03-10 12:51:16 +07:00
Resolved #12477 - Limited, but performant, edge filters
This brings back 'edges below improvements'
This commit is contained in:
parent
f2221ddf43
commit
3c7bf97148
@ -78,14 +78,19 @@ class TileLayerTerrain(tileGroup: TileGroup, size: Float) : TileLayer(tileGroup,
|
||||
val terrainImages = if (tile.naturalWonder != null)
|
||||
sequenceOf(tile.baseTerrain, tile.naturalWonder!!)
|
||||
else sequenceOf(tile.baseTerrain) + tile.terrainFeatures.asSequence()
|
||||
val edgeImages = getEdgeTileLocations()
|
||||
val allTogether = (terrainImages + resourceAndImprovementSequence).joinToString("+")
|
||||
val allTogetherLocation = strings().getTile(allTogether)
|
||||
|
||||
// If the tilesetconfig *explicitly* lists the terrains+improvements etc, we can't know where in that list to place the edges
|
||||
// So we default to placing them over everything else.
|
||||
// If there is no explicit list, then we can know to place them between the terrain and the improvement
|
||||
return when {
|
||||
strings().tileSetConfig.ruleVariants[allTogether] != null -> baseHexagon + strings().tileSetConfig.ruleVariants[allTogether]!!.map { strings().getTile(it) }
|
||||
ImageGetter.imageExists(allTogetherLocation) -> baseHexagon + allTogetherLocation
|
||||
tile.naturalWonder != null -> getNaturalWonderBackupImage(baseHexagon)
|
||||
else -> baseHexagon + getTerrainImageLocations(terrainImages) + getImprovementAndResourceImages(resourceAndImprovementSequence)
|
||||
strings().tileSetConfig.ruleVariants[allTogether] != null -> baseHexagon +
|
||||
strings().tileSetConfig.ruleVariants[allTogether]!!.map { strings().getTile(it) } + edgeImages
|
||||
ImageGetter.imageExists(allTogetherLocation) -> baseHexagon + allTogetherLocation + edgeImages
|
||||
tile.naturalWonder != null -> getNaturalWonderBackupImage(baseHexagon) + edgeImages
|
||||
else -> baseHexagon + getTerrainImageLocations(terrainImages) + edgeImages + getImprovementAndResourceImages(resourceAndImprovementSequence)
|
||||
}
|
||||
}
|
||||
|
||||
@ -102,10 +107,17 @@ class TileLayerTerrain(tileGroup: TileGroup, size: Float) : TileLayer(tileGroup,
|
||||
val direction = NeighborDirection.fromVector(vectorToNeighbor)
|
||||
?: return emptyList()
|
||||
val possibleEdgeFiles = strings().edgeImagesByPosition[direction] ?: return emptyList()
|
||||
|
||||
// Required for performance - full matchesFilter is too expensive for something that needs to run every update()
|
||||
fun matchesFilterMinimal(originTile: Tile, filter: String): Boolean {
|
||||
if (originTile.allTerrains.any { it.name == filter }) return true
|
||||
if (originTile.getBaseTerrain().type.name == filter) return true
|
||||
return false
|
||||
}
|
||||
|
||||
return possibleEdgeFiles.filter {
|
||||
if (!originTile.matchesFilter(it.originTileFilter)) return@filter false
|
||||
if (!neighborTile.matchesFilter(it.destinationTileFilter)) return@filter false
|
||||
if (!matchesFilterMinimal(originTile, it.originTileFilter)) return@filter false
|
||||
if (!matchesFilterMinimal(neighborTile, it.destinationTileFilter)) return@filter false
|
||||
return@filter true
|
||||
}.map { it.fileName }
|
||||
}
|
||||
@ -119,11 +131,9 @@ class TileLayerTerrain(tileGroup: TileGroup, size: Float) : TileLayer(tileGroup,
|
||||
}
|
||||
tileImageIdentifiers = tileBaseImageLocations
|
||||
|
||||
val allImages = tileBaseImageLocations + getEdgeTileLocations()
|
||||
|
||||
for (image in tileBaseImages) image.remove()
|
||||
tileBaseImages.clear()
|
||||
for (baseLocation in allImages) {
|
||||
for (baseLocation in tileBaseImageLocations) {
|
||||
// Here we check what actual tiles exist, and pick one - not at random, but based on the tile location,
|
||||
// so it stays consistent throughout the game
|
||||
if (!ImageGetter.imageExists(baseLocation)) continue
|
||||
|
@ -162,6 +162,11 @@ The name of the tile should be `<tile name>-<origin tile filter>-<destination ti
|
||||
- TopLeft
|
||||
- TopRight
|
||||
|
||||
And where the tile filter is one of:
|
||||
- Terrain name
|
||||
- Feature name
|
||||
- Terrain type (Land/Water)
|
||||
|
||||
For example: `Cliff-Hills-Coast-Top.png`
|
||||
|
||||
The initial name has no bearing on the image used, it is just a way to group images together.
|
||||
|
Loading…
Reference in New Issue
Block a user