Skip to content

Commit

Permalink
Fix F5 chart not reloading
Browse files Browse the repository at this point in the history
  • Loading branch information
gamerbross authored and charlesisfeline committed Jul 15, 2024
1 parent 35df468 commit fe9b4e7
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 68 deletions.
59 changes: 4 additions & 55 deletions source/funkin/play/PlayState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -1491,64 +1491,13 @@ class PlayState extends MusicBeatSubState
}

/**
* Removes any references to the current stage, then clears the stage cache,
* then reloads all the stages.
*
* This is useful for when you want to edit a stage without reloading the whole game.
* Reloading works on both the JSON and the HXC, if applicable.
*
* Call this by pressing F5 on a debug build.
*/
override function debug_refreshModules():Void
override function reloadAssets():Void
{
// Prevent further gameplay updates, which will try to reference dead objects.
criticalFailure = true;

// Remove the current stage. If the stage gets deleted while it's still in use,
// it'll probably crash the game or something.
if (this.currentStage != null)
{
remove(currentStage);
var event:ScriptEvent = new ScriptEvent(DESTROY, false);
ScriptEventDispatcher.callEvent(currentStage, event);
currentStage = null;
}

if (!overrideMusic)
{
// Stop the instrumental.
if (FlxG.sound.music != null)
{
FlxG.sound.music.destroy();
FlxG.sound.music = null;
}

// Stop the vocals.
if (vocals != null && vocals.exists)
{
vocals.destroy();
vocals = null;
}
}
else
{
// Stop the instrumental.
if (FlxG.sound.music != null)
{
FlxG.sound.music.stop();
}

// Stop the vocals.
if (vocals != null && vocals.exists)
{
vocals.stop();
}
}

super.debug_refreshModules();

var event:ScriptEvent = new ScriptEvent(CREATE, false);
ScriptEventDispatcher.callEvent(currentSong, event);
funkin.modding.PolymodHandler.forceReloadAssets();
lastParams.targetSong = SongRegistry.instance.fetchEntry(currentSong.id);
LoadingState.loadPlayState(lastParams);
}

override function stepHit():Bool
Expand Down
7 changes: 1 addition & 6 deletions source/funkin/ui/MusicBeatState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,6 @@ class MusicBeatState extends FlxTransitionableState implements IEventHandler
{
// Emergency exit button.
if (FlxG.keys.justPressed.F4) FlxG.switchState(() -> new MainMenuState());

// This can now be used in EVERY STATE YAY!
if (FlxG.keys.justPressed.F5) debug_refreshModules();
}

override function update(elapsed:Float)
Expand Down Expand Up @@ -114,12 +111,10 @@ class MusicBeatState extends FlxTransitionableState implements IEventHandler
ModuleHandler.callEvent(event);
}

function debug_refreshModules()
function reloadAssets()
{
PolymodHandler.forceReloadAssets();

this.destroy();

// Create a new instance of the current state, so old data is cleared.
FlxG.resetState();
}
Expand Down
5 changes: 1 addition & 4 deletions source/funkin/ui/MusicBeatSubState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,14 @@ class MusicBeatSubState extends FlxSubState implements IEventHandler
// Emergency exit button.
if (FlxG.keys.justPressed.F4) FlxG.switchState(() -> new MainMenuState());

// This can now be used in EVERY STATE YAY!
if (FlxG.keys.justPressed.F5) debug_refreshModules();

// Display Conductor info in the watch window.
FlxG.watch.addQuick("musicTime", FlxG.sound.music?.time ?? 0.0);
Conductor.watchQuick(conductorInUse);

dispatchEvent(new UpdateScriptEvent(elapsed));
}

function debug_refreshModules()
function reloadAssets()
{
PolymodHandler.forceReloadAssets();

Expand Down
14 changes: 11 additions & 3 deletions source/funkin/util/plugins/ReloadAssetsDebugPlugin.hx
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package funkin.util.plugins;

import flixel.FlxG;
import flixel.FlxBasic;
import funkin.ui.MusicBeatState;
import funkin.ui.MusicBeatSubState;

/**
* A plugin which adds functionality to press `F5` to reload all game assets, then reload the current state.
Expand Down Expand Up @@ -28,10 +31,15 @@ class ReloadAssetsDebugPlugin extends FlxBasic
if (FlxG.keys.justPressed.F5)
#end
{
funkin.modding.PolymodHandler.forceReloadAssets();
var state:Dynamic = FlxG.state;
if (state is MusicBeatState || state is MusicBeatSubState) state.reloadAssets();
else
{
funkin.modding.PolymodHandler.forceReloadAssets();

// Create a new instance of the current state, so old data is cleared.
FlxG.resetState();
// Create a new instance of the current state, so old data is cleared.
FlxG.resetState();
}
}
}

Expand Down

0 comments on commit fe9b4e7

Please sign in to comment.