diff --git a/source/funkin/ui/mainmenu/MainMenuState.hx b/source/funkin/ui/mainmenu/MainMenuState.hx index 29b852871..d4678f558 100644 --- a/source/funkin/ui/mainmenu/MainMenuState.hx +++ b/source/funkin/ui/mainmenu/MainMenuState.hx @@ -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(); } diff --git a/source/funkin/util/InputUtil.hx b/source/funkin/util/InputUtil.hx index 17e9ececa..189c0a140 100644 --- a/source/funkin/util/InputUtil.hx +++ b/source/funkin/util/InputUtil.hx @@ -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):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):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):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) diff --git a/source/funkin/util/plugins/ForceCrashPlugin.hx b/source/funkin/util/plugins/ForceCrashPlugin.hx index faa2cb2e9..62533fba4 100644 --- a/source/funkin/util/plugins/ForceCrashPlugin.hx +++ b/source/funkin/util/plugins/ForceCrashPlugin.hx @@ -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!";