From 5f60be6d7569862486c9eb062da60ee23305f008 Mon Sep 17 00:00:00 2001 From: FabsTheFabs Date: Thu, 12 Sep 2024 22:44:22 +0100 Subject: [PATCH] allow controls to get dialouge name from control + ignore brackets --- source/funkin/input/Controls.hx | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/source/funkin/input/Controls.hx b/source/funkin/input/Controls.hx index b5aefd08d..da5aaac58 100644 --- a/source/funkin/input/Controls.hx +++ b/source/funkin/input/Controls.hx @@ -395,20 +395,37 @@ class Controls extends FlxActionSet return result; } - public function getDialogueName(action:FlxActionDigital):String + public function getDialogueName(action:FlxActionDigital, ?ignoreSurrounding:Bool = false):String { var input = action.inputs[0]; - return switch (input.device) + if (ignoreSurrounding == false) { - case KEYBOARD: return '[${(input.inputID : FlxKey)}]'; - case GAMEPAD: return '(${(input.inputID : FlxGamepadInputID)})'; - case device: throw 'unhandled device: $device'; + return switch (input.device) + { + case KEYBOARD: return '[${(input.inputID : FlxKey)}]'; + case GAMEPAD: return '(${(input.inputID : FlxGamepadInputID)})'; + case device: throw 'unhandled device: $device'; + } + } + else + { + return switch (input.device) + { + case KEYBOARD: return '${(input.inputID : FlxKey)}'; + case GAMEPAD: return '${(input.inputID : FlxGamepadInputID)}'; + case device: throw 'unhandled device: $device'; + } } } - public function getDialogueNameFromToken(token:String):String + public function getDialogueNameFromToken(token:String, ?ignoreSurrounding:Bool = false):String { - return getDialogueName(getActionFromControl(Control.createByName(token.toUpperCase()))); + return getDialogueName(getActionFromControl(Control.createByName(token.toUpperCase())), ignoreSurrounding); + } + + public function getDialogueNameFromControl(control:Control, ?ignoreSurrounding:Bool = false):String + { + return getDialogueName(getActionFromControl(control), ignoreSurrounding); } function getActionFromControl(control:Control):FlxActionDigital