# Hurry Curry! - a game about cooking
# Copyright (C) 2026 Hurry Curry! Contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, version 3 of the License only.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.
#
class_name CatEars
extends Node3D

const EAR_ROTATION := deg_to_rad(0.)
var ear_target := 0.

@onready var character: Character = get_parent().get_parent().get_parent().get_parent()

func set_inner_mat(mat: BaseMaterial3D):
	$Left/Mesh.set_surface_override_material(1, mat)
	$Right/Mesh.set_surface_override_material(1, mat)


func set_outer_mat(mat: BaseMaterial3D):
	$Left/Mesh.set_surface_override_material(0, mat)
	$Right/Mesh.set_surface_override_material(0, mat)

func _ready() -> void:
	set_inner_mat(character.main.get_active_material(0))
	set_outer_mat(character.hair_mesh.get_active_material(0))

var t := 0.
func _process(delta: float) -> void:
	if visible:
		$Right.rotation.z = G.interpolate_angle($Right.rotation.z, ear_target + EAR_ROTATION, delta * 17.5)
		$Left.rotation.z = G.interpolate_angle($Left.rotation.z, -ear_target + -EAR_ROTATION, delta * 17.5)
		if character.walking:
			t += delta
			ear_target = sin(t * character.WALK_ANIM_SPEED) * 0.075 if character.walking else 0.
		else:
			t = 0
			ear_target = 0.
