extends TextureRect

var unlock_font = preload("res://fonts/unlock_font.tres")

var count
var counter
var countString

var castBar

func _init(pos, size):
  count = 0
  set_position(pos)
  set_size(size)
  
func _ready():
  counter = RichTextLabel.new()
  counter.bbcode_enabled = true
  _updateCounter()
  counter.set_size(2 * get_rect().size)
  counter.rect_position = Vector2(-140, -30)
  add_child(counter)
  
  castBar = ColorRect.new()
  castBar.color = Color(0.5, 0.1, 0, 0.5)
  castBar.set_size(Vector2(0, get_rect().size.y))
  add_child(castBar)
  

func setSheepCount(count):
  self.count = count
  _updateCounter()

func _updateCounter():
  counter.clear()
  counter.push_color(Color(1.0, 0, 0))
  counter.push_font(unlock_font)
  counter.push_align(2)
  countString = str(count) 
  counter.append_bbcode(countString)
  
func setImage(texture):
  set_texture(texture)
  
func setSacrificeProgress(progress):
  castBar.set_size(Vector2(2 * progress * get_rect().size.x , get_rect().size.y))
