Skip to content

Commit 07ae6b6

Browse files
ItsLJcoolNexIsDumb
andauthored
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>
1 parent 7a8f1f0 commit 07ae6b6

File tree

10 files changed

+114
-49
lines changed

10 files changed

+114
-49
lines changed

assets/data/global.hx

Lines changed: 0 additions & 3 deletions
This file was deleted.

assets/songs/stress/cutscene.hx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@ function create() {
5959
}
6060

6161
function update(elapsed) {
62-
if (FlxG.keys.justPressed.F5)
63-
FlxG.resetState();
6462
switch(step) {
6563
case 0:
6664
lipSync(tankman, 0, 16750);

source/funkin/backend/MusicBeatState.hx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ class MusicBeatState extends FlxState implements IBeatReceiver
101101
public static var skipTransOut:Bool = false;
102102
public static var skipTransIn:Bool = false;
103103

104+
public static var ALLOW_DEBUG_RELOAD:Bool = true;
105+
104106
inline function get_controls():Controls
105107
return PlayerSettings.solo.controls;
106108
inline function get_controlsP1():Controls
@@ -147,16 +149,20 @@ class MusicBeatState extends FlxState implements IBeatReceiver
147149
call("postUpdate", [elapsed]);
148150
}
149151

150-
if (_requestSubStateReset)
151-
{
152+
if (_requestSubStateReset) {
152153
_requestSubStateReset = false;
153154
resetSubState();
154155
}
156+
157+
if (/*subState == null && */(ALLOW_DEBUG_RELOAD && controls.DEBUG_RELOAD)) {
158+
Logs.trace("Reloading Current State...", INFO, YELLOW);
159+
FlxG.resetState();
160+
}
161+
155162
if (subState != null)
156-
{
157163
subState.tryUpdate(elapsed);
158-
}
159164
}
165+
160166
override function create()
161167
{
162168
loadScript();
@@ -189,10 +195,6 @@ class MusicBeatState extends FlxState implements IBeatReceiver
189195

190196
override function update(elapsed:Float)
191197
{
192-
// TODO: DEBUG MODE!!
193-
if (FlxG.keys.justPressed.F5) {
194-
loadScript();
195-
}
196198
call("update", [elapsed]);
197199

198200
super.update(elapsed);

source/funkin/backend/MusicBeatSubstate.hx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -126,15 +126,19 @@ class MusicBeatSubstate extends FlxSubState implements IBeatReceiver
126126
call("postUpdate", [elapsed]);
127127
}
128128

129-
if (_requestSubStateReset)
130-
{
129+
// if (subState == null && (MusicBeatState.ALLOW_DEBUG_RELOAD && controls.DEBUG_RELOAD)) {
130+
// Logs.trace("Reloading Current SubState...", INFO, YELLOW);
131+
// var test = Type.createInstance(Type.getClass(this), [this.scriptsAllowed, this.scriptName]);
132+
// parent.openSubState(test);
133+
// }
134+
135+
if (_requestSubStateReset) {
131136
_requestSubStateReset = false;
132137
resetSubState();
133138
}
139+
134140
if (subState != null)
135-
{
136141
subState.tryUpdate(elapsed);
137-
}
138142
}
139143

140144
override function close() {
@@ -171,10 +175,6 @@ class MusicBeatSubstate extends FlxSubState implements IBeatReceiver
171175

172176
override function update(elapsed:Float)
173177
{
174-
// TODO: DEBUG MODE!!
175-
if (FlxG.keys.justPressed.F5) {
176-
loadScript();
177-
}
178178
call("update", [elapsed]);
179179
super.update(elapsed);
180180
}

source/funkin/backend/scripting/GlobalScript.hx

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ import funkin.backend.assets.ModsFolder;
1111
class GlobalScript {
1212
public static var scripts:ScriptPack;
1313

14+
private static var reloading:Bool = false;
15+
private static var _lastAllow_Reload:Bool = false;
16+
1417
public static function init() {
1518
#if MOD_SUPPORT
1619
ModsFolder.onModSwitch.add(onModSwitch);
@@ -42,16 +45,12 @@ class GlobalScript {
4245
});
4346
FlxG.signals.postUpdate.add(function() {
4447
call("postUpdate", [FlxG.elapsed]);
45-
if (FlxG.keys.justPressed.F5) {
46-
if (scripts.scripts.length > 0) {
47-
Logs.trace('Reloading global script...', WARNING, YELLOW);
48-
scripts.reload();
49-
Logs.trace('Global script successfully reloaded.', WARNING, GREEN);
50-
} else {
51-
Logs.trace('Loading global script...', WARNING, YELLOW);
52-
onModSwitch(#if MOD_SUPPORT ModsFolder.currentModFolder #else null #end);
53-
}
48+
49+
if (reloading) {
50+
reloading = false;
51+
MusicBeatState.ALLOW_DEBUG_RELOAD = _lastAllow_Reload;
5452
}
53+
5554
if (FlxG.keys.justPressed.F2)
5655
NativeAPI.allocConsole();
5756
});
@@ -70,12 +69,29 @@ class GlobalScript {
7069
FlxG.signals.preStateSwitch.add(function() {
7170
call("preStateSwitch", []);
7271
});
72+
7373
FlxG.signals.preUpdate.add(function() {
7474
call("preUpdate", [FlxG.elapsed]);
7575
call("update", [FlxG.elapsed]);
76-
});
7776

78-
onModSwitch(#if MOD_SUPPORT ModsFolder.currentModFolder #else null #end);
77+
if (FlxG.keys.pressed.SHIFT) {
78+
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.
79+
if ((FlxG.state is MusicBeatState)) resetKey = cast(FlxG.state, MusicBeatState).controls.DEBUG_RELOAD;
80+
81+
// If we want, we could just make reseting GlobalScript it's own keybind, but for now this works.
82+
if (resetKey) {
83+
reloading = true;
84+
Logs.trace("Reloading Global Scripts...", INFO, YELLOW);
85+
86+
// yeah its a bit messy, sorry. This just prevents actually reloading the actual state.
87+
_lastAllow_Reload = MusicBeatState.ALLOW_DEBUG_RELOAD;
88+
MusicBeatState.ALLOW_DEBUG_RELOAD = false;
89+
90+
// Would be better to just re-initalize GlobalScript so there aren't any lose ends.
91+
onModSwitch(#if MOD_SUPPORT ModsFolder.currentModFolder #else null #end);
92+
}
93+
}
94+
});
7995
}
8096

8197
public static function event<T:CancellableEvent>(name:String, event:T):T {
@@ -88,6 +104,7 @@ class GlobalScript {
88104
if (scripts != null)
89105
scripts.call(name, args);
90106
}
107+
91108
public static function onModSwitch(newMod:String) {
92109
call("destroy");
93110
scripts = FlxDestroyUtil.destroy(scripts);

source/funkin/backend/scripting/ScriptPack.hx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class ScriptPack extends Script {
5353

5454
public override function call(func:String, ?parameters:Array<Dynamic>):Dynamic {
5555
for(e in scripts)
56-
if(e.active)
56+
if (e.active)
5757
e.call(func, parameters);
5858
return null;
5959
}

source/funkin/backend/system/Controls.hx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ enum abstract Action(String) to String from String {
4444
var RESET = "reset";
4545
var CHEAT = "cheat";
4646
var SWITCHMOD = "switchmod";
47+
48+
// Debugs
49+
var DEBUG_RELOAD = "debug-reload";
4750
}
4851

4952
enum Device
@@ -73,6 +76,9 @@ enum Control
7376
PAUSE;
7477
CHEAT;
7578
SWITCHMOD;
79+
80+
// Debugs
81+
DEBUG_RELOAD;
7682
}
7783

7884
enum KeyboardScheme
@@ -122,6 +128,8 @@ class Controls extends FlxActionSet
122128
var _reset = new FlxActionDigital(Action.RESET);
123129
var _cheat = new FlxActionDigital(Action.CHEAT);
124130
var _switchMod = new FlxActionDigital(Action.SWITCHMOD);
131+
132+
var debug_reload = new FlxActionDigital(Action.DEBUG_RELOAD);
125133

126134
#if (haxe >= "4.0.0")
127135
var byName:Map<String, FlxActionDigital> = [];
@@ -372,6 +380,14 @@ class Controls extends FlxActionSet
372380
inline function set_SWITCHMOD(val)
373381
return @:privateAccess _switchMod._checked = val;
374382

383+
public var DEBUG_RELOAD(get, set):Bool;
384+
385+
inline function get_DEBUG_RELOAD()
386+
return debug_reload.check();
387+
388+
inline function set_DEBUG_RELOAD(val)
389+
return @:privateAccess debug_reload._checked = val;
390+
375391
public function new(name, scheme = None)
376392
{
377393
super(name);
@@ -408,6 +424,7 @@ class Controls extends FlxActionSet
408424
add(_reset);
409425
add(_cheat);
410426
add(_switchMod);
427+
add(debug_reload);
411428

412429
for (action in digitalActions)
413430
byName[action.name] = action;
@@ -469,6 +486,7 @@ class Controls extends FlxActionSet
469486
case RESET: _reset;
470487
case CHEAT: _cheat;
471488
case SWITCHMOD: _switchMod;
489+
case DEBUG_RELOAD: debug_reload;
472490
}
473491
}
474492

@@ -532,6 +550,8 @@ class Controls extends FlxActionSet
532550
func(_cheat, JUST_PRESSED);
533551
case SWITCHMOD:
534552
func(_switchMod, JUST_PRESSED);
553+
case DEBUG_RELOAD:
554+
func(debug_reload, JUST_PRESSED);
535555
}
536556
}
537557

@@ -687,6 +707,7 @@ class Controls extends FlxActionSet
687707
inline bindKeys(Control.PAUSE, Options.SOLO_PAUSE);
688708
inline bindKeys(Control.RESET, Options.SOLO_RESET);
689709
inline bindKeys(Control.SWITCHMOD, Options.SOLO_SWITCHMOD);
710+
inline bindKeys(Control.DEBUG_RELOAD, Options.SOLO_DEBUG_RELOAD);
690711
case Duo(true):
691712
inline bindKeys(Control.UP, Options.P1_UP);
692713
inline bindKeys(Control.DOWN, Options.P1_DOWN);
@@ -701,6 +722,7 @@ class Controls extends FlxActionSet
701722
inline bindKeys(Control.PAUSE, Options.P1_PAUSE);
702723
inline bindKeys(Control.RESET, Options.P1_RESET);
703724
inline bindKeys(Control.SWITCHMOD, Options.P1_SWITCHMOD);
725+
inline bindKeys(Control.DEBUG_RELOAD, Options.P1_DEBUG_RELOAD);
704726
case Duo(false):
705727
inline bindKeys(Control.UP, Options.P2_UP);
706728
inline bindKeys(Control.DOWN, Options.P2_DOWN);
@@ -715,6 +737,7 @@ class Controls extends FlxActionSet
715737
inline bindKeys(Control.PAUSE, Options.P2_PAUSE);
716738
inline bindKeys(Control.RESET, Options.P2_RESET);
717739
inline bindKeys(Control.SWITCHMOD, Options.P2_SWITCHMOD);
740+
inline bindKeys(Control.DEBUG_RELOAD, Options.P2_DEBUG_RELOAD);
718741
case None: // nothing
719742
case Custom: // nothing
720743
}

source/funkin/game/PlayState.hx

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1266,16 +1266,8 @@ class PlayState extends MusicBeatState
12661266
if (updateRatingStuff != null)
12671267
updateRatingStuff();
12681268

1269-
if (canAccessDebugMenus) {
1270-
if (chartingMode && FlxG.keys.justPressed.SEVEN) {
1271-
FlxG.switchState(new funkin.editors.charter.Charter(SONG.meta.name, difficulty, false));
1272-
}
1273-
if (FlxG.keys.justPressed.F5) {
1274-
Logs.trace('Reloading scripts...', WARNING, YELLOW);
1275-
scripts.reload();
1276-
Logs.trace('Song scripts successfully reloaded.', WARNING, GREEN);
1277-
}
1278-
}
1269+
if (canAccessDebugMenus && chartingMode && FlxG.keys.justPressed.SEVEN)
1270+
FlxG.switchState(new funkin.editors.charter.Charter(SONG.meta.name, difficulty, false));
12791271

12801272
if (doIconBop)
12811273
for (icon in iconArray)

source/funkin/options/Options.hx

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,56 +69,83 @@ class Options
6969
public static var charterAutoSavesSeperateFolder:Bool = false;
7070

7171
/**
72-
* PLAYER 1 CONTROLS
73-
*/
72+
* PLAYER 1 CONTROLS
73+
*/
74+
75+
// Notes
7476
public static var P1_NOTE_LEFT:Array<FlxKey> = [A];
7577
public static var P1_NOTE_DOWN:Array<FlxKey> = [S];
7678
public static var P1_NOTE_UP:Array<FlxKey> = [W];
7779
public static var P1_NOTE_RIGHT:Array<FlxKey> = [D];
80+
81+
// Menus
7882
public static var P1_LEFT:Array<FlxKey> = [A];
7983
public static var P1_DOWN:Array<FlxKey> = [S];
8084
public static var P1_UP:Array<FlxKey> = [W];
8185
public static var P1_RIGHT:Array<FlxKey> = [D];
8286
public static var P1_ACCEPT:Array<FlxKey> = [ENTER];
8387
public static var P1_BACK:Array<FlxKey> = [BACKSPACE];
8488
public static var P1_PAUSE:Array<FlxKey> = [ENTER];
89+
90+
// Misc
8591
public static var P1_RESET:Array<FlxKey> = [R];
8692
public static var P1_SWITCHMOD:Array<FlxKey> = [TAB];
93+
94+
// Debugs
95+
public static var P1_DEBUG_RELOAD:Array<FlxKey> = [F5];
8796

8897
/**
89-
* PLAYER 2 CONTROLS (ALT)
90-
*/
98+
* PLAYER 2 CONTROLS (ALT)
99+
*/
100+
101+
// Notes
91102
public static var P2_NOTE_LEFT:Array<FlxKey> = [LEFT];
92103
public static var P2_NOTE_DOWN:Array<FlxKey> = [DOWN];
93104
public static var P2_NOTE_UP:Array<FlxKey> = [UP];
94105
public static var P2_NOTE_RIGHT:Array<FlxKey> = [RIGHT];
106+
107+
// Menus
95108
public static var P2_LEFT:Array<FlxKey> = [LEFT];
96109
public static var P2_DOWN:Array<FlxKey> = [DOWN];
97110
public static var P2_UP:Array<FlxKey> = [UP];
98111
public static var P2_RIGHT:Array<FlxKey> = [RIGHT];
99112
public static var P2_ACCEPT:Array<FlxKey> = [SPACE];
100113
public static var P2_BACK:Array<FlxKey> = [ESCAPE];
101114
public static var P2_PAUSE:Array<FlxKey> = [ESCAPE];
115+
116+
// Misc
102117
public static var P2_RESET:Array<FlxKey> = [];
103118
public static var P2_SWITCHMOD:Array<FlxKey> = [];
119+
120+
// Debugs
121+
public static var P2_DEBUG_RELOAD:Array<FlxKey> = [];
104122

105123
/**
106-
* SOLO GETTERS
107-
*/
124+
* SOLO GETTERS
125+
*/
126+
127+
// Notes
108128
public static var SOLO_NOTE_LEFT(get, null):Array<FlxKey>;
109129
public static var SOLO_NOTE_DOWN(get, null):Array<FlxKey>;
110130
public static var SOLO_NOTE_UP(get, null):Array<FlxKey>;
111131
public static var SOLO_NOTE_RIGHT(get, null):Array<FlxKey>;
132+
133+
// Menus
112134
public static var SOLO_LEFT(get, null):Array<FlxKey>;
113135
public static var SOLO_DOWN(get, null):Array<FlxKey>;
114136
public static var SOLO_UP(get, null):Array<FlxKey>;
115137
public static var SOLO_RIGHT(get, null):Array<FlxKey>;
116138
public static var SOLO_ACCEPT(get, null):Array<FlxKey>;
117139
public static var SOLO_BACK(get, null):Array<FlxKey>;
118140
public static var SOLO_PAUSE(get, null):Array<FlxKey>;
141+
142+
// Misc
119143
public static var SOLO_RESET(get, null):Array<FlxKey>;
120144
public static var SOLO_SWITCHMOD(get, null):Array<FlxKey>;
121145

146+
// Debugs
147+
public static var SOLO_DEBUG_RELOAD(get, null):Array<FlxKey>;
148+
122149
public static function load() {
123150
if (__save == null) __save = new FlxSave();
124151
__save.bind("options", "CodenameEngine");

source/funkin/options/keybinds/KeybindsOptions.hx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,15 @@ class KeybindsOptions extends MusicBeatSubstate {
7474
control: 'SWITCHMOD'
7575
},
7676
]
77+
},
78+
{
79+
name: 'DEBUG',
80+
settings: [
81+
{
82+
name: 'Reload',
83+
control: 'DEBUG_RELOAD'
84+
},
85+
]
7786
}
7887
];
7988

0 commit comments

Comments
 (0)