extends Actor

onready var actor_hurtbox = $Hurtbox_Component/CollisionShape2D


#var sound_effects = preload("res://src/playerC/resources/sound_effects.tres")

func _ready() -> void:
	movement_state_machine.init_animated_actor(self, movement_animations, movement_component)

	# Experimenting with sound based resources I did this and it worked
	#sound_effect_player.stream = sound_effects.sounds["pew"]
	#print(sounds.sounds["pew"])
	#sound_effects.play()
	
	# Trying something new with a custom resourse.
	for i in SoundEffects:
		sound_effects_dict[i.animation_name + str(i.frame_number)] = i.sound
	print (sound_effects_dict)	

func _unhandled_input(event: InputEvent) -> void:
	movement_state_machine.process_input(event)

func _physics_process(delta: float) -> void:
	movement_state_machine.process_physics(delta)
#	#TODO: So much hack
#	if direction.x != 0:
#		gun.set_scale( Vector2(direction.x,1))

	# Commented out to try parent transforms instead
#	if direction.x < 0:
#		var t = Transform2D()
#		# Translation
#		t.origin = Vector2(gun.offset_position.x * -1, gun.offset_position.y)
#		gun.transform = t
#	elif direction.x > 0:
#		var t = Transform2D()
#		# Translation
#		t.origin = Vector2(gun.offset_position.x, gun.offset_position.y)
#		gun.transform = t

	# Attempting a Kinematic2D level scale for flip operations instead.
	#self.transform
	#self.scale.x = -1

func _process(delta: float) -> void:
	movement_component.process(delta)
	movement_state_machine.process_frame(delta)
	play_sound_frame(movement_animations.animation , movement_animations.frame)


##TODO: I don't like player class having do do this.
## Figure out how to programatically signal subscribe
#func _on_AnimatedSprite_animation_finished():
#	if movement_animations.frames.get_animation_loop(movement_animations.animation) == false:
#		movement_state_machine.current_state.animation_index += 1



