dev mode implementation

This commit is contained in:
⍚~Nex
2025-07-07 01:53:02 +02:00
parent 86157be887
commit e6766cdcd7
10 changed files with 85 additions and 33 deletions
+2 -2
View File
@@ -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();
}
+1 -1
View File
@@ -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);
@@ -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);
+20 -5
View File
@@ -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<String, FlxActionDigital> = [];
@@ -14,6 +14,7 @@ class ControlsMacro
{
static var _allControls: Array<String> = null;
static var _allInternalControls: Array<String> = null;
static var _allDevModeOnlyControls: Array<String> = null;
static var _currentControls: Map<String, Array<Expr>> = null;
static var _currentGamepadControls: Map<String, Expr> = null;
static var _keySet: Map<String, String> = 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,
+1 -1
View File
@@ -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)
+1 -1
View File
@@ -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());
+10 -3
View File
@@ -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<FlxKey> = [];
// Debugs
public static var P1_DEBUG_RELOAD:Array<FlxKey> = [F5];
public static var P1_DEV_ACCESS:Array<FlxKey> = [SEVEN];
public static var P1_DEV_CONSOLE:Array<FlxKey> = [F2];
public static var P1_DEV_RELOAD:Array<FlxKey> = [F5];
/**
* PLAYER 2 CONTROLS (ALT)
@@ -128,7 +131,9 @@ class Options
public static var P2_VOLUME_MUTE:Array<FlxKey> = [NUMPADZERO];
// Debugs
public static var P2_DEBUG_RELOAD:Array<FlxKey> = [];
public static var P2_DEV_ACCESS:Array<FlxKey> = [];
public static var P2_DEV_CONSOLE:Array<FlxKey> = [];
public static var P2_DEV_RELOAD:Array<FlxKey> = [];
/**
* SOLO GETTERS
@@ -157,7 +162,9 @@ class Options
public static var SOLO_VOLUME_MUTE(get, null):Array<FlxKey>;
// Debugs
public static var SOLO_DEBUG_RELOAD(get, null):Array<FlxKey>;
public static var SOLO_DEV_ACCESS(get, null):Array<FlxKey>;
public static var SOLO_DEV_CONSOLE(get, null):Array<FlxKey>;
public static var SOLO_DEV_RELOAD(get, null):Array<FlxKey>;
public static function load() {
if (__save == null) __save = new FlxSave();
@@ -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",
@@ -4,10 +4,20 @@ import flixel.util.FlxColor;
using StringTools;
typedef KeybindsCategory = {
var name:String;
var settings:Array<KeybindsSettings>;
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<KeybindsCategory> = [
{
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);