extends StateAnimatedActor

export (NodePath) var idle_node

onready var idle_state: StateAnimatedActor = get_node(idle_node)
#onready var landing_mod: StateModifier = get_node(landing_node)

var climbing_modifier: StateModifier

func _ready():
	climbing_modifier= StateModifier.new()
	#add_child(modifier)
	#modifier.init_ref()
#	climbing_modifier.ready( "landing", "jump" , climbing_modifier.TYPE.EXIT_ANIMATION)
#	climbing_modifier.starting_frame = 6
	#print("ready! MOD")
	

func enter() -> void:
	.enter()
	animations.frame = 5

func process_physics(delta: float) -> State:
	
	# First allow horizontal movement.
	#move_actor_as_desired(delta)
	# Make wure we still want to climb
	var ladder_location = move_component.get_climb_shape_location()
	if ladder_location != Vector2(-1,-1):
		UiManager.debug_text =  str(ladder_location) + '\n' + str(ladder_location - parent.global_position) #+ '\n' + str(parent.global_position.distance_to(ladder_location)) 
		# An attempt to snap to the ladder location 
		if parent.global_position.x != round(ladder_location.x):
			parent.global_translate(Vector2(round((ladder_location.x - parent.global_position.x)),(ladder_location.y * move_speed) * delta))
		if ladder_location.y != 0:
			animations.play()
		else:
			# Make sure we hopped the step index
			if animation_index > 0:
				animations.stop()
	else: 
		return idle_state
	#parent.move_local_x()
	#Flip the character before tha actual move maybe.
	if move_component.get_movement_direction() != 0.0:
		parent.transform.x.x = move_component.get_movement_direction()
	
#	if parent.is_on_floor():
#		#modifier.reference()
#		idle_state.modifier = climbing_modifier
#		return idle_state
	return null
