Dungeon Tile RLE Missing
This commit is contained in:
@@ -178,8 +178,13 @@ func _handle_dungeon_enter(data: Dictionary):
|
||||
dungeon.width = int(data.get("width", data.get("Width", 0)))
|
||||
dungeon.height = int(data.get("height", data.get("Height", 0)))
|
||||
|
||||
var tiles_data = data.get("tiles", data.get("Tiles", ""))
|
||||
_parse_tiles(tiles_data)
|
||||
# Check for RLE tiles first, fallback to legacy format
|
||||
var tiles_rle = data.get("tilesRLE", data.get("TilesRLE", ""))
|
||||
if not tiles_rle.is_empty():
|
||||
_parse_tiles_rle(tiles_rle)
|
||||
else:
|
||||
var tiles_data = data.get("tiles", data.get("Tiles", ""))
|
||||
_parse_tiles(tiles_data)
|
||||
|
||||
var spawn = data.get("spawn", data.get("Spawn", {}))
|
||||
self_player = {
|
||||
@@ -229,6 +234,43 @@ func _parse_tiles(tiles_string: String):
|
||||
if x >= dungeon.width:
|
||||
break
|
||||
dungeon.tiles[x][y] = 0 if row[x] == "." else 1
|
||||
func _parse_tiles_rle(rle_string: String):
|
||||
# RLE format: "tile,count;tile,count;..."
|
||||
# Decode into a flat array first, then reshape to 2D
|
||||
dungeon.tiles = []
|
||||
if rle_string.is_empty():
|
||||
return
|
||||
|
||||
# Initialize 2D array
|
||||
for x in range(dungeon.width):
|
||||
dungeon.tiles.append([])
|
||||
for y in range(dungeon.height):
|
||||
dungeon.tiles[x].append(0)
|
||||
|
||||
# Decode RLE
|
||||
var flat_tiles: Array[int] = []
|
||||
var runs = rle_string.split(";")
|
||||
|
||||
for run in runs:
|
||||
if run.is_empty():
|
||||
continue
|
||||
var parts = run.split(",")
|
||||
if parts.size() != 2:
|
||||
continue
|
||||
var tile_value = int(parts[0])
|
||||
var count = int(parts[1])
|
||||
for i in range(count):
|
||||
flat_tiles.append(tile_value)
|
||||
|
||||
# Convert flat array to 2D (row-major order: y then x)
|
||||
var idx = 0
|
||||
for y in range(dungeon.height):
|
||||
for x in range(dungeon.width):
|
||||
if idx < flat_tiles.size():
|
||||
dungeon.tiles[x][y] = flat_tiles[idx]
|
||||
idx += 1
|
||||
|
||||
print("[GameState] Parsed RLE tiles: %d values for %dx%d grid" % [flat_tiles.size(), dungeon.width, dungeon.height])
|
||||
|
||||
func _handle_dungeon_state(data: Dictionary):
|
||||
# Check dungeon phase first
|
||||
|
||||
Reference in New Issue
Block a user