@tool
extends Node2D
class_name Character

@export var chara_resource: CharacterResource:
	set(new_resource):
		chara_resource = new_resource
		_on_chara_resource_changed()
		# Connect the changed signal as soon as a new resource is being added.
		if chara_resource != null:
			chara_resource.changed.connect(_on_chara_resource_changed)

@onready var face: Sprite2D = $Face
@onready var mask_eyes: Mask = $MaskEyes
@onready var mask_mouth: Mask = $MaskMouth

var mask_eyes_location: Vector2
var mask_mouth_location: Vector2

func _on_chara_resource_changed() -> void:
	face.texture = chara_resource.chara_sprite
	mask_eyes_location = chara_resource.mask_eyes_location
	mask_mouth_location = chara_resource.mask_mouth_location
	

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


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
	if Engine.is_editor_hint():
		_engine_process(delta)
	else:
		_game_process(delta)
		
		
func _game_process(delta: float) -> void:
	pass		


func _engine_process(delta: float) -> void:
	mask_eyes.position = mask_eyes_location
	mask_mouth.position = mask_mouth_location
