Resolved race-condition error for loading terrain icons

This commit is contained in:
yairm210 2024-09-29 23:11:55 +03:00
parent 2a8f0be257
commit 660ae105c3
2 changed files with 15 additions and 10 deletions

View File

@ -8,7 +8,9 @@ import com.badlogic.gdx.graphics.glutils.FrameBuffer
import com.badlogic.gdx.math.Matrix4
import com.badlogic.gdx.scenes.scene2d.Actor
import com.badlogic.gdx.scenes.scene2d.Group
import com.unciv.UncivGame
import com.unciv.models.ruleset.Ruleset
import com.unciv.models.tilesets.TileSetCache
import com.unciv.ui.components.extensions.center
import com.unciv.ui.components.extensions.setSize
import com.unciv.ui.components.fonts.FontRulesetIcons.getPixmapFromActor
@ -75,15 +77,18 @@ object FontRulesetIcons {
addChar(policy.name, ImageGetter.getImage(fileLocation).apply { setSize(Fonts.ORIGINAL_FONT_SIZE) })
}
for (terrain in ruleset.terrains.values) {
// These ensure that the font icons are correctly sized - tilegroup rendering works differently than others, to account for clickability vs rendered areas
val tileGroup = CivilopediaImageGetters.terrainImage(terrain, ruleset, Fonts.ORIGINAL_FONT_SIZE)
tileGroup.width *= 1.5f
tileGroup.height *= 1.5f
for (layer in tileGroup.children) layer.center(tileGroup)
addChar(terrain.name, tileGroup)
}
// Upon *game initialization* we can get here without the tileset being loaded yet
// in which case we can't add terrain icons
if (TileSetCache.containsKey(UncivGame.Current.settings.tileSet))
for (terrain in ruleset.terrains.values) {
// These ensure that the font icons are correctly sized - tilegroup rendering works differently than others, to account for clickability vs rendered areas
val tileGroup = CivilopediaImageGetters.terrainImage(terrain, ruleset, Fonts.ORIGINAL_FONT_SIZE)
tileGroup.width *= 1.5f
tileGroup.height *= 1.5f
for (layer in tileGroup.children) layer.center(tileGroup)
addChar(terrain.name, tileGroup)
}
}

View File

@ -49,7 +49,7 @@ private class MapArrow(val targetTile: Tile, val arrowType: MapArrowType, val st
class TileLayerMisc(tileGroup: TileGroup, size: Float) : TileLayer(tileGroup, size) {
// For different unit views, we want to effectively "ignore" the terrain and color it by special view
private val terrainOverlay = ImageGetter.getImage(strings().hexagon ).setHexagonSize()
private val terrainOverlay = ImageGetter.getImage(strings().hexagon).setHexagonSize()
init {
terrainOverlay.isVisible = false