velho/godot/nodes/actions/move_action.gd

26 lines
546 B
GDScript

@icon("res://icons/turn_action.svg")
class_name MoveAction
extends Action
var mover: GridPosition
var dir: Vector2i
func _init(new_mover: GridPosition, new_dir: Vector2i) -> void:
mover = new_mover
dir = new_dir
func get_action_name() -> String:
return "move"
func predicate():
return mover.can_move(dir)
func action_ready():
mover.finished_moving.connect(_on_mover_done, CONNECT_ONE_SHOT)
if not mover.try_move(dir):
mover.finished_moving.disconnect(_on_mover_done)
abort.emit()
func _on_mover_done(_dir: Vector2i):
done.emit()