extends Actor

export var player_number: int = 1

onready var player_hurtbox = $Hurtbox_Component/CollisionShape2D

onready var gun = $Gun

func _ready() -> void:
	PlayerInfo.player_health = $Health_Component.health
	movement_component.player_number = player_number

var portrait = preload("res://assets/MManPortrait.png")

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



##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

func _on_Hurtbox_area_entered():
	#print("Ouch.",area)
	movement_state_machine.change_state($movement_state_machine/hurt)

func set_hurtbox(enabled: bool):
	pass
	## TODO: This breaks now I guess because I moved the process functions out to parent class
	#player_hurtbox.set_deferred("disabled", !enabled) #WTF Apparently this is how to do it

func shoot_projectile():
	var is_shooting = false
	print("Direction: ",  transform.x.x)
	is_shooting = gun.shoot(int(transform.x.x))

#func play_sound():
#	sound_effects.stream = "res://assets/Sounds/crappy pew.wav"

func gotcha(damage):
	print("oh! You got me for ", damage)
	$Hurtbox_Component.set_hurtbox(false)
	$Health_Component.take_damage(damage)
	if $Health_Component.health > 0:
		movement_state_machine.change_state($movement_state_machine/hurt)
	PlayerInfo.player_health = $Health_Component.health
	yield( get_tree().create_timer(2 + $movement_state_machine/hurt.timeout_seconds), "timeout")
	$Hurtbox_Component.set_hurtbox(true)

func _on_hurt_state_exited():
	pass
	#$Hurtbox_Component.set_hurtbox(true)
	#actually await may be better here.

func _on_Health_Component_health_depleted():
	# die I guess.
	queue_free()


func heylookatme(sender):
	print("does it work!")
	UiManager.current_pane = UiManager.UI_PANES.DIALOG
	UiManager.dialog_text = "Hey there. I'm glad we can see you."
	UiManager.dialog_portrait = portrait
