Live Tiles
This commit is contained in:
@@ -20,6 +20,7 @@ signal crafting_result_received(result: Dictionary)
|
||||
signal recipe_discovered(recipe: Dictionary)
|
||||
signal stash_updated(stash_data: Dictionary)
|
||||
signal stash_result(result: Dictionary)
|
||||
signal dungeon_tiles_updated(tiles: Array)
|
||||
|
||||
# Use constants instead of enum to avoid type issues
|
||||
const STATE_AUTH = 0
|
||||
@@ -117,6 +118,8 @@ func _on_message_received(opcode: int, data: Dictionary):
|
||||
_handle_dungeon_enter(data)
|
||||
OpCodes.DUNGEON_STATE:
|
||||
_handle_dungeon_state(data)
|
||||
OpCodes.DUNGEON_TILE_UPDATE:
|
||||
_handle_tile_update(data)
|
||||
OpCodes.INVENTORY_STATE:
|
||||
_handle_inventory_state(data)
|
||||
OpCodes.LOOT_RECEIVED:
|
||||
@@ -685,3 +688,39 @@ func stash_withdraw(stash_slot: int, quantity: int = 1):
|
||||
"stashSlot": stash_slot,
|
||||
"quantity": quantity
|
||||
})
|
||||
|
||||
func _handle_tile_update(data: Dictionary):
|
||||
var tiles = data.get("tiles", data.get("Tiles", []))
|
||||
var walkable_updates = data.get("walkable", data.get("Walkable", []))
|
||||
|
||||
print("[GameState] Received tile update: %d tiles, %d walkable changes" % [tiles.size(), walkable_updates.size()])
|
||||
|
||||
# Update walkable data if provided
|
||||
for w in walkable_updates:
|
||||
var x = int(w.get("x", 0))
|
||||
var y = int(w.get("y", 0))
|
||||
var is_walkable = w.get("w", true)
|
||||
var idx = y * dungeon.width + x
|
||||
if idx >= 0 and idx < dungeon.tiles.size():
|
||||
dungeon.tiles[idx] = 1 if is_walkable else 0
|
||||
|
||||
# Update visual tiles cache
|
||||
if dungeon.has_visual_tiles and tiles.size() > 0:
|
||||
for tile in tiles:
|
||||
var x = int(tile.get("x", 0))
|
||||
var y = int(tile.get("y", 0))
|
||||
var layer = int(tile.get("l", 0))
|
||||
|
||||
# Find and update or add
|
||||
var found = false
|
||||
for i in range(dungeon.visual_tiles.tiles.size()):
|
||||
var t = dungeon.visual_tiles.tiles[i]
|
||||
if int(t.get("x", -1)) == x and int(t.get("y", -1)) == y and int(t.get("l", 0)) == layer:
|
||||
dungeon.visual_tiles.tiles[i] = tile
|
||||
found = true
|
||||
break
|
||||
|
||||
if not found:
|
||||
dungeon.visual_tiles.tiles.append(tile)
|
||||
|
||||
dungeon_tiles_updated.emit(tiles)
|
||||
|
||||
Reference in New Issue
Block a user