45 lines
902 B
GDScript
45 lines
902 B
GDScript
extends StaticBody3D
|
|
|
|
enum TileType {
|
|
Empty,
|
|
Plain,
|
|
Forest
|
|
}
|
|
|
|
@export var tile_type: TileType = TileType.Empty;
|
|
|
|
func update_tile():
|
|
var children = find_children("*tile");
|
|
for child in children:
|
|
if TileType.keys()[tile_type] == child.name.split("_")[0]:
|
|
child.visible = true;
|
|
else:
|
|
child.visible = false;
|
|
|
|
func _ready():
|
|
update_tile()
|
|
|
|
func get_free_dirs_around():
|
|
var free_tiles_around = []
|
|
if tile_type == TileType.Empty: return free_tiles_around
|
|
var raycasts = find_children("ray*");
|
|
|
|
for raycast: RayCast3D in raycasts:
|
|
raycast.force_raycast_update()
|
|
if !raycast.is_colliding():
|
|
free_tiles_around.append(raycast.name.split("_")[1])
|
|
return free_tiles_around
|
|
|
|
func _process(delta):
|
|
pass
|
|
|
|
func save():
|
|
if tile_type == TileType.Empty: return {}
|
|
return {
|
|
"node": "tile",
|
|
"pos_x": position.x,
|
|
"pos_y": position.y,
|
|
"pos_z": position.z,
|
|
"tile_type": tile_type
|
|
}
|