extends StateAnimatedActor

export (NodePath) var idle_node
export (NodePath) var attack_node
export (NodePath) var fall_node

onready var idle_state: State = get_node(idle_node)
onready var attack_state: State = get_node(attack_node)
onready var fall_state: State = get_node(fall_node)

var flip_flop = false

func enter(state_modifiers: Array = []) -> void:
	.enter()
	parent.set_hurtbox(true)
	state_timeout.start()
	if flip_flop:
		flip_flop = false
		move_component.desired_movement_vector.x = 1.0
	else:
		flip_flop = true
		move_component.desired_movement_vector.x = -1.0

func process_frame(_delta: float) -> State:

#	if parent.player_detection.is_colliding():
#		return attack_state
	
	if state_timeout.time_left == 0:
		return idle_state
	
#	if move_component.wants_jump() and parent.is_on_floor():
#		return jump_state
#
#	move_component.get_movement_direction()
	return null


func process_physics(delta: float) -> State:

	parent.velocity.y += gravity * delta

	parent.velocity.x = move_component.desired_movement_vector.x * move_speed
	parent.velocity = parent.move_and_slide(parent.velocity, Vector2(0, -1))

	if parent.velocity.x == 0.0:
		return idle_state
	else:
		if parent.velocity.x > 0:
			parent.direction.x = 1
		elif parent.velocity.x < 0:
			parent.direction.x = -1
	
	parent.transform.x.x = parent.direction.x
	
	if !parent.is_on_floor():
		return fall_state
	return null
