fixed an oversight where newly-added blocks would not be recognised by the old savegame

This commit is contained in:
minjaesong
2021-10-06 17:16:09 +09:00
parent 170503ecdb
commit c211b94b13
3 changed files with 18 additions and 25 deletions

View File

@@ -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<Int, ItemID>()
tileNameToNumberMap = HashMap<ItemID, Int>()
AppLoader.tileMaker.tags.forEach {
tileNumberToNameMap[it.value.tileNumber] = it.key
val oldTileNumberToNameMap: Map<Long, ItemID> = 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

View File

@@ -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

View File

@@ -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)}")