2022-05-01 20:23:01 +00:00
|
|
|
extends Node
|
2022-05-04 14:46:58 +00:00
|
|
|
|
2022-05-04 12:10:28 +00:00
|
|
|
onready var server = $StateServer
|
2022-05-01 22:20:37 +00:00
|
|
|
|
2022-05-05 15:54:08 +00:00
|
|
|
export var xsize = 512
|
|
|
|
export var ysize = 512
|
|
|
|
export var zsize = 16
|
2022-05-04 14:46:58 +00:00
|
|
|
|
|
|
|
var Tilemap = preload("res://world/Tilemap.tscn")
|
|
|
|
var tilemaps = []
|
|
|
|
|
2022-05-01 20:23:01 +00:00
|
|
|
func _ready():
|
2022-05-04 14:46:58 +00:00
|
|
|
server.generate_world(xsize, ysize, zsize)
|
|
|
|
|
2022-05-05 15:17:48 +00:00
|
|
|
func respawn_tilemaps(amount: int):
|
2022-05-04 14:46:58 +00:00
|
|
|
tilemaps = []
|
2022-05-05 15:17:48 +00:00
|
|
|
for i in range(0, amount + 1):
|
|
|
|
var map = Tilemap.instance()
|
2022-05-05 15:54:08 +00:00
|
|
|
map.position.y -= i * map.cell_size.y
|
|
|
|
map.z_index = i
|
2022-05-05 15:17:48 +00:00
|
|
|
add_child(map)
|
|
|
|
tilemaps.push_back(map)
|
2022-05-05 09:13:29 +00:00
|
|
|
|
2022-05-05 14:59:11 +00:00
|
|
|
func get_tile_at(pos: Vector3) -> String:
|
|
|
|
return server.get_tile_at(int(pos.x), int(pos.y), int(pos.z))
|
|
|
|
|
2022-05-05 15:17:48 +00:00
|
|
|
func update_tiles(tile_positions: PoolVector3Array):
|
2022-05-05 15:54:08 +00:00
|
|
|
for tile in tile_positions:
|
|
|
|
tilemaps[tile.z].set_tile_graphics(Vector2(tile.x, tile.y),
|
|
|
|
get_tile_at(tile))
|
|
|
|
pass
|
2022-05-05 14:59:11 +00:00
|
|
|
|
2022-05-05 09:13:29 +00:00
|
|
|
func _on_StateServer_request_init():
|
|
|
|
respawn_tilemaps(zsize - 1)
|
|
|
|
|
2022-05-05 15:17:48 +00:00
|
|
|
func _on_StateServer_changed_tiletypes(tile_positions: PoolVector3Array):
|
2022-05-05 14:59:11 +00:00
|
|
|
call_deferred("update_tiles", tile_positions)
|