class_name ItemInteractable extends Item @onready var interaction_area: InteractionArea = $InteractionArea @onready var animation_player: AnimationPlayer = $AnimationPlayer # Einheitliche Standardtexte/-anim-Namen (können in Subklassen überschrieben werden) const ACTION_OPEN: StringName = &"open" const ACTION_CLOSE: StringName = &"close" const ANIM_OPEN: StringName = &"open" const ANIM_CLOSE: StringName = &"close" func _ready() -> void: # Nur verbinden, wenn noch nicht verbunden (verhindert Doppelverbindungen in Subklassen) if not state_changed.is_connected(_on_state_changed): state_changed.connect(_on_state_changed) # Standardaktion initial setzen _update_action_name_for_state(state) func _on_interact() -> void: # Standardverhalten: zwischen opened/closed toggeln match state: States.closed: state = States.opened States.opened: state = States.closed _: pass _update_action_name_for_state(state) func _on_state_changed(new_state: States) -> void: _play_animation_for_state(new_state) _update_action_name_for_state(new_state) func _play_animation_for_state(new_state: States) -> void: if animation_player == null: return match new_state: States.opened: animation_player.play(ANIM_OPEN) States.closed: animation_player.play(ANIM_CLOSE) _: pass func _update_action_name_for_state(s: States) -> void: if interaction_area == null: return match s: States.closed: interaction_area.action_name = ACTION_OPEN States.opened: interaction_area.action_name = ACTION_CLOSE _: pass