class_name InputListener extends Control

enum ActionEvent {
    Pressed,
    Released
}

signal opened
signal closed

@export var input_event: ActionEvent
@export var open_action: StringName
@export var close_action: StringName

func _is_active(event: InputEvent, action: StringName) -> bool:
    match input_event:
        ActionEvent.Pressed: return event.is_action_pressed(action)
        ActionEvent.Released: return event.is_action_released(action)
        _: return false

func _unhandled_input(event: InputEvent) -> void:
    if _is_active(event, open_action):
        accept_event()
        opened.emit()

func _gui_input(event: InputEvent) -> void:
    if _is_active(event, close_action):
        accept_event()
        closed.emit()
