extends "res://Entities/Entity.gd"

onready var progress_bar = $ProgressBar
var is_long_tap: bool = false
var long_tap_power: float = 0 setget set_long_tap_power

enum STATE {
	NORMAL,
	NO_INPUT
}

var state = STATE.NORMAL

func set_class(stats: Resource):
	if stats is PlayerClass:
		if stats.skin != null:
			draw_pivot.get_node("Sprite").texture = stats.skin
		if stats.weapon != null:
			change_weapon(stats.weapon.instance())
		max_health = stats.max_health
		healthbar.max_value = max_health
		self.health = max_health
		
		damage_base = stats.damage_base
		block_damage_divider = stats.block_damage_divider
		agility_base = stats.agility_base
		for item in stats.items:
			item_add(item)

func _process(delta):
	if state == STATE.NO_INPUT:
		return
	if Input.is_action_just_pressed("action"):
		is_long_tap = false
	if Input.is_action_pressed("action"):
		if animation_player.current_animation == "Idle" and not is_long_tap:
			self.long_tap_power += delta
	if Input.is_action_just_released("action"):
		if not is_long_tap:
			short_tap()

func short_tap():
	if can_block:
		block()
	else:
		attack()
	
	self.long_tap_power = 0

func set_long_tap_power(value):
	long_tap_power = value
	progress_bar.value = value
	
	if long_tap_power >= 1:
		long_tap()
#		print("Items left: ")
#		for item in items:
#			print("\t", item.name)

func long_tap():
	item_use()
	
	is_long_tap = true
	long_tap_power = 0

func _on_InventoryContainer_ready():
	emit_signal("items_update", items)
