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 {
} }
fun renumberTilesAfterLoad() {
/**
* Load existing world
*/
/*internal constructor(worldIndex: Int, json: JsonObject) {
this.worldIndex = worldIndex
// TODO setup layerTerrain, layerWall, etc. from the json
// before the renaming, update the name maps // before the renaming, update the name maps
tileNumberToNameMap = HashMap<Int, ItemID>() val oldTileNumberToNameMap: Map<Long, ItemID> = tileNumberToNameMap.toMap()
tileNameToNumberMap = HashMap<ItemID, Int>() tileNumberToNameMap.clear()
AppLoader.tileMaker.tags.forEach { tileNameToNumberMap.clear()
tileNumberToNameMap[it.value.tileNumber] = it.key App.tileMaker.tags.forEach {
tileNumberToNameMap[it.value.tileNumber.toLong()] = it.key
tileNameToNumberMap[it.key] = it.value.tileNumber tileNameToNumberMap[it.key] = it.value.tileNumber
} }
// perform renaming of tile layers // perform renaming of tile layers
val oldTileNumberToNameMap = /* todo */
for (y in 0 until layerTerrain.height) { for (y in 0 until layerTerrain.height) {
for (x in 0 until layerTerrain.width) { for (x in 0 until layerTerrain.width) {
layerTerrain.unsafeSetTile(x, y, tileNameToNumberMap[oldTileNumberToNameMap[layerTerrain.unsafeGetTile(x, y)]]!!) layerTerrain.unsafeSetTile(x, y, tileNameToNumberMap[oldTileNumberToNameMap[layerTerrain.unsafeGetTile(x, y).toLong()]]!!)
layerWall.unsafeSetTile(x, y, tileNameToNumberMap[oldTileNumberToNameMap[layerWall.unsafeGetTile(x, y)]]!!) layerWall.unsafeSetTile(x, y, tileNameToNumberMap[oldTileNumberToNameMap[layerWall.unsafeGetTile(x, y).toLong()]]!!)
// TODO rename fluid map
// TODO rename wire map
} }
} }
// AN EXCEPTIONAL TERM: tilenum 0 is always redirected to Air tile, even if the tilenum for actual Air tile is not zero // 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 tileNumberToNameMap[0] = Block.AIR
}*/ }
/** /**
* Get 2d array data of wire * Get 2d array data of wire
* @return byte[][] wire layer * @return byte[][] wire layer
*/ */
//val wireArray: ByteArray //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 wx = (world.width.toFloat() / previewWidth * x).roundToInt()
val wy = (world.height.toFloat() / previewHeight * y).roundToInt() val wy = (world.height.toFloat() / previewHeight * y).roundToInt()
val outCol = if (BlockCodex[world.getTileFromTerrain(wx, wy)].isSolid) WorldgenLoadScreen.COL_TERR val outCol = try {
else if (BlockCodex[world.getTileFromWall(wx, wy)].isSolid) WorldgenLoadScreen.COL_WALLED if (BlockCodex[world.getTileFromTerrain(wx, wy)].isSolid) WorldgenLoadScreen.COL_TERR
else WorldgenLoadScreen.COL_AIR 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.setColor(outCol)
previewPixmap.drawPixel(x, previewHeight - 1 - y) // this flips Y 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)}") Echo("${ccW}Savegame loaded from $ccY${disk.getDiskNameString(Common.CHARSET)}")