extends Node2D

const TILE_SIZE = 64

enum MaskType { NONE, TRIANGLE, CIRCLE, SQUARE }

@onready var sprite = $Sprite2D

var TRIANGLE_GUARD = preload("res://assets/guards/triangle_guard.png")
var CIRCLE_GUARD = preload("res://assets/guards/circle_guard.png")
var SQUARE_GUARD = preload("res://assets/guards/square_guard.png")

func _ready():
	z_index = 100
	

func set_guard_type(mask_type: MaskType):
	# Wait until the node is ready
	if sprite == null:
		return

	match mask_type:
		MaskType.TRIANGLE:
			sprite.texture = TRIANGLE_GUARD
		MaskType.CIRCLE:
			sprite.texture = CIRCLE_GUARD
		MaskType.SQUARE:
			sprite.texture = SQUARE_GUARD

	fit_sprite_to_tile()

func fit_sprite_to_tile():
	if sprite.texture == null:
		return
	var texture_size = sprite.texture.get_size()
	var scale_factor = min(TILE_SIZE / texture_size.x, TILE_SIZE / texture_size.y)
	sprite.scale = Vector2(scale_factor, scale_factor)
