FantasyRun/Tiles/tile_turn.gd
Matthew Welch 5669da34c5 update type hints
fix issue with signal for tiles exiting the screen
2024-10-12 15:19:15 -07:00

53 lines
1.3 KiB
GDScript

extends Tile
class_name TileTurn
@onready var area_3d: Area3D = $Area3D as Area3D
@onready var path_forward: TilePath = $PathForward as TilePath
@onready var path_right: TilePath = $PathRight as TilePath
@onready var path_left: TilePath = $PathLeft as TilePath
var connected: bool = false
var current_direction: String = "forward"
var character: Character
var on_main_path: bool:
get:
return path_index == 0
func _process(delta: float) -> void:
var character_found = false
for area in area_3d.get_overlapping_areas():
if area is Character:
character_found = true
if connected:
break
character = area as Character
character.turn.connect(turn)
connected = true
if not character_found and connected:
character.turn.disconnect(turn)
connected = false
super(delta)
func load_path() -> void:
paths.append($MainPath)
paths.append($PathForward)
func turn(direction: String) -> void:
if on_main_path:
current_direction = direction
paths[path_index+1] = get_path_by_direction(current_direction)
func get_path_by_direction(direction: String) -> TilePath:
if direction == "forward" and path_forward != null:
return path_forward
elif direction == "right" and path_right != null:
return path_right
elif direction == "left" and path_left != null:
return path_left
return null