class_name AmmoUI
extends HBoxContainer

@export var ammo_img:Texture2D
@export var img_container:Control

var num:int:
	get: return num
	set(val):
		num = val
		update_ui(num)

func update_ui(number:int):
	var num_to_add: int = number - img_container.get_child_count()
	
	if num_to_add > 0:
		for i in range(num_to_add):
			var texrect:TextureRect = TextureRect.new()
			texrect.stretch_mode= TextureRect.STRETCH_KEEP_ASPECT_CENTERED
			texrect.texture = ammo_img
			img_container.add_child(texrect)
	if num_to_add < 0:
		for i in range(img_container.get_child_count() - 1, img_container.get_child_count() - 1 + num_to_add, -1):
			img_container.remove_child(img_container.get_child(i))

	C.jiggle(self, 1.2, 0.35)
