codename-routes/godot/world/Tilemaps.gd

35 lines
1.1 KiB
GDScript
Raw Normal View History

2022-05-08 14:45:53 +00:00
extends Node
var Tilemap = preload("res://world/Tilemap.tscn")
var tilemaps = []
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 = []
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)
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-08 16:53:27 +00:00
if !StateServer.is_tile_hidden(int(tile.x), int(tile.y), int(tile.z)):
tilemaps[tile.z].set_tile_graphics(Vector2(tile.x, tile.y),
get_tile_at(tile))
for map in tilemaps:
map.update_dirty_quadrants()
func _on_StateServer_request_init():
call_deferred("respawn_tilemaps")
func _on_StateServer_changed_tiletypes(tile_positions: PoolVector3Array):
call_deferred("update_tiles", tile_positions)