mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-26 13:27:22 -04:00
Accelerate custom map selection a tiny bit (#6815)
This commit is contained in:
parent
6021dcadb8
commit
07562f23ff
@ -3,6 +3,7 @@ package com.unciv.logic
|
||||
import com.badlogic.gdx.Gdx
|
||||
import com.badlogic.gdx.files.FileHandle
|
||||
import com.unciv.json.json
|
||||
import com.unciv.logic.map.MapParameters
|
||||
import com.unciv.logic.map.TileMap
|
||||
import com.unciv.ui.saves.Gzip
|
||||
|
||||
@ -41,11 +42,27 @@ object MapSaver {
|
||||
getMap(mapName).writeString(mapToSavedString(tileMap), false)
|
||||
}
|
||||
|
||||
fun loadMap(mapFile:FileHandle, checkSizeErrors: Boolean = true):TileMap {
|
||||
fun loadMap(mapFile: FileHandle, checkSizeErrors: Boolean = true): TileMap {
|
||||
return mapFromSavedString(mapFile.readString(), checkSizeErrors)
|
||||
}
|
||||
|
||||
fun getMaps(): Array<FileHandle> = Gdx.files.local(mapsFolder).list()
|
||||
|
||||
private fun mapFromJson(json:String): TileMap = json().fromJson(TileMap::class.java, json)
|
||||
private fun mapFromJson(json: String): TileMap = json().fromJson(TileMap::class.java, json)
|
||||
|
||||
/** Class to parse only the parameters out of a map file */
|
||||
private class TileMapPreview {
|
||||
val mapParameters = MapParameters()
|
||||
}
|
||||
fun loadMapParameters(mapFile: FileHandle): MapParameters {
|
||||
return mapParametersFromSavedString(mapFile.readString())
|
||||
}
|
||||
fun mapParametersFromSavedString(mapString: String): MapParameters {
|
||||
val unzippedJson = try {
|
||||
Gzip.unzip(mapString.trim())
|
||||
} catch (ex: Exception) {
|
||||
mapString
|
||||
}
|
||||
return json().fromJson(TileMapPreview::class.java, unzippedJson).mapParameters
|
||||
}
|
||||
}
|
||||
|
@ -91,9 +91,8 @@ class MapOptionsTable(private val newGameScreen: NewGameScreen): Table() {
|
||||
val mapFileSelectBox = SelectBox<FileHandleWrapper>(BaseScreen.skin)
|
||||
mapFileSelectBox.onChange {
|
||||
val mapFile = mapFileSelectBox.selected.fileHandle
|
||||
val map: TileMap
|
||||
try {
|
||||
map = MapSaver.loadMap(mapFile)
|
||||
val mapParams = try {
|
||||
MapSaver.loadMapParameters(mapFile)
|
||||
} catch (ex:Exception){
|
||||
ex.printStackTrace()
|
||||
Popup(newGameScreen).apply {
|
||||
@ -107,9 +106,9 @@ class MapOptionsTable(private val newGameScreen: NewGameScreen): Table() {
|
||||
}
|
||||
mapParameters.name = mapFile.name()
|
||||
newGameScreen.gameSetupInfo.mapFile = mapFile
|
||||
val mapMods = map.mapParameters.mods.partition { RulesetCache[it]?.modOptions?.isBaseRuleset == true }
|
||||
val mapMods = mapParams.mods.partition { RulesetCache[it]?.modOptions?.isBaseRuleset == true }
|
||||
newGameScreen.gameSetupInfo.gameParameters.mods = LinkedHashSet(mapMods.second)
|
||||
newGameScreen.gameSetupInfo.gameParameters.baseRuleset = mapMods.first.firstOrNull() ?: map.mapParameters.baseRuleset
|
||||
newGameScreen.gameSetupInfo.gameParameters.baseRuleset = mapMods.first.firstOrNull() ?: mapParams.baseRuleset
|
||||
newGameScreen.updateRuleset()
|
||||
newGameScreen.updateTables()
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user