diff options
| -rw-r--r-- | client/game.gd | 13 | ||||
| -rw-r--r-- | client/map/map.gd | 17 |
2 files changed, 17 insertions, 13 deletions
diff --git a/client/game.gd b/client/game.gd index 50230f93..0c2d51e9 100644 --- a/client/game.gd +++ b/client/game.gd @@ -225,10 +225,9 @@ func handle_packet(p): pl.set_item(null, h) "update_map": var neighbors: Array = p["neighbors"] - if p.kind != null: - if neighbors != null: neighbors = neighbors.map(func(x): return tile_names[x] if x != null else null) - map.set_tile(p.tile, tile_names[p.kind], neighbors) - else: map.clear_tile(p.tile) + if neighbors != null: neighbors = neighbors.map(func(x): return tile_names[x] if x != null else null) + if p.kind != null: map.set_tile(p.tile, tile_names[p.kind], neighbors) + else: map.set_tile(p.tile) "flush_map": map.flush() "communicate": @@ -299,9 +298,9 @@ func handle_packet(p): if p.state: reset_camera() - map.gi_bake() + map.flush() await get_parent()._menu_open() - map.autobake = true + map.autoflush = true in_lobby_updated.emit(in_lobby) if not in_lobby and not is_replay and not Global.using_touch and not join_state == JoinState.SPECTATING: @@ -315,7 +314,7 @@ func handle_packet(p): else: mp.send_ready() else: - map.autobake = false + map.autoflush = false await get_parent()._menu_exit() if in_lobby: overlay_lobby.select_map(0) diff --git a/client/map/map.gd b/client/map/map.gd index 150520d7..800cb57d 100644 --- a/client/map/map.gd +++ b/client/map/map.gd @@ -25,7 +25,7 @@ class TileInfo: var neighbours: Array var tile_by_pos: Dictionary[Vector2i, TileInfo] = {} -var autobake = false +var autoflush = false var currently_baked = false var floor_node := MeshInstance3D.new() var tile_factory = TileFactory.new() @@ -39,15 +39,20 @@ func get_tile_instance(pos: Vector2i) -> Tile: if e != null: return e.tile else: return null -func set_tile(pos: Vector2i, name_: String, neighbors: Array = [null,null,null,null]) -> Tile: - clear_tile(pos) - var tile := tile_factory.produce(name_, pos, neighbors) +func set_tile(pos: Vector2i, tilename = null, neighbors: Array = [null,null,null,null]): + _remove_tile(pos) + if tilename != null: + _add_tile(pos, tilename, neighbors) + if autoflush: flush() + +func _add_tile(pos: Vector2i, tilename: String, neighbors: Array) -> Tile: + var tile := tile_factory.produce(tilename, pos, neighbors) add_child(tile) tile.position = Vector3(pos.x, 0, pos.y) - tile_by_pos[pos] = TileInfo.new(pos, name_, tile, neighbors) + tile_by_pos[pos] = TileInfo.new(pos, tilename, tile, neighbors) return tile -func clear_tile(pos: Vector2i): +func _remove_tile(pos: Vector2i): var tile = get_tile_instance(pos) if tile == null: return if tile.item != null: tile.item.queue_free() |