You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

76 lines
2.5 KiB
GDScript

extends Node3D
class_name PlayerInput
@onready var status: Status = (%Status as Status)
@onready var combo: Combo = (%Combo as Combo)
@onready var action: PlayerAction = (%PlayerAction as PlayerAction)
var action_map: Dictionary = {}
var switch_action_list: Array[Variant] = ["attack_heavy", "attack_light", "jump", "interact"]
var skill_action_list: Array[Variant] = ["skill1", "skill2", "skill3", "skill4"]
func _ready():
SignalManager.connect("input_action_pressed", on_input_action_pressed)
SignalManager.connect("input_action_released", on_input_action_released)
SignalManager.connect("input_action_move", on_input_action_move)
func on_input_action_pressed(action_name: String) -> void:
if action_name in action_map:
return
action_map[action_name] = true
var is_switch: bool = is_switch_action(action_name)
if is_switch:
action_name = get_switch_action(action_name)
action_name = get_skill_action(action_name)
Global.ui_mgr.input_action(action_name, true)
if Global.is_control_pause:
return
if not action.check_action(action_name, true):
combo.add_input_action(action_name, is_switch)
func on_input_action_released(action_name: String) -> void:
if not action_name in action_map:
return
action_map.erase(action_name)
var is_switch: bool = is_switch_action(action_name)
Global.ui_mgr.input_action(action_name, false)
if Global.is_control_pause:
return
if not action.check_action(action_name, false):
combo.add_input_action("%s_release" % action_name, is_switch)
return
func on_input_action_move(input_dir) -> void:
Global.ui_mgr.input_dir(input_dir)
if Global.is_control_pause:
return
status.input_dir = input_dir
func is_switch_action(action_name: String)->bool:
return action_name in skill_action_list or (status.is_switch and action_name in switch_action_list)
func get_switch_action(action_name: String)->String:
if not action_name in switch_action_list:
return action_name
if status.is_lock:
return "lock_%s" % action_name
else:
return "free_%s" % action_name
func get_skill_action(action_name: String)->String:
if not action_name in skill_action_list:
return action_name
var index: int = skill_action_list.find(action_name)
action_name = switch_action_list[index]
if status.is_lock:
return "lock_%s" % action_name
else:
return "free_%s"% action_name