extends HBoxContainer

# This one is an exact copy of the tutorial

# Declare member variables here. Examples:
# var a = 2
# var b = "text"
enum MODES {simple, empty, partial}

var heart_full = preload("res://art/full_heart.png")
var heart_empty = preload("res://art/empty_heart.png")
var heart_half = preload("res://art/half_heart.png")

export (MODES) var mode = MODES.simple

func update_health(value):
	match mode:
		MODES.simple:
			update_simple(value)
		MODES.empty:
			update_empty(value)
		MODES.partial:
			update_partial(value)

func update_simple(value):
	for i in get_child_count():
		get_child(i).visible = value > i
	if Input.on_button_pressed("move_up"):
		value =+ 1
	if Input.on_button_pressed("move_down"):
		value =- 1

func update_empty(value):
	for i in get_child_count():
		if value > i:
			get_child(i).texture = heart_full
		else:
			get_child(i).texture = heart_empty
	if Input.on_button_pressed("move_up"):
		value =+ 1
	if Input.on_button_pressed("move_down"):
		value =- 1

func update_partial(value):
	for i in get_child_count():
		if value > i * 2 + 1:
			get_child(i).texture = heart_full
		elif value > i * 2:
			get_child(i).texture = heart_half
		else:
			get_child(i).texture = heart_empty
	if Input.on_button_pressed("move_up"):
		value =+ 1
	if Input.on_button_pressed("move_down"):
		value =- 1

	

# Called when the node enters the scene tree for the first time.
func _ready():
	pass # Replace with function body.


# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
#	pass
