diff options
| author | tpart <tpart120@proton.me> | 2026-02-26 20:30:49 +0100 |
|---|---|---|
| committer | tpart <tpart120@proton.me> | 2026-02-26 20:49:54 +0100 |
| commit | 04dd47d13a8da9224e7f9ea8ccacf64129717ec1 (patch) | |
| tree | 2a88e646d1b8dfbcd5973092655bf9a0ebc1c625 /client/map/map.gd | |
| parent | b91eb2a9bdf4167c69a4d82f2a44855138f58b94 (diff) | |
| download | hurrycurry-04dd47d13a8da9224e7f9ea8ccacf64129717ec1.tar hurrycurry-04dd47d13a8da9224e7f9ea8ccacf64129717ec1.tar.bz2 hurrycurry-04dd47d13a8da9224e7f9ea8ccacf64129717ec1.tar.zst | |
Implement tile stacks in client; Upgrade to Godot 4.6
Diffstat (limited to 'client/map/map.gd')
| -rw-r--r-- | client/map/map.gd | 38 |
1 files changed, 27 insertions, 11 deletions
diff --git a/client/map/map.gd b/client/map/map.gd index 4dd76ec4..afac0a1b 100644 --- a/client/map/map.gd +++ b/client/map/map.gd @@ -23,12 +23,14 @@ class TileInfo: var name: String var tile: Tile var neighbours: Array + +const NEIGHBOR_OFFSETS: Array[Vector2i] = [Vector2i.UP, Vector2i.LEFT, Vector2i.DOWN, Vector2i.RIGHT] var tile_by_pos: Dictionary[Vector2i, TileInfo] = {} var autoflush = false var currently_baked = false var floor_node := MeshInstance3D.new() -var tile_factory = TileFactory.new() +var tile_factory := TileFactory.new() func get_tile_name(pos: Vector2i): # -> String? var e = tile_by_pos.get(pos) @@ -39,22 +41,36 @@ func get_tile_instance(pos: Vector2i) -> Tile: if e != null: return e.tile else: return null -func set_tile(pos: Vector2i, tilename = null, neighbors: Array = [null,null,null,null]): +func set_tiles(pos: Vector2i, tiles: Array = [], pending_changes: Dictionary[Vector2i, Array] = {}): # tiles: Array[String] var inst = get_tile_instance(pos) - if inst and tilename: if inst.change(tilename): return # instance handled change itself + if inst != null and not tiles.is_empty(): + for tile: String in tiles: + # TODO: Don't return, but handle changes which weren't handled by the instance below. + if inst.change(tile): + return # Instance handled change itself! _remove_tile(pos) - if tilename: _add_tile(pos, tilename, neighbors) + if not tiles.is_empty(): _add_tiles(pos, tiles, pending_changes) 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, tilename, tile, neighbors) - return tile +func _add_tiles(pos: Vector2i, tiles: Array, pending_changes: Dictionary[Vector2i, Array] = {}) -> void: + # Find neighbor tile names + var neighbors: Array[Array] = [] # Array[Array[String]] + for offset: Vector2i in NEIGHBOR_OFFSETS: + var neighbor_pos: Vector2i = pos + offset + if pending_changes.has(neighbor_pos): + neighbors.append(pending_changes[neighbor_pos]) + elif tile_by_pos.has(neighbor_pos): + neighbors.append(tile_by_pos[neighbor_pos]) + else: neighbors.append([]) + + for tile_name: String in tiles: + var tile := tile_factory.produce(tile_name, pos, neighbors) + add_child(tile) + tile.position = Vector3(pos.x, 0, pos.y) + tile_by_pos[pos] = TileInfo.new(pos, tile_name, tile, neighbors) func _remove_tile(pos: Vector2i): - var tile = get_tile_instance(pos) + var tile := get_tile_instance(pos) if tile == null: return if tile.item != null: tile.item.queue_free() if tile is FloorLike: |