extends Node onready var server = $StateServer export var xsize = 16 export var ysize = 16 export var zsize = 16 var Tilemap = preload("res://world/Tilemap.tscn") var tilemaps = [] func _ready(): server.generate_world(xsize, ysize, zsize) print(server.get_tile_at(0,0,0)) func respawn_tilemaps(amount: int): tilemaps = [] for i in range(0, amount + 1): var map = Tilemap.instance() map.position.y -= i * map.cell_size.y map.z_index = i add_child(map) tilemaps.push_back(map) func get_tile_at(pos: Vector3) -> String: return server.get_tile_at(int(pos.x), int(pos.y), int(pos.z)) func update_tiles(tile_positions: PoolVector3Array): for tile in tile_positions: tilemaps[tile.z].set_tile_graphics(Vector2(tile.x, tile.y), get_tile_at(tile)) func _on_StateServer_request_init(): respawn_tilemaps(zsize - 1) func _on_StateServer_changed_tiletypes(tile_positions: PoolVector3Array): call_deferred("update_tiles", tile_positions)