''' Dash的生命周期
	1. 
'''
extends LimboState

const DASH_FREEZE_TIME: float = .05
@export var dash_time: float = .15
var _dash_timer: float

func _enter() -> void:
	get_root().blackboard.set_var(&"is_dashing",true) ##BB里锁住Dash状态
	
	#禁用原本Locomotion Component的更新
	agent.locomotion_comp.stop_movement()
	agent.locomotion_comp.suspend_movement()
	
	var dash_start_on_ground: bool = agent.is_on_floor()
	
	agent.locomotion_comp.integrate_dash(_get_dash_direction())
	_dash_timer = dash_time

func _exit() -> void:
	blackboard.set_var(&"is_dashing",false) ##BB里清除Dash状态
	agent.locomotion_comp.enable_movement()
	agent.locomotion_comp.can_dash = false

func _update(delta: float) -> void:
	if _dash_timer > 0:
		_dash_timer -= delta
		return
	
	if agent.is_on_floor():
		self.dispatch(&"exit_on_ground")
	else:
		self.dispatch(&"exit_on_air")
	return

func _get_dash_direction() -> Vector2:
	var r : Vector2
	r = Vector2(1,0) if agent.direction == Player.Direction.RIGHT else Vector2(-1,0)
	
	var dash_direction_x = Input.get_axis(&"move_left",&"move_right") as float
	var dash_direction_y = Input.get_axis(&"move_up",&"move_down") as float
	if dash_direction_x != 0 or dash_direction_y != 0:
		r = Vector2(dash_direction_x,dash_direction_y)
	
	return r
