2024-01-04 00:53:17 +00:00
|
|
|
package funkin.util.plugins;
|
|
|
|
|
2024-07-09 22:23:06 +00:00
|
|
|
import flixel.FlxG;
|
2024-01-04 00:53:17 +00:00
|
|
|
import flixel.FlxBasic;
|
2024-07-09 22:23:06 +00:00
|
|
|
import funkin.ui.MusicBeatState;
|
|
|
|
import funkin.ui.MusicBeatSubState;
|
2024-01-04 00:53:17 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A plugin which adds functionality to press `F5` to reload all game assets, then reload the current state.
|
|
|
|
* This is useful for hot reloading assets during development.
|
|
|
|
*/
|
|
|
|
class ReloadAssetsDebugPlugin extends FlxBasic
|
|
|
|
{
|
|
|
|
public function new()
|
|
|
|
{
|
|
|
|
super();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function initialize():Void
|
|
|
|
{
|
|
|
|
FlxG.plugins.addPlugin(new ReloadAssetsDebugPlugin());
|
|
|
|
}
|
|
|
|
|
|
|
|
public override function update(elapsed:Float):Void
|
|
|
|
{
|
|
|
|
super.update(elapsed);
|
|
|
|
|
2024-03-15 20:45:18 +00:00
|
|
|
#if html5
|
|
|
|
if (FlxG.keys.justPressed.FIVE && FlxG.keys.pressed.SHIFT)
|
|
|
|
#else
|
2024-01-04 00:53:17 +00:00
|
|
|
if (FlxG.keys.justPressed.F5)
|
2024-03-15 20:45:18 +00:00
|
|
|
#end
|
2024-01-04 00:53:17 +00:00
|
|
|
{
|
2024-07-09 22:23:06 +00:00
|
|
|
var state:Dynamic = FlxG.state;
|
|
|
|
if (state is MusicBeatState || state is MusicBeatSubState) state.reloadAssets();
|
|
|
|
else
|
|
|
|
{
|
|
|
|
funkin.modding.PolymodHandler.forceReloadAssets();
|
2024-01-04 00:53:17 +00:00
|
|
|
|
2024-07-09 22:23:06 +00:00
|
|
|
// Create a new instance of the current state, so old data is cleared.
|
|
|
|
FlxG.resetState();
|
|
|
|
}
|
2024-01-04 00:53:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public override function destroy():Void
|
|
|
|
{
|
|
|
|
super.destroy();
|
|
|
|
}
|
|
|
|
}
|