extends StateAnimatedActor

export (NodePath) var jump_node
export (NodePath) var idle_node
export (NodePath) var fall_node
export (NodePath) var move_node

onready var jump_state: State = get_node(jump_node)
onready var idle_state: State = get_node(idle_node)
onready var fall_state: State = get_node(fall_node)
onready var move_state: State = get_node(move_node)

var can_fire = true

func enter() -> void:
	.enter()
	parent.set_hurtbox(false)
	state_timeout.start()
	can_fire = true
	if modifier_stack_ref.has($"../attack") == false:
		$"../attack".enter()
		modifier_stack_ref.push_front($"../attack")
	##TODO: Hacky, don't do it this way. 
	#parent.sound_effect_player.play()
	
	

func process_input(_event: InputEvent) -> State:
	if move_component.wants_jump() and parent.is_on_floor():
		return jump_state

	move_component.get_movement_direction()

#	if Input.is_action_just_pressed('dash'):
#		return dash_state
	return null

func process_frame(delta: float) -> State:
	if state_timeout.time_left == 0:
		return idle_state
	return null


func process_physics(delta: float) -> State:
	
	if can_fire: # trying to do this in the physics because irrecular behavior
		parent.shoot_projectile()
		can_fire = false
		
	move_component.velocity.y += gravity * delta
	move_component.velocity = parent.move_and_slide(move_component.velocity, Vector2(0, -1))
	move_component.velocity.x = move_component.desired_movement_vector.x * move_speed
	move_component.velocity = parent.move_and_slide(move_component.velocity, Vector2(0, -1))

	if move_component.velocity.x != 0.0:
		return move_state
	
	if !parent.is_on_floor():
		return fall_state

#	if move_component.flipped_sprite == true:
#		animations.flip_h = parent.direction.x > 0
#	else:
#		animations.flip_h = parent.direction.x < 0

	
	return null

func exit() -> void:
	# force timer reset
	$"../attack".state_timeout.start()
	for mods in modifier_stack_ref:
		print(mods.name)
	
#	var testmod :StateModifier = StateModifier.new()
#	testmod.name
	
	return	
