From e6766cdcd7422ad74627bd93141e838b7f4fd1f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=8D=9A=7ENex?= <87421482+NexIsDumb@users.noreply.github.com> Date: Mon, 7 Jul 2025 01:53:02 +0200 Subject: [PATCH] dev mode implementation --- source/funkin/backend/MusicBeatState.hx | 4 +-- source/funkin/backend/MusicBeatSubstate.hx | 2 +- .../funkin/backend/scripting/GlobalScript.hx | 15 ++++----- source/funkin/backend/system/Controls.hx | 25 +++++++++++--- .../system/macros/ControlsMacro.macro.hx | 15 ++++++--- source/funkin/game/PlayState.hx | 2 +- source/funkin/menus/MainMenuState.hx | 2 +- source/funkin/options/Options.hx | 13 ++++++-- .../funkin/options/categories/MiscOptions.hx | 7 ++-- .../options/keybinds/KeybindsOptions.hx | 33 ++++++++++++++++--- 10 files changed, 85 insertions(+), 33 deletions(-) diff --git a/source/funkin/backend/MusicBeatState.hx b/source/funkin/backend/MusicBeatState.hx index ffbccd67..63eeef6c 100644 --- a/source/funkin/backend/MusicBeatState.hx +++ b/source/funkin/backend/MusicBeatState.hx @@ -105,7 +105,7 @@ class MusicBeatState extends FlxState implements IBeatReceiver public static var skipTransOut:Bool = false; public static var skipTransIn:Bool = false; - public static var ALLOW_DEBUG_RELOAD:Bool = true; + public static var ALLOW_DEV_RELOAD:Bool = true; inline function get_controls():Controls return PlayerSettings.solo.controls; @@ -158,7 +158,7 @@ class MusicBeatState extends FlxState implements IBeatReceiver resetSubState(); } - if (/*subState == null && */(ALLOW_DEBUG_RELOAD && controls.DEBUG_RELOAD)) { + if (/*subState == null && */(ALLOW_DEV_RELOAD && controls.DEV_RELOAD)) { Logs.trace("Reloading Current State...", INFO, YELLOW); FlxG.resetState(); } diff --git a/source/funkin/backend/MusicBeatSubstate.hx b/source/funkin/backend/MusicBeatSubstate.hx index 552ecb0a..a9cd55bf 100644 --- a/source/funkin/backend/MusicBeatSubstate.hx +++ b/source/funkin/backend/MusicBeatSubstate.hx @@ -134,7 +134,7 @@ class MusicBeatSubstate extends FlxSubState implements IBeatReceiver call("postUpdate", [elapsed]); } - // if (subState == null && (MusicBeatState.ALLOW_DEBUG_RELOAD && controls.DEBUG_RELOAD)) { + // if (subState == null && (MusicBeatState.ALLOW_DEV_RELOAD && controls.DEV_RELOAD)) { // Logs.trace("Reloading Current SubState...", INFO, YELLOW); // var test = Type.createInstance(Type.getClass(this), [this.scriptsAllowed, this.scriptName]); // parent.openSubState(test); diff --git a/source/funkin/backend/scripting/GlobalScript.hx b/source/funkin/backend/scripting/GlobalScript.hx index b1f70b79..a604c457 100644 --- a/source/funkin/backend/scripting/GlobalScript.hx +++ b/source/funkin/backend/scripting/GlobalScript.hx @@ -4,6 +4,8 @@ import flixel.FlxState; import funkin.backend.assets.ModsFolder; import funkin.backend.scripting.events.CancellableEvent; import funkin.backend.system.Conductor; +import funkin.options.PlayerSettings; + #if GLOBAL_SCRIPT /** * Class for THE Global Script, aka script that runs in the background at all times. @@ -51,10 +53,10 @@ class GlobalScript { if (reloading) { reloading = false; - MusicBeatState.ALLOW_DEBUG_RELOAD = _lastAllow_Reload; + MusicBeatState.ALLOW_DEV_RELOAD = _lastAllow_Reload; } - if (FlxG.keys.justPressed.F2) + if (PlayerSettings.solo.controls.DEV_CONSOLE) NativeAPI.allocConsole(); }); FlxG.signals.preDraw.add(function() { @@ -78,17 +80,14 @@ class GlobalScript { call("update", [FlxG.elapsed]); if (FlxG.keys.pressed.SHIFT) { - var resetKey = FlxG.keys.justPressed.F5; // we default the key to F5, but really this shouldn't matter, as every state will be at minimum a MusicBeatState. - if ((FlxG.state is MusicBeatState)) resetKey = cast(FlxG.state, MusicBeatState).controls.DEBUG_RELOAD; - // If we want, we could just make reseting GlobalScript it's own keybind, but for now this works. - if (resetKey) { + if (PlayerSettings.solo.controls.DEV_RELOAD) { reloading = true; Logs.trace("Reloading Global Scripts...", INFO, YELLOW); // yeah its a bit messy, sorry. This just prevents actually reloading the actual state. - _lastAllow_Reload = MusicBeatState.ALLOW_DEBUG_RELOAD; - MusicBeatState.ALLOW_DEBUG_RELOAD = false; + _lastAllow_Reload = MusicBeatState.ALLOW_DEV_RELOAD; + MusicBeatState.ALLOW_DEV_RELOAD = false; // Would be better to just re-initalize GlobalScript so there aren't any lose ends. onModSwitch(#if MOD_SUPPORT ModsFolder.currentModFolder #else null #end); diff --git a/source/funkin/backend/system/Controls.hx b/source/funkin/backend/system/Controls.hx index 5451c547..48036036 100644 --- a/source/funkin/backend/system/Controls.hx +++ b/source/funkin/backend/system/Controls.hx @@ -26,7 +26,9 @@ enum Control SWITCHMOD; // Debugs - DEBUG_RELOAD; + DEV_ACCESS; + DEV_CONSOLE; + DEV_RELOAD; } enum KeyboardScheme @@ -153,10 +155,23 @@ class Controls extends FlxActionSet @:pressed("switchmod") public var SWITCHMOD_HOLD(get, set): Bool; @:justReleased("switchmod") public var SWITCHMOD_R(get, set): Bool; - @:gamepad([GUIDE]) // the center button (like the PS button on a playstation controller) on the gamepad - @:justPressed("debug-reload") public var DEBUG_RELOAD(get, set): Bool; - @:pressed("debug-reload") public var DEBUG_RELOAD_HOLD(get, set): Bool; - @:justReleased("debug-reload") public var DEBUG_RELOAD_R(get, set): Bool; + @:devModeOnly + @:gamepad([]) + @:justPressed("dev-access") public var DEV_ACCESS(get, set): Bool; + @:pressed("dev-access") public var DEV_ACCESS_HOLD(get, set): Bool; + @:justReleased("dev-access") public var DEV_ACCESS_R(get, set): Bool; + + @:devModeOnly + @:gamepad([]) + @:justPressed("dev-console") public var DEV_CONSOLE(get, set): Bool; + @:pressed("dev-console") public var DEV_CONSOLE_HOLD(get, set): Bool; + @:justReleased("dev-console") public var DEV_CONSOLE_R(get, set): Bool; + + @:devModeOnly + @:gamepad([]) + @:justPressed("dev-reload") public var DEV_RELOAD(get, set): Bool; + @:pressed("dev-reload") public var DEV_RELOAD_HOLD(get, set): Bool; + @:justReleased("dev-reload") public var DEV_RELOAD_R(get, set): Bool; var byName:Map = []; diff --git a/source/funkin/backend/system/macros/ControlsMacro.macro.hx b/source/funkin/backend/system/macros/ControlsMacro.macro.hx index 2219a677..93c927cc 100644 --- a/source/funkin/backend/system/macros/ControlsMacro.macro.hx +++ b/source/funkin/backend/system/macros/ControlsMacro.macro.hx @@ -14,6 +14,7 @@ class ControlsMacro { static var _allControls: Array = null; static var _allInternalControls: Array = null; + static var _allDevModeOnlyControls: Array = null; static var _currentControls: Map> = null; static var _currentGamepadControls: Map = null; static var _keySet: Map = null; @@ -29,6 +30,7 @@ class ControlsMacro _allControls = []; _allInternalControls = []; + _allDevModeOnlyControls = []; _currentControls = []; _currentGamepadControls = []; _keySet = []; @@ -154,6 +156,7 @@ class ControlsMacro _allControls = null; _allInternalControls = null; + _allDevModeOnlyControls = null; _currentControls = null; _currentGamepadControls = null; _keySet = null; @@ -289,6 +292,9 @@ class ControlsMacro case ":justReleased": keyset = extractString(meta.params[0]); expr = macro func($i{internalName}, JUST_RELEASED); + case ":devModeOnly": + if (!_allDevModeOnlyControls.contains(shortName)) + _allDevModeOnlyControls.push(shortName); default: shouldRemove = false; } @@ -326,17 +332,16 @@ class ControlsMacro // Generated Code: // inline function get_UI_UP(): Bool - // return _uiUp.check(); + // return _uiUp.check(); or return Options.devMode && _uiUp.check(); depending if its dev mode var getField: Field = { name: "get_" + name, access: [APrivate, AInline], kind: FFun({ ret: macro : Bool, params: [], - expr: macro - { - return $i{internalName}.check(); - }, + expr: _allDevModeOnlyControls.contains(shortName) ? + (macro return Options.devMode && $i{internalName}.check()) : + (macro return $i{internalName}.check()), args: [] }), pos: field.pos, diff --git a/source/funkin/game/PlayState.hx b/source/funkin/game/PlayState.hx index 90ea76a4..f5f6bc5b 100644 --- a/source/funkin/game/PlayState.hx +++ b/source/funkin/game/PlayState.hx @@ -1316,7 +1316,7 @@ class PlayState extends MusicBeatState if (updateRatingStuff != null) updateRatingStuff(); - if (canAccessDebugMenus && chartingMode && FlxG.keys.justPressed.SEVEN) + if (canAccessDebugMenus && chartingMode && controls.DEV_ACCESS) FlxG.switchState(new funkin.editors.charter.Charter(SONG.meta.name, difficulty, false)); if (doIconBop) diff --git a/source/funkin/menus/MainMenuState.hx b/source/funkin/menus/MainMenuState.hx index 06f1cbe1..220bf73b 100644 --- a/source/funkin/menus/MainMenuState.hx +++ b/source/funkin/menus/MainMenuState.hx @@ -92,7 +92,7 @@ class MainMenuState extends MusicBeatState if (!selectedSomethin) { if (canAccessDebugMenus) { - if (FlxG.keys.justPressed.SEVEN) { + if (controls.DEV_ACCESS) { persistentUpdate = false; persistentDraw = true; openSubState(new funkin.editors.EditorPicker()); diff --git a/source/funkin/options/Options.hx b/source/funkin/options/Options.hx index f9a2bcbf..71423236 100644 --- a/source/funkin/options/Options.hx +++ b/source/funkin/options/Options.hx @@ -33,6 +33,7 @@ class Options public static var gameplayShaders:Bool = true; public static var colorHealthBar:Bool = true; public static var lowMemoryMode:Bool = false; + public static var devMode:Bool = false; public static var betaUpdates:Bool = false; public static var splashesEnabled:Bool = true; public static var hitWindow:Float = 250; @@ -99,7 +100,9 @@ class Options public static var P1_VOLUME_MUTE:Array = []; // Debugs - public static var P1_DEBUG_RELOAD:Array = [F5]; + public static var P1_DEV_ACCESS:Array = [SEVEN]; + public static var P1_DEV_CONSOLE:Array = [F2]; + public static var P1_DEV_RELOAD:Array = [F5]; /** * PLAYER 2 CONTROLS (ALT) @@ -128,7 +131,9 @@ class Options public static var P2_VOLUME_MUTE:Array = [NUMPADZERO]; // Debugs - public static var P2_DEBUG_RELOAD:Array = []; + public static var P2_DEV_ACCESS:Array = []; + public static var P2_DEV_CONSOLE:Array = []; + public static var P2_DEV_RELOAD:Array = []; /** * SOLO GETTERS @@ -157,7 +162,9 @@ class Options public static var SOLO_VOLUME_MUTE(get, null):Array; // Debugs - public static var SOLO_DEBUG_RELOAD(get, null):Array; + public static var SOLO_DEV_ACCESS(get, null):Array; + public static var SOLO_DEV_CONSOLE(get, null):Array; + public static var SOLO_DEV_RELOAD(get, null):Array; public static function load() { if (__save == null) __save = new FlxSave(); diff --git a/source/funkin/options/categories/MiscOptions.hx b/source/funkin/options/categories/MiscOptions.hx index 2aecb20f..52b8e624 100644 --- a/source/funkin/options/categories/MiscOptions.hx +++ b/source/funkin/options/categories/MiscOptions.hx @@ -1,9 +1,12 @@ package funkin.options.categories; - class MiscOptions extends OptionsScreen { public override function new() { - super("Miscellaneous", "Use this menu to reset save data or engine settings."); + super("Miscellaneous", "Change some other options like enabling Developer Mode, resetting data..."); + add(new Checkbox( + "Developer Mode", + "If checked, you will be able to access developer features like certain keybinds, editors, developer options, state reloads, console and more.", + "devMode")); #if UPDATE_CHECKING add(new Checkbox( "Enable Nightly Updates", diff --git a/source/funkin/options/keybinds/KeybindsOptions.hx b/source/funkin/options/keybinds/KeybindsOptions.hx index efafbf1b..1f8c3b43 100644 --- a/source/funkin/options/keybinds/KeybindsOptions.hx +++ b/source/funkin/options/keybinds/KeybindsOptions.hx @@ -4,10 +4,20 @@ import flixel.util.FlxColor; using StringTools; +typedef KeybindsCategory = { + var name:String; + var settings:Array; + var ?devModeOnly:Bool; +} +typedef KeybindsSettings = { + var name:String; + var control:String; +} + class KeybindsOptions extends MusicBeatSubstate { public static var instance:KeybindsOptions; - public var categories = [ + public var categories:Array = [ { name: 'Notes', settings: [ @@ -93,12 +103,23 @@ class KeybindsOptions extends MusicBeatSubstate { ] }, { - name: 'DEBUG', + name: 'Developer', + devModeOnly: true, settings: [ { - name: 'Reload', - control: 'DEBUG_RELOAD' + name: 'Developer Menus', + control: 'DEV_ACCESS' }, + #if GLOBAL_SCRIPT // since theyre integrated into global script - Nex + { + name: 'Open Console', + control: 'DEV_CONSOLE' + }, + { + name: 'Reload State', + control: 'DEV_RELOAD' + }, + #end ] } ]; @@ -154,7 +175,9 @@ class KeybindsOptions extends MusicBeatSubstate { } var k:Int = 0; - for(category in categories) { + for (category in categories) { + if (category.devModeOnly && !Options.devMode) continue; + k++; var title = new Alphabet(0, k * 75, category.name, true); title.screenCenter(X);