2022-05-08 14:45:53 +00:00
|
|
|
extends Node
|
|
|
|
|
|
|
|
var Tilemap = preload("res://world/Tilemap.tscn")
|
|
|
|
var tilemaps = []
|
|
|
|
|
2022-05-08 15:56:37 +00:00
|
|
|
func _ready():
|
|
|
|
StateServer.connect("changed_tiletypes", self, "_on_StateServer_changed_tiletypes")
|
|
|
|
StateServer.connect("request_init", self, "_on_StateServer_request_init")
|
|
|
|
|
|
|
|
func respawn_tilemaps():
|
2022-05-08 14:45:53 +00:00
|
|
|
tilemaps = []
|
2022-05-08 15:56:37 +00:00
|
|
|
for i in range(0, StateServer.get_world_size().z):
|
2022-05-08 14:45:53 +00:00
|
|
|
var map = Tilemap.instance()
|
|
|
|
map.position.y -= i * map.cell_size.y
|
|
|
|
map.z_index = i
|
|
|
|
add_child(map)
|
|
|
|
tilemaps.push_back(map)
|
2022-05-08 15:56:37 +00:00
|
|
|
|
|
|
|
func get_tile_at(pos: Vector3) -> String:
|
|
|
|
return StateServer.get_tile_at(int(pos.x), int(pos.y), int(pos.z))
|
|
|
|
|
|
|
|
func update_tiles(tile_positions: PoolVector3Array):
|
|
|
|
for tile in tile_positions:
|
2022-05-13 18:44:22 +00:00
|
|
|
tilemaps[tile.z].set_tile_graphics(Vector2(tile.x, tile.y),
|
|
|
|
get_tile_at(tile))
|
2022-05-08 18:40:33 +00:00
|
|
|
for map in tilemaps:
|
|
|
|
map.update_dirty_quadrants()
|
2022-05-08 15:56:37 +00:00
|
|
|
|
|
|
|
func _on_StateServer_request_init():
|
|
|
|
call_deferred("respawn_tilemaps")
|
|
|
|
|
|
|
|
func _on_StateServer_changed_tiletypes(tile_positions: PoolVector3Array):
|
|
|
|
call_deferred("update_tiles", tile_positions)
|