diff --git a/android/assets/jsons/translations/template.properties b/android/assets/jsons/translations/template.properties index f2195b57b5..5a9852c545 100644 --- a/android/assets/jsons/translations/template.properties +++ b/android/assets/jsons/translations/template.properties @@ -524,8 +524,6 @@ Area: [amount] tiles, [amount2]% water, [amount3] continents/islands = Do you want to leave without saving the recent changes? = Leave = 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! = Please don't use step 'Landmass' with map type 'Empty', create a new empty map instead. = This map has errors: = diff --git a/core/src/com/unciv/logic/MapSaver.kt b/core/src/com/unciv/logic/MapSaver.kt index bc0401ae42..6378379f1c 100644 --- a/core/src/com/unciv/logic/MapSaver.kt +++ b/core/src/com/unciv/logic/MapSaver.kt @@ -14,23 +14,13 @@ object MapSaver { 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 { Gzip.unzip(mapString.trim()) } catch (ex: Exception) { mapString } - return mapFromJson(unzippedJson).apply { - // 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('-',' ')) - } - } + return mapFromJson(unzippedJson) } fun mapToSavedString(tileMap: TileMap): String { tileMap.assignContinents(TileMap.AssignContinentsMode.Reassign) @@ -38,12 +28,12 @@ object MapSaver { 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) } - fun loadMap(mapFile: FileHandle, checkSizeErrors: Boolean = true): TileMap { - return mapFromSavedString(mapFile.readString(), checkSizeErrors) + fun loadMap(mapFile: FileHandle): TileMap { + return mapFromSavedString(mapFile.readString()) } fun getMaps(): Array = Gdx.files.local(mapsFolder).list() diff --git a/core/src/com/unciv/ui/mapeditor/MapEditorLoadTab.kt b/core/src/com/unciv/ui/mapeditor/MapEditorLoadTab.kt index 64eb61f597..52c2438b27 100644 --- a/core/src/com/unciv/ui/mapeditor/MapEditorLoadTab.kt +++ b/core/src/com/unciv/ui/mapeditor/MapEditorLoadTab.kt @@ -9,9 +9,9 @@ import com.unciv.logic.MapSaver import com.unciv.logic.UncivShowableException import com.unciv.models.ruleset.RulesetCache import com.unciv.models.translations.tr +import com.unciv.ui.popup.ConfirmPopup import com.unciv.ui.popup.Popup import com.unciv.ui.popup.ToastPopup -import com.unciv.ui.popup.ConfirmPopup import com.unciv.ui.utils.AutoScrollPane import com.unciv.ui.utils.BaseScreen import com.unciv.ui.utils.KeyCharAndCode @@ -105,7 +105,7 @@ class MapEditorLoadTab( } } try { - val map = MapSaver.loadMap(chosenMap!!, checkSizeErrors = false) + val map = MapSaver.loadMap(chosenMap!!) val missingMods = map.mapParameters.mods.filter { it !in RulesetCache }.toMutableList() // [TEMPORARY] conversion of old maps with a base ruleset contained in the mods diff --git a/core/src/com/unciv/ui/mapeditor/MapEditorOptionsTab.kt b/core/src/com/unciv/ui/mapeditor/MapEditorOptionsTab.kt index 69ce16b918..c72e2e58b3 100644 --- a/core/src/com/unciv/ui/mapeditor/MapEditorOptionsTab.kt +++ b/core/src/com/unciv/ui/mapeditor/MapEditorOptionsTab.kt @@ -75,7 +75,7 @@ class MapEditorOptionsTab( private fun pasteHandler() { try { val clipboardContentsString = Gdx.app.clipboard.contents.trim() - val loadedMap = MapSaver.mapFromSavedString(clipboardContentsString, checkSizeErrors = false) + val loadedMap = MapSaver.mapFromSavedString(clipboardContentsString) editorScreen.loadMap(loadedMap) } catch (ex: Exception) { ToastPopup("Could not load map!", editorScreen) diff --git a/core/src/com/unciv/ui/mapeditor/MapEditorScreen.kt b/core/src/com/unciv/ui/mapeditor/MapEditorScreen.kt index af55e01065..b74215f4cf 100644 --- a/core/src/com/unciv/ui/mapeditor/MapEditorScreen.kt +++ b/core/src/com/unciv/ui/mapeditor/MapEditorScreen.kt @@ -3,9 +3,7 @@ package com.unciv.ui.mapeditor import com.badlogic.gdx.Gdx import com.badlogic.gdx.graphics.Color import com.unciv.UncivGame -import com.unciv.logic.HexMath import com.unciv.logic.map.MapParameters -import com.unciv.logic.map.MapShape import com.unciv.logic.map.MapSize import com.unciv.logic.map.MapSizeNew 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.ruleset.Ruleset import com.unciv.models.ruleset.RulesetCache -import com.unciv.models.translations.tr import com.unciv.ui.images.ImageGetter import com.unciv.ui.popup.ConfirmPopup -import com.unciv.ui.popup.ToastPopup import com.unciv.ui.tilegroups.TileGroup import com.unciv.ui.utils.BaseScreen 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) { mapHolder.remove() tileMap = map - checkAndFixMapSize() ruleset = newRuleset ?: RulesetCache.getComplexRuleset(map.mapParameters) mapHolder = newMapHolder() isDirty = false @@ -217,31 +212,5 @@ class MapEditorScreen(map: TileMap? = null): BaseScreen(), RecreateOnResize { 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) }