mirror of
https://github.com/yairm210/Unciv.git
synced 2025-02-12 03:48:16 +07:00
Resolve #8336 - Remove 'incorrect area' code for super-old maps
This commit is contained in:
parent
37cfc12a64
commit
f9da3204b6
@ -524,8 +524,6 @@ Area: [amount] tiles, [amount2]% water, [amount3] continents/islands =
|
|||||||
Do you want to leave without saving the recent changes? =
|
Do you want to leave without saving the recent changes? =
|
||||||
Leave =
|
Leave =
|
||||||
Do you want to load another map without saving the recent changes? =
|
Do you want to load another map without saving the recent changes? =
|
||||||
Invalid map: Area ([area]) does not match saved dimensions ([dimensions]). =
|
|
||||||
The dimensions have now been fixed for you. =
|
|
||||||
River generation failed! =
|
River generation failed! =
|
||||||
Please don't use step 'Landmass' with map type 'Empty', create a new empty map instead. =
|
Please don't use step 'Landmass' with map type 'Empty', create a new empty map instead. =
|
||||||
This map has errors: =
|
This map has errors: =
|
||||||
|
@ -14,23 +14,13 @@ object MapSaver {
|
|||||||
|
|
||||||
private fun getMap(mapName:String) = Gdx.files.local("$mapsFolder/$mapName")
|
private fun getMap(mapName:String) = Gdx.files.local("$mapsFolder/$mapName")
|
||||||
|
|
||||||
fun mapFromSavedString(mapString: String, checkSizeErrors: Boolean = true): TileMap {
|
fun mapFromSavedString(mapString: String): TileMap {
|
||||||
val unzippedJson = try {
|
val unzippedJson = try {
|
||||||
Gzip.unzip(mapString.trim())
|
Gzip.unzip(mapString.trim())
|
||||||
} catch (ex: Exception) {
|
} catch (ex: Exception) {
|
||||||
mapString
|
mapString
|
||||||
}
|
}
|
||||||
return mapFromJson(unzippedJson).apply {
|
return mapFromJson(unzippedJson)
|
||||||
// old maps (rarely) can come with mapSize fields not matching tile list
|
|
||||||
if (checkSizeErrors && mapParameters.getArea() != values.size)
|
|
||||||
throw UncivShowableException("Invalid map: Area ([${values.size}]) does not match saved dimensions ([${mapParameters.displayMapDimensions()}]).")
|
|
||||||
// compatibility with rare maps saved with old mod names
|
|
||||||
if (!checkSizeErrors)
|
|
||||||
mapParameters.mods.filter { '-' in it }.forEach {
|
|
||||||
mapParameters.mods.remove(it)
|
|
||||||
mapParameters.mods.add(it.replace('-',' '))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
fun mapToSavedString(tileMap: TileMap): String {
|
fun mapToSavedString(tileMap: TileMap): String {
|
||||||
tileMap.assignContinents(TileMap.AssignContinentsMode.Reassign)
|
tileMap.assignContinents(TileMap.AssignContinentsMode.Reassign)
|
||||||
@ -38,12 +28,12 @@ object MapSaver {
|
|||||||
return if (saveZipped) Gzip.zip(mapJson) else mapJson
|
return if (saveZipped) Gzip.zip(mapJson) else mapJson
|
||||||
}
|
}
|
||||||
|
|
||||||
fun saveMap(mapName: String,tileMap: TileMap) {
|
fun saveMap(mapName: String, tileMap: TileMap) {
|
||||||
getMap(mapName).writeString(mapToSavedString(tileMap), false)
|
getMap(mapName).writeString(mapToSavedString(tileMap), false)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun loadMap(mapFile: FileHandle, checkSizeErrors: Boolean = true): TileMap {
|
fun loadMap(mapFile: FileHandle): TileMap {
|
||||||
return mapFromSavedString(mapFile.readString(), checkSizeErrors)
|
return mapFromSavedString(mapFile.readString())
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getMaps(): Array<FileHandle> = Gdx.files.local(mapsFolder).list()
|
fun getMaps(): Array<FileHandle> = Gdx.files.local(mapsFolder).list()
|
||||||
|
@ -9,9 +9,9 @@ import com.unciv.logic.MapSaver
|
|||||||
import com.unciv.logic.UncivShowableException
|
import com.unciv.logic.UncivShowableException
|
||||||
import com.unciv.models.ruleset.RulesetCache
|
import com.unciv.models.ruleset.RulesetCache
|
||||||
import com.unciv.models.translations.tr
|
import com.unciv.models.translations.tr
|
||||||
|
import com.unciv.ui.popup.ConfirmPopup
|
||||||
import com.unciv.ui.popup.Popup
|
import com.unciv.ui.popup.Popup
|
||||||
import com.unciv.ui.popup.ToastPopup
|
import com.unciv.ui.popup.ToastPopup
|
||||||
import com.unciv.ui.popup.ConfirmPopup
|
|
||||||
import com.unciv.ui.utils.AutoScrollPane
|
import com.unciv.ui.utils.AutoScrollPane
|
||||||
import com.unciv.ui.utils.BaseScreen
|
import com.unciv.ui.utils.BaseScreen
|
||||||
import com.unciv.ui.utils.KeyCharAndCode
|
import com.unciv.ui.utils.KeyCharAndCode
|
||||||
@ -105,7 +105,7 @@ class MapEditorLoadTab(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
val map = MapSaver.loadMap(chosenMap!!, checkSizeErrors = false)
|
val map = MapSaver.loadMap(chosenMap!!)
|
||||||
|
|
||||||
val missingMods = map.mapParameters.mods.filter { it !in RulesetCache }.toMutableList()
|
val missingMods = map.mapParameters.mods.filter { it !in RulesetCache }.toMutableList()
|
||||||
// [TEMPORARY] conversion of old maps with a base ruleset contained in the mods
|
// [TEMPORARY] conversion of old maps with a base ruleset contained in the mods
|
||||||
|
@ -75,7 +75,7 @@ class MapEditorOptionsTab(
|
|||||||
private fun pasteHandler() {
|
private fun pasteHandler() {
|
||||||
try {
|
try {
|
||||||
val clipboardContentsString = Gdx.app.clipboard.contents.trim()
|
val clipboardContentsString = Gdx.app.clipboard.contents.trim()
|
||||||
val loadedMap = MapSaver.mapFromSavedString(clipboardContentsString, checkSizeErrors = false)
|
val loadedMap = MapSaver.mapFromSavedString(clipboardContentsString)
|
||||||
editorScreen.loadMap(loadedMap)
|
editorScreen.loadMap(loadedMap)
|
||||||
} catch (ex: Exception) {
|
} catch (ex: Exception) {
|
||||||
ToastPopup("Could not load map!", editorScreen)
|
ToastPopup("Could not load map!", editorScreen)
|
||||||
|
@ -3,9 +3,7 @@ package com.unciv.ui.mapeditor
|
|||||||
import com.badlogic.gdx.Gdx
|
import com.badlogic.gdx.Gdx
|
||||||
import com.badlogic.gdx.graphics.Color
|
import com.badlogic.gdx.graphics.Color
|
||||||
import com.unciv.UncivGame
|
import com.unciv.UncivGame
|
||||||
import com.unciv.logic.HexMath
|
|
||||||
import com.unciv.logic.map.MapParameters
|
import com.unciv.logic.map.MapParameters
|
||||||
import com.unciv.logic.map.MapShape
|
|
||||||
import com.unciv.logic.map.MapSize
|
import com.unciv.logic.map.MapSize
|
||||||
import com.unciv.logic.map.MapSizeNew
|
import com.unciv.logic.map.MapSizeNew
|
||||||
import com.unciv.logic.map.TileInfo
|
import com.unciv.logic.map.TileInfo
|
||||||
@ -14,10 +12,8 @@ import com.unciv.models.metadata.BaseRuleset
|
|||||||
import com.unciv.models.metadata.GameSetupInfo
|
import com.unciv.models.metadata.GameSetupInfo
|
||||||
import com.unciv.models.ruleset.Ruleset
|
import com.unciv.models.ruleset.Ruleset
|
||||||
import com.unciv.models.ruleset.RulesetCache
|
import com.unciv.models.ruleset.RulesetCache
|
||||||
import com.unciv.models.translations.tr
|
|
||||||
import com.unciv.ui.images.ImageGetter
|
import com.unciv.ui.images.ImageGetter
|
||||||
import com.unciv.ui.popup.ConfirmPopup
|
import com.unciv.ui.popup.ConfirmPopup
|
||||||
import com.unciv.ui.popup.ToastPopup
|
|
||||||
import com.unciv.ui.tilegroups.TileGroup
|
import com.unciv.ui.tilegroups.TileGroup
|
||||||
import com.unciv.ui.utils.BaseScreen
|
import com.unciv.ui.utils.BaseScreen
|
||||||
import com.unciv.ui.utils.KeyCharAndCode
|
import com.unciv.ui.utils.KeyCharAndCode
|
||||||
@ -159,7 +155,6 @@ class MapEditorScreen(map: TileMap? = null): BaseScreen(), RecreateOnResize {
|
|||||||
fun loadMap(map: TileMap, newRuleset: Ruleset? = null, selectPage: Int = 0) {
|
fun loadMap(map: TileMap, newRuleset: Ruleset? = null, selectPage: Int = 0) {
|
||||||
mapHolder.remove()
|
mapHolder.remove()
|
||||||
tileMap = map
|
tileMap = map
|
||||||
checkAndFixMapSize()
|
|
||||||
ruleset = newRuleset ?: RulesetCache.getComplexRuleset(map.mapParameters)
|
ruleset = newRuleset ?: RulesetCache.getComplexRuleset(map.mapParameters)
|
||||||
mapHolder = newMapHolder()
|
mapHolder = newMapHolder()
|
||||||
isDirty = false
|
isDirty = false
|
||||||
@ -217,31 +212,5 @@ class MapEditorScreen(map: TileMap? = null): BaseScreen(), RecreateOnResize {
|
|||||||
highlightTile(tile, color)
|
highlightTile(tile, color)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun checkAndFixMapSize() {
|
|
||||||
val areaFromTiles = tileMap.values.size
|
|
||||||
val params = tileMap.mapParameters
|
|
||||||
val areaFromSize = params.getArea()
|
|
||||||
if (areaFromSize == areaFromTiles) return
|
|
||||||
|
|
||||||
Gdx.app.postRunnable {
|
|
||||||
val message = ("Invalid map: Area ([$areaFromTiles]) does not match saved dimensions ([" +
|
|
||||||
params.displayMapDimensions() + "]).").tr() +
|
|
||||||
"\n" + "The dimensions have now been fixed for you.".tr()
|
|
||||||
ToastPopup(message, this@MapEditorScreen, 4000L )
|
|
||||||
}
|
|
||||||
|
|
||||||
if (params.shape == MapShape.hexagonal || params.shape == MapShape.flatEarth) {
|
|
||||||
params.mapSize = MapSizeNew(HexMath.getHexagonalRadiusForArea(areaFromTiles).toInt())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// These mimic tileMap.max* without the abs()
|
|
||||||
val minLatitude = (tileMap.values.map { it.latitude }.minOrNull() ?: 0f).toInt()
|
|
||||||
val minLongitude = (tileMap.values.map { it.longitude }.minOrNull() ?: 0f).toInt()
|
|
||||||
val maxLatitude = (tileMap.values.map { it.latitude }.maxOrNull() ?: 0f).toInt()
|
|
||||||
val maxLongitude = (tileMap.values.map { it.longitude }.maxOrNull() ?: 0f).toInt()
|
|
||||||
params.mapSize = MapSizeNew((maxLongitude - minLongitude + 1), (maxLatitude - minLatitude + 1) / 2)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun recreate(): BaseScreen = MapEditorScreen(tileMap)
|
override fun recreate(): BaseScreen = MapEditorScreen(tileMap)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user