aboutsummaryrefslogtreecommitdiff
path: root/client/map
diff options
context:
space:
mode:
Diffstat (limited to 'client/map')
-rw-r--r--client/map/kitchen_background.gd25
-rw-r--r--client/map/map.gd4
2 files changed, 17 insertions, 12 deletions
diff --git a/client/map/kitchen_background.gd b/client/map/kitchen_background.gd
index 4b728a94..a638ad5f 100644
--- a/client/map/kitchen_background.gd
+++ b/client/map/kitchen_background.gd
@@ -22,13 +22,13 @@ func _ready() -> void:
func init_map():
var map_tile = func (t): match t:
- ".": return "floor"
- "=": return "counter"
- "s": return "stove"
- "c": return "chair"
- "t": return "table"
- "o": return "oven"
- "#": return "wall"
+ ".": return ["floor"]
+ "=": return ["counter"]
+ "s": return ["stove"]
+ "c": return ["chair"]
+ "t": return ["table"]
+ "o": return ["oven"]
+ "#": return ["wall"]
_: push_error("unknown tile: ", t)
var tiles = [
"...............",
@@ -39,9 +39,10 @@ func init_map():
".............=#",
".............=#"
].map(func (l): return Array(l.split("")).map(map_tile))
- var gt = func (e): return null if e[1] >= tiles.size() else null if e[0] >= tiles[e[1]].size() else tiles[e[1]][e[0]]
- var co = Vector2i(floor(tiles[0].size() / 2), floor(tiles.size() - 2))
- for y in tiles.size():
- for x in tiles[y].size():
- map.set_tile(Vector2i(x,y) - co, gt.call([x,y]), [[x,y-1],[x-1,y],[x,y+1],[x+1,y]].map(gt))
+ var offset = Vector2i(floor(tiles[0].size() / 2), floor(tiles.size() - 2))
+ var pos_to_tile: Dictionary[Vector2i, Array] = {} # : Dictionary[Vector2i, Array[String]]
+ for y in range(tiles.size()):
+ for x in range(tiles[y].size()):
+ pos_to_tile[Vector2i(x,y) - offset] = tiles[y][x]
+ map.set_all_tiles(pos_to_tile)
map.flush()
diff --git a/client/map/map.gd b/client/map/map.gd
index afac0a1b..acf7c1a4 100644
--- a/client/map/map.gd
+++ b/client/map/map.gd
@@ -41,6 +41,10 @@ func get_tile_instance(pos: Vector2i) -> Tile:
if e != null: return e.tile
else: return null
+func set_all_tiles(changes: Dictionary[Vector2i, Array]):
+ for pos: Vector2i in changes:
+ set_tiles(Vector2i(pos.x, pos.y), changes[pos], changes)
+
func set_tiles(pos: Vector2i, tiles: Array = [], pending_changes: Dictionary[Vector2i, Array] = {}): # tiles: Array[String]
var inst = get_tile_instance(pos)
if inst != null and not tiles.is_empty():