class_name PawnInput extends Node


@export var dir : Vector3
@export var pressed : Dictionary[String, bool]
@export var just_pressed : Dictionary[String, bool]
@export var just_released : Dictionary[String, bool]

func _ready() -> void:
	pressed = {
		"left cycle trap":false,
		"right cycle trap":false,
		"detonate":false,
		"detect":false,
		"lay trap":false,
		"attack":false
	}
	just_pressed = {
		"left cycle trap":false,
		"right cycle trap":false,
		"detonate":false,
		"detect":false,
		"lay trap":false,
		"attack":false
	}
	just_released = {
		"left cycle trap":false,
		"right cycle trap":false,
		"detonate":false,
		"detect":false,
		"lay trap":false,
		"attack":false
	}

func _physics_process(delta: float) -> void:
	var d = Input.get_vector("west", "east", "north", "south")
	dir = Vector3(d.x, 0, d.y)
	for key : String in pressed:
		if Input.is_action_pressed(key):
			just_pressed[key] = !pressed[key]
			just_released[key] = false
			pressed[key] = true
		else:
			just_released[key] = pressed[key]
			just_pressed[key] = false
			pressed[key] = false

func is_action_pressed(action : String) -> bool:
	return pressed.has(action) && pressed[action]

func is_action_just_pressed(action : String) -> bool:
	return just_pressed.has(action) && just_pressed[action]
	
func is_action_just_released(action : String) -> bool:
	return just_released.has(action) && just_released[action]
