Resolved #9177 - Tileset no longer reverts to default on Android after restarting game

This commit is contained in:
Yair Morgenstern 2023-04-13 17:41:59 +03:00
parent f98f4e8c9b
commit 2fbd24231f
2 changed files with 15 additions and 14 deletions

View File

@ -189,8 +189,8 @@ open class UncivGame(val isConsoleMode: Boolean = false) : Game(), PlatformSpeci
ImageGetter.resetAtlases()
ImageGetter.setNewRuleset(ImageGetter.ruleset) // This needs to come after the settings, since we may have default visual mods
val availableTileSets = ImageGetter.getAvailableTilesets().toSet()
.intersect(TileSetCache.getAvailableTilesets().toSet())
val imageGetterTilesets = ImageGetter.getAvailableTilesets()
val availableTileSets = TileSetCache.getAvailableTilesets(imageGetterTilesets)
if (settings.tileSet !in availableTileSets) { // If the configured tileset is no longer available, default back
settings.tileSet = Constants.defaultTileset
}

View File

@ -82,18 +82,19 @@ object TileSetCache : HashMap<String, TileSet>() {
}
/** Determines potentially available TileSets - by scanning for TileSet jsons.
*
* Available before initialization finishes.
* To get more reliable info, either wait until `this` is fully initialized,
* or intersect with [ImageGetter.getAvailableTilesets]
*/
fun getAvailableTilesets() = sequence<FileHandle> {
yieldAll(FileHandle("jsons/TileSets").list().asIterable())
for (modFolder in FileHandle("mods").list()) {
if (!modFolder.isDirectory || modFolder.name().startsWith('.'))
continue
yieldAll(modFolder.child("jsons/TileSets").list().asIterable())
}
}.filter { it.exists() }
.map { it.nameWithoutExtension().removeSuffix("Config") }
fun getAvailableTilesets(imageGetterTilesets:Sequence<String>): Set<String> {
val modTilesetConfigFiles = Gdx.files.local("mods").list().asSequence()
.filter { it.isDirectory && !it.name().startsWith('.') }
.flatMap { it.child("jsons/TileSets").list().asSequence() }
val builtinTilesetConfigFiles = imageGetterTilesets
.map { Gdx.files.internal("jsons/TileSets/$it.json") }
return (builtinTilesetConfigFiles + modTilesetConfigFiles)
.filter { it.exists() }
.map { it.nameWithoutExtension().removeSuffix("Config") }
.toSet()
}
}