FINALLY fixed the issue with GlobalState blowing up when pressing F5. (#666)

* peak is happening

<r>RED<r>

* oops

* oops x2

forgot I left a trace when loading up global.hx from `Assets` lol

* **State / SubState reloading broken rn but pushing changes to see if anyone can fix**

* Human... I remember you
<r>disabling reloading substates cuz it broke...<r>

* <y>forgor to edit assets global.hx<y>

* lemme see

* kk

* opa

---------

Co-authored-by: ⍚~Nex <87421482+NexIsDumb@users.noreply.github.com>
This commit is contained in:
ItsLJcool
2025-07-05 01:46:42 +02:00
committed by GitHub
co-authored by ⍚~Nex
parent 7a8f1f0ded
commit 07ae6b643c
10 changed files with 115 additions and 50 deletions
-3
View File
@@ -1,3 +0,0 @@
//
function update(elapsed:Float)
if (FlxG.keys.justPressed.F5) FlxG.resetState();
-2
View File
@@ -59,8 +59,6 @@ function create() {
}
function update(elapsed) {
if (FlxG.keys.justPressed.F5)
FlxG.resetState();
switch(step) {
case 0:
lipSync(tankman, 0, 16750);
+11 -9
View File
@@ -101,6 +101,8 @@ 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;
inline function get_controls():Controls
return PlayerSettings.solo.controls;
inline function get_controlsP1():Controls
@@ -147,16 +149,20 @@ class MusicBeatState extends FlxState implements IBeatReceiver
call("postUpdate", [elapsed]);
}
if (_requestSubStateReset)
{
if (_requestSubStateReset) {
_requestSubStateReset = false;
resetSubState();
}
if (subState != null)
{
subState.tryUpdate(elapsed);
if (/*subState == null && */(ALLOW_DEBUG_RELOAD && controls.DEBUG_RELOAD)) {
Logs.trace("Reloading Current State...", INFO, YELLOW);
FlxG.resetState();
}
if (subState != null)
subState.tryUpdate(elapsed);
}
override function create()
{
loadScript();
@@ -189,10 +195,6 @@ class MusicBeatState extends FlxState implements IBeatReceiver
override function update(elapsed:Float)
{
// TODO: DEBUG MODE!!
if (FlxG.keys.justPressed.F5) {
loadScript();
}
call("update", [elapsed]);
super.update(elapsed);
+8 -8
View File
@@ -126,15 +126,19 @@ class MusicBeatSubstate extends FlxSubState implements IBeatReceiver
call("postUpdate", [elapsed]);
}
if (_requestSubStateReset)
{
// if (subState == null && (MusicBeatState.ALLOW_DEBUG_RELOAD && controls.DEBUG_RELOAD)) {
// Logs.trace("Reloading Current SubState...", INFO, YELLOW);
// var test = Type.createInstance(Type.getClass(this), [this.scriptsAllowed, this.scriptName]);
// parent.openSubState(test);
// }
if (_requestSubStateReset) {
_requestSubStateReset = false;
resetSubState();
}
if (subState != null)
{
subState.tryUpdate(elapsed);
}
}
override function close() {
@@ -171,10 +175,6 @@ class MusicBeatSubstate extends FlxSubState implements IBeatReceiver
override function update(elapsed:Float)
{
// TODO: DEBUG MODE!!
if (FlxG.keys.justPressed.F5) {
loadScript();
}
call("update", [elapsed]);
super.update(elapsed);
}
+28 -11
View File
@@ -11,6 +11,9 @@ import funkin.backend.assets.ModsFolder;
class GlobalScript {
public static var scripts:ScriptPack;
private static var reloading:Bool = false;
private static var _lastAllow_Reload:Bool = false;
public static function init() {
#if MOD_SUPPORT
ModsFolder.onModSwitch.add(onModSwitch);
@@ -42,16 +45,12 @@ class GlobalScript {
});
FlxG.signals.postUpdate.add(function() {
call("postUpdate", [FlxG.elapsed]);
if (FlxG.keys.justPressed.F5) {
if (scripts.scripts.length > 0) {
Logs.trace('Reloading global script...', WARNING, YELLOW);
scripts.reload();
Logs.trace('Global script successfully reloaded.', WARNING, GREEN);
} else {
Logs.trace('Loading global script...', WARNING, YELLOW);
onModSwitch(#if MOD_SUPPORT ModsFolder.currentModFolder #else null #end);
}
if (reloading) {
reloading = false;
MusicBeatState.ALLOW_DEBUG_RELOAD = _lastAllow_Reload;
}
if (FlxG.keys.justPressed.F2)
NativeAPI.allocConsole();
});
@@ -70,12 +69,29 @@ class GlobalScript {
FlxG.signals.preStateSwitch.add(function() {
call("preStateSwitch", []);
});
FlxG.signals.preUpdate.add(function() {
call("preUpdate", [FlxG.elapsed]);
call("update", [FlxG.elapsed]);
});
onModSwitch(#if MOD_SUPPORT ModsFolder.currentModFolder #else null #end);
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) {
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;
// Would be better to just re-initalize GlobalScript so there aren't any lose ends.
onModSwitch(#if MOD_SUPPORT ModsFolder.currentModFolder #else null #end);
}
}
});
}
public static function event<T:CancellableEvent>(name:String, event:T):T {
@@ -88,6 +104,7 @@ class GlobalScript {
if (scripts != null)
scripts.call(name, args);
}
public static function onModSwitch(newMod:String) {
call("destroy");
scripts = FlxDestroyUtil.destroy(scripts);
@@ -53,7 +53,7 @@ class ScriptPack extends Script {
public override function call(func:String, ?parameters:Array<Dynamic>):Dynamic {
for(e in scripts)
if(e.active)
if (e.active)
e.call(func, parameters);
return null;
}
+23
View File
@@ -44,6 +44,9 @@ enum abstract Action(String) to String from String {
var RESET = "reset";
var CHEAT = "cheat";
var SWITCHMOD = "switchmod";
// Debugs
var DEBUG_RELOAD = "debug-reload";
}
enum Device
@@ -73,6 +76,9 @@ enum Control
PAUSE;
CHEAT;
SWITCHMOD;
// Debugs
DEBUG_RELOAD;
}
enum KeyboardScheme
@@ -122,6 +128,8 @@ class Controls extends FlxActionSet
var _reset = new FlxActionDigital(Action.RESET);
var _cheat = new FlxActionDigital(Action.CHEAT);
var _switchMod = new FlxActionDigital(Action.SWITCHMOD);
var debug_reload = new FlxActionDigital(Action.DEBUG_RELOAD);
#if (haxe >= "4.0.0")
var byName:Map<String, FlxActionDigital> = [];
@@ -372,6 +380,14 @@ class Controls extends FlxActionSet
inline function set_SWITCHMOD(val)
return @:privateAccess _switchMod._checked = val;
public var DEBUG_RELOAD(get, set):Bool;
inline function get_DEBUG_RELOAD()
return debug_reload.check();
inline function set_DEBUG_RELOAD(val)
return @:privateAccess debug_reload._checked = val;
public function new(name, scheme = None)
{
super(name);
@@ -408,6 +424,7 @@ class Controls extends FlxActionSet
add(_reset);
add(_cheat);
add(_switchMod);
add(debug_reload);
for (action in digitalActions)
byName[action.name] = action;
@@ -469,6 +486,7 @@ class Controls extends FlxActionSet
case RESET: _reset;
case CHEAT: _cheat;
case SWITCHMOD: _switchMod;
case DEBUG_RELOAD: debug_reload;
}
}
@@ -532,6 +550,8 @@ class Controls extends FlxActionSet
func(_cheat, JUST_PRESSED);
case SWITCHMOD:
func(_switchMod, JUST_PRESSED);
case DEBUG_RELOAD:
func(debug_reload, JUST_PRESSED);
}
}
@@ -687,6 +707,7 @@ class Controls extends FlxActionSet
inline bindKeys(Control.PAUSE, Options.SOLO_PAUSE);
inline bindKeys(Control.RESET, Options.SOLO_RESET);
inline bindKeys(Control.SWITCHMOD, Options.SOLO_SWITCHMOD);
inline bindKeys(Control.DEBUG_RELOAD, Options.SOLO_DEBUG_RELOAD);
case Duo(true):
inline bindKeys(Control.UP, Options.P1_UP);
inline bindKeys(Control.DOWN, Options.P1_DOWN);
@@ -701,6 +722,7 @@ class Controls extends FlxActionSet
inline bindKeys(Control.PAUSE, Options.P1_PAUSE);
inline bindKeys(Control.RESET, Options.P1_RESET);
inline bindKeys(Control.SWITCHMOD, Options.P1_SWITCHMOD);
inline bindKeys(Control.DEBUG_RELOAD, Options.P1_DEBUG_RELOAD);
case Duo(false):
inline bindKeys(Control.UP, Options.P2_UP);
inline bindKeys(Control.DOWN, Options.P2_DOWN);
@@ -715,6 +737,7 @@ class Controls extends FlxActionSet
inline bindKeys(Control.PAUSE, Options.P2_PAUSE);
inline bindKeys(Control.RESET, Options.P2_RESET);
inline bindKeys(Control.SWITCHMOD, Options.P2_SWITCHMOD);
inline bindKeys(Control.DEBUG_RELOAD, Options.P2_DEBUG_RELOAD);
case None: // nothing
case Custom: // nothing
}
+2 -10
View File
@@ -1266,16 +1266,8 @@ class PlayState extends MusicBeatState
if (updateRatingStuff != null)
updateRatingStuff();
if (canAccessDebugMenus) {
if (chartingMode && FlxG.keys.justPressed.SEVEN) {
FlxG.switchState(new funkin.editors.charter.Charter(SONG.meta.name, difficulty, false));
}
if (FlxG.keys.justPressed.F5) {
Logs.trace('Reloading scripts...', WARNING, YELLOW);
scripts.reload();
Logs.trace('Song scripts successfully reloaded.', WARNING, GREEN);
}
}
if (canAccessDebugMenus && chartingMode && FlxG.keys.justPressed.SEVEN)
FlxG.switchState(new funkin.editors.charter.Charter(SONG.meta.name, difficulty, false));
if (doIconBop)
for (icon in iconArray)
+33 -6
View File
@@ -69,12 +69,16 @@ class Options
public static var charterAutoSavesSeperateFolder:Bool = false;
/**
* PLAYER 1 CONTROLS
*/
* PLAYER 1 CONTROLS
*/
// Notes
public static var P1_NOTE_LEFT:Array<FlxKey> = [A];
public static var P1_NOTE_DOWN:Array<FlxKey> = [S];
public static var P1_NOTE_UP:Array<FlxKey> = [W];
public static var P1_NOTE_RIGHT:Array<FlxKey> = [D];
// Menus
public static var P1_LEFT:Array<FlxKey> = [A];
public static var P1_DOWN:Array<FlxKey> = [S];
public static var P1_UP:Array<FlxKey> = [W];
@@ -82,16 +86,25 @@ class Options
public static var P1_ACCEPT:Array<FlxKey> = [ENTER];
public static var P1_BACK:Array<FlxKey> = [BACKSPACE];
public static var P1_PAUSE:Array<FlxKey> = [ENTER];
// Misc
public static var P1_RESET:Array<FlxKey> = [R];
public static var P1_SWITCHMOD:Array<FlxKey> = [TAB];
// Debugs
public static var P1_DEBUG_RELOAD:Array<FlxKey> = [F5];
/**
* PLAYER 2 CONTROLS (ALT)
*/
* PLAYER 2 CONTROLS (ALT)
*/
// Notes
public static var P2_NOTE_LEFT:Array<FlxKey> = [LEFT];
public static var P2_NOTE_DOWN:Array<FlxKey> = [DOWN];
public static var P2_NOTE_UP:Array<FlxKey> = [UP];
public static var P2_NOTE_RIGHT:Array<FlxKey> = [RIGHT];
// Menus
public static var P2_LEFT:Array<FlxKey> = [LEFT];
public static var P2_DOWN:Array<FlxKey> = [DOWN];
public static var P2_UP:Array<FlxKey> = [UP];
@@ -99,16 +112,25 @@ class Options
public static var P2_ACCEPT:Array<FlxKey> = [SPACE];
public static var P2_BACK:Array<FlxKey> = [ESCAPE];
public static var P2_PAUSE:Array<FlxKey> = [ESCAPE];
// Misc
public static var P2_RESET:Array<FlxKey> = [];
public static var P2_SWITCHMOD:Array<FlxKey> = [];
// Debugs
public static var P2_DEBUG_RELOAD:Array<FlxKey> = [];
/**
* SOLO GETTERS
*/
* SOLO GETTERS
*/
// Notes
public static var SOLO_NOTE_LEFT(get, null):Array<FlxKey>;
public static var SOLO_NOTE_DOWN(get, null):Array<FlxKey>;
public static var SOLO_NOTE_UP(get, null):Array<FlxKey>;
public static var SOLO_NOTE_RIGHT(get, null):Array<FlxKey>;
// Menus
public static var SOLO_LEFT(get, null):Array<FlxKey>;
public static var SOLO_DOWN(get, null):Array<FlxKey>;
public static var SOLO_UP(get, null):Array<FlxKey>;
@@ -116,9 +138,14 @@ class Options
public static var SOLO_ACCEPT(get, null):Array<FlxKey>;
public static var SOLO_BACK(get, null):Array<FlxKey>;
public static var SOLO_PAUSE(get, null):Array<FlxKey>;
// Misc
public static var SOLO_RESET(get, null):Array<FlxKey>;
public static var SOLO_SWITCHMOD(get, null):Array<FlxKey>;
// Debugs
public static var SOLO_DEBUG_RELOAD(get, null):Array<FlxKey>;
public static function load() {
if (__save == null) __save = new FlxSave();
__save.bind("options", "CodenameEngine");
@@ -74,6 +74,15 @@ class KeybindsOptions extends MusicBeatSubstate {
control: 'SWITCHMOD'
},
]
},
{
name: 'DEBUG',
settings: [
{
name: 'Reload',
control: 'DEBUG_RELOAD'
},
]
}
];