input util functions for less verbose key combos

This commit is contained in:
Cameron Taylor
2025-08-14 14:34:55 -04:00
committed by Eric
parent 8cba81d207
commit 517eb4eb48
3 changed files with 40 additions and 7 deletions
+7 -6
View File
@@ -15,6 +15,7 @@ import flixel.tweens.FlxEase;
import funkin.graphics.FunkinCamera;
import funkin.audio.FunkinSound;
import funkin.util.SwipeUtil;
import funkin.util.InputUtil;
import flixel.tweens.FlxTween;
import funkin.ui.MusicBeatState;
import funkin.ui.UIStateMachine;
@@ -510,12 +511,12 @@ class MainMenuState extends MusicBeatState
// Ctrl+Alt+Shift+E = Dump save data
// Ctrl+Alt+Shift+L = Force crash and create a log dump
if (FlxG.keys.pressed.CONTROL && FlxG.keys.pressed.ALT && FlxG.keys.pressed.SHIFT && FlxG.keys.justPressed.P)
if (InputUtil.allPressedWithDebounce([CONTROL, ALT, SHIFT, P]))
{
FlxG.switchState(() -> new funkin.ui.charSelect.CharacterUnlockState('pico'));
}
if (FlxG.keys.pressed.CONTROL && FlxG.keys.pressed.ALT && FlxG.keys.pressed.SHIFT && FlxG.keys.justPressed.W)
if (InputUtil.allPressedWithDebounce([CONTROL, ALT, SHIFT, W]))
{
FunkinSound.playOnce(Paths.sound('confirmMenu'));
// Give the user a score of 1 point on Weekend 1 story mode (Easy difficulty).
@@ -538,7 +539,7 @@ class MainMenuState extends MusicBeatState
});
}
if (FlxG.keys.pressed.CONTROL && FlxG.keys.pressed.ALT && FlxG.keys.pressed.SHIFT && FlxG.keys.justPressed.M)
if (InputUtil.allPressedWithDebounce([CONTROL, ALT, SHIFT, M]))
{
FunkinSound.playOnce(Paths.sound('confirmMenu'));
// Give the user a score of 0 points on Weekend 1 story mode (all difficulties).
@@ -564,7 +565,7 @@ class MainMenuState extends MusicBeatState
}
}
if (FlxG.keys.pressed.CONTROL && FlxG.keys.pressed.ALT && FlxG.keys.pressed.SHIFT && FlxG.keys.justPressed.R)
if (InputUtil.allPressedWithDebounce([CONTROL, ALT, SHIFT, R]))
{
// Give the user a hypothetical overridden score,
// and see if we can maintain that golden P rank.
@@ -586,7 +587,7 @@ class MainMenuState extends MusicBeatState
});
}
if (FlxG.keys.pressed.CONTROL && FlxG.keys.pressed.ALT && FlxG.keys.pressed.SHIFT && FlxG.keys.justPressed.N)
if (InputUtil.allPressedWithDebounce([CONTROL, ALT, SHIFT, N]))
{
@:privateAccess
{
@@ -595,7 +596,7 @@ class MainMenuState extends MusicBeatState
}
}
if (FlxG.keys.pressed.CONTROL && FlxG.keys.pressed.ALT && FlxG.keys.pressed.SHIFT && FlxG.keys.justPressed.E)
if (InputUtil.allPressedWithDebounce([CONTROL, ALT, SHIFT, E]))
{
funkin.save.Save.instance.debug_dumpSave();
}
+32
View File
@@ -22,6 +22,38 @@ class InputUtil
}
}
/**
* Returns true if all of the keys in keyArray are being pressed,
* but also only fires once on the last key in the array being justPressed
* @param keyArray An array of FlxKeys
* @return Bool True if all of the keys in keyArray are being pressed, with at least one of them being in a JUST_PRESSED state
*/
public static function allPressedWithDebounce(keyArray:Array<FlxKey>):Bool
{
return allPressed(keyArray) && FlxG.keys.anyJustPressed(keyArray);
}
/**
* Returns true if all of the keys in keyArray are being pressed
* @param keyArray An array of FlxKeys
* @return Bool True if all keys in keyArray are being pressed
*/
public static function allPressed(keyArray:Array<FlxKey>):Bool
{
return !anyNotPressed(keyArray);
}
/**
* Returns if any key is not being pressed (or just pressed)
* @param keyArray An array of FlxKeys
* @return Bool True if there's any key in keyArray that isn't being pressed
*/
public static function anyNotPressed(keyArray:Array<FlxKey>):Bool
{
var isKeyNotPressed:FlxKey->Bool = key -> return FlxG.keys.checkStatus(key, RELEASED) || FlxG.keys.checkStatus(key, JUST_RELEASED);
return keyArray.exists(isKeyNotPressed);
}
public static function getKeyName(id:Int):String
{
return switch (id)
@@ -24,7 +24,7 @@ class ForceCrashPlugin extends FlxBasic
super.update(elapsed);
// Ctrl + Alt + Shift + L = Crash the game for debugging purposes
if (FlxG.keys.pressed.CONTROL && FlxG.keys.pressed.ALT && FlxG.keys.pressed.SHIFT && FlxG.keys.pressed.L)
if (InputUtil.allPressedWithDebounce([CONTROL, ALT, SHIFT, L]))
{
// TODO: Make this message 87% funnier.
throw "DEBUG: Crashing the game via debug keybind!";