From c211b94b134ddcaf0b5218b3e5a45708ae25128d Mon Sep 17 00:00:00 2001 From: minjaesong Date: Wed, 6 Oct 2021 17:16:09 +0900 Subject: [PATCH] fixed an oversight where newly-added blocks would not be recognised by the old savegame --- .../torvald/terrarum/gameworld/GameWorld.kt | 31 ++++++------------- .../modulebasegame/ChunkLoadingLoadScreen.kt | 9 ++++-- .../terrarum/serialise/WriteSavegame.kt | 3 +- 3 files changed, 18 insertions(+), 25 deletions(-) diff --git a/src/net/torvald/terrarum/gameworld/GameWorld.kt b/src/net/torvald/terrarum/gameworld/GameWorld.kt index 4bb659f2f..3e431ac5a 100644 --- a/src/net/torvald/terrarum/gameworld/GameWorld.kt +++ b/src/net/torvald/terrarum/gameworld/GameWorld.kt @@ -157,41 +157,30 @@ open class GameWorld() : Disposable { } - - /** - * Load existing world - */ - /*internal constructor(worldIndex: Int, json: JsonObject) { - this.worldIndex = worldIndex - - // TODO setup layerTerrain, layerWall, etc. from the json - + fun renumberTilesAfterLoad() { // before the renaming, update the name maps - tileNumberToNameMap = HashMap() - tileNameToNumberMap = HashMap() - AppLoader.tileMaker.tags.forEach { - tileNumberToNameMap[it.value.tileNumber] = it.key + val oldTileNumberToNameMap: Map = tileNumberToNameMap.toMap() + tileNumberToNameMap.clear() + tileNameToNumberMap.clear() + App.tileMaker.tags.forEach { + tileNumberToNameMap[it.value.tileNumber.toLong()] = it.key tileNameToNumberMap[it.key] = it.value.tileNumber } // perform renaming of tile layers - val oldTileNumberToNameMap = /* todo */ for (y in 0 until layerTerrain.height) { for (x in 0 until layerTerrain.width) { - layerTerrain.unsafeSetTile(x, y, tileNameToNumberMap[oldTileNumberToNameMap[layerTerrain.unsafeGetTile(x, y)]]!!) - layerWall.unsafeSetTile(x, y, tileNameToNumberMap[oldTileNumberToNameMap[layerWall.unsafeGetTile(x, y)]]!!) - // TODO rename fluid map - // TODO rename wire map + layerTerrain.unsafeSetTile(x, y, tileNameToNumberMap[oldTileNumberToNameMap[layerTerrain.unsafeGetTile(x, y).toLong()]]!!) + layerWall.unsafeSetTile(x, y, tileNameToNumberMap[oldTileNumberToNameMap[layerWall.unsafeGetTile(x, y).toLong()]]!!) } } // AN EXCEPTIONAL TERM: tilenum 0 is always redirected to Air tile, even if the tilenum for actual Air tile is not zero tileNumberToNameMap[0] = Block.AIR - }*/ - + } + /** * Get 2d array data of wire - * @return byte[][] wire layer */ //val wireArray: ByteArray diff --git a/src/net/torvald/terrarum/modulebasegame/ChunkLoadingLoadScreen.kt b/src/net/torvald/terrarum/modulebasegame/ChunkLoadingLoadScreen.kt index 26dd65864..bfa996b03 100644 --- a/src/net/torvald/terrarum/modulebasegame/ChunkLoadingLoadScreen.kt +++ b/src/net/torvald/terrarum/modulebasegame/ChunkLoadingLoadScreen.kt @@ -81,9 +81,12 @@ class ChunkLoadingLoadScreen(screenToBeLoaded: IngameInstance, private val world val wx = (world.width.toFloat() / previewWidth * x).roundToInt() val wy = (world.height.toFloat() / previewHeight * y).roundToInt() - val outCol = if (BlockCodex[world.getTileFromTerrain(wx, wy)].isSolid) WorldgenLoadScreen.COL_TERR - else if (BlockCodex[world.getTileFromWall(wx, wy)].isSolid) WorldgenLoadScreen.COL_WALLED - else WorldgenLoadScreen.COL_AIR + val outCol = try { + if (BlockCodex[world.getTileFromTerrain(wx, wy)].isSolid) WorldgenLoadScreen.COL_TERR + else if (BlockCodex[world.getTileFromWall(wx, wy)].isSolid) WorldgenLoadScreen.COL_WALLED + else WorldgenLoadScreen.COL_AIR + } + catch (e: NoSuchElementException) { WorldgenLoadScreen.COL_AIR } previewPixmap.setColor(outCol) previewPixmap.drawPixel(x, previewHeight - 1 - y) // this flips Y diff --git a/src/net/torvald/terrarum/serialise/WriteSavegame.kt b/src/net/torvald/terrarum/serialise/WriteSavegame.kt index a046f007b..0653c75b2 100644 --- a/src/net/torvald/terrarum/serialise/WriteSavegame.kt +++ b/src/net/torvald/terrarum/serialise/WriteSavegame.kt @@ -170,7 +170,8 @@ object LoadSavegame { } -// ModMgr.reloadModules() + loadscreen.addMessage("Updating Block Mappings...") + world.renumberTilesAfterLoad() Echo("${ccW}Savegame loaded from $ccY${disk.getDiskNameString(Common.CHARSET)}")