extends Node3D
class_name InputController

@export_group("Mapping contexts")
@export var base_mode:GUIDEMappingContext

@export_group("Move actions")
@export var move:GUIDEAction
@export var rotate_y:GUIDEAction
@export var rotate_floorplane:GUIDEAction

@export_group("Trigger actions")
@export_subgroup("Aim")
@export var aim_down:GUIDEAction
@export var aim_pressed:GUIDEAction
@export var aim_released:GUIDEAction
@export_subgroup("Jump")
@export var jump:GUIDEAction
@export var jump_pressed:GUIDEAction
@export_subgroup("Other")
@export var empower_down:GUIDEAction
@export var empower_released:GUIDEAction
@export var aim_canceled:GUIDEAction
@export var hit:GUIDEAction
@export var dash:GUIDEAction
@export var throw:GUIDEAction

signal input_move(value: Vector3)
signal input_rotate_y(value: float)
signal input_rotate_floorplane(value: float)

# Jump
signal input_jump_started
signal input_jump_ongoing
signal input_jump_ended

signal input_aim_pressed
signal input_aim_down
signal input_aim_released

signal input_empower_down
signal input_empower_released
signal input_aim_canceled

signal input_hit
signal input_dash
signal input_throw

func _ready() -> void:
	GUIDE.enable_mapping_context(base_mode)
	
	aim_down.triggered.connect(on_input_aim_down)
	aim_pressed.triggered.connect(on_input_aim_pressed)
	aim_released.triggered.connect(on_input_aim_released)
	empower_down.triggered.connect(on_input_empower_down)
	empower_released.triggered.connect(on_input_empower_released)
	aim_canceled.triggered.connect(on_input_aim_canceled)
	
	jump_pressed.triggered.connect(on_input_jump_started)
	jump.triggered.connect(on_input_jump_ongoing)
	jump.completed.connect(on_input_jump_ended)
	
	hit.triggered.connect(on_input_hit)
	dash.triggered.connect(on_input_dash)
	throw.triggered.connect(on_input_throw)

func on_input_dash():
	input_dash.emit()
	
func on_input_throw():
	input_throw.emit()

func on_input_hit():
	input_hit.emit()

func on_input_jump_started():
	input_jump_started.emit()

func on_input_jump_ongoing():
	input_jump_ongoing.emit()

func on_input_jump_ended():
	input_jump_ended.emit()

func on_input_aim_down():
	input_aim_down.emit()
	
func on_input_aim_pressed():
	input_aim_pressed.emit()

func on_input_aim_released():
	input_aim_released.emit()

func on_input_empower_down():
	input_empower_down.emit()

func on_input_empower_released():
	input_empower_released.emit()

func on_input_aim_canceled():
	input_aim_canceled.emit()

func _process(_delta: float) -> void:
	input_move.emit(move.value_axis_3d)
	input_rotate_y.emit(rotate_y.value_axis_1d)
	input_rotate_floorplane.emit(rotate_floorplane.value_axis_1d)
