extends LimboState

##跳輸入缓存时间
@export var jump_grace_time: float = .14

var jump_grace_timer: float

func _setup() -> void:
	self.add_event_handler(&"trigger_jump",_handler_trigger_jump)

func _enter() -> void:
	jump_grace_timer = jump_grace_time

func _update(delta: float) -> void:
	if jump_grace_timer > 0:
		jump_grace_timer -= delta
	
	var move_direction = Input.get_axis(&"move_left",&"move_right") as float
	agent.locomotion_comp.add_movement_input(move_direction)
	if move_direction == 0.0:
		get_root().dispatch(self.EVENT_FINISHED)
		return

func _handler_trigger_jump() -> bool:
	if not get_root().blackboard.get_var(&"is_jumping",false):
		if jump_grace_timer > 0:
			get_root().dispatch(&"air_to_jump")
	
	return false
