codename-routes/godot/world/Tilemaps.gd

34 lines
1,010 B
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-13 18:44:22 +00:00
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)