100 lines
3.3 KiB
Haxe
100 lines
3.3 KiB
Haxe
package funkin.scripting;
|
|
|
|
import flixel.FlxG;
|
|
import flixel.FlxState;
|
|
import funkin.mods.ModsFolder;
|
|
#if GLOBAL_SCRIPT
|
|
/**
|
|
* Class for THE Global Script, aka script that runs in the background at all times.
|
|
*/
|
|
class GlobalScript {
|
|
public static var script:Script;
|
|
|
|
public static function init() {
|
|
#if MOD_SUPPORT
|
|
ModsFolder.onModSwitch.add(onModSwitch);
|
|
#end
|
|
FlxG.signals.focusGained.add(function() {
|
|
call("focusGained");
|
|
});
|
|
FlxG.signals.focusLost.add(function() {
|
|
call("focusLost");
|
|
});
|
|
FlxG.signals.gameResized.add(function(w:Int, h:Int) {
|
|
call("gameResized", [w, h]);
|
|
});
|
|
FlxG.signals.postDraw.add(function() {
|
|
call("postDraw");
|
|
});
|
|
FlxG.signals.postGameReset.add(function() {
|
|
call("postGameReset");
|
|
});
|
|
FlxG.signals.postGameStart.add(function() {
|
|
});
|
|
FlxG.signals.postStateSwitch.add(function() {
|
|
call("postStateSwitch");
|
|
});
|
|
FlxG.signals.postUpdate.add(function() {
|
|
call("postUpdate", [FlxG.elapsed]);
|
|
call("updatePost", [FlxG.elapsed]);
|
|
if (FlxG.keys.justPressed.F5) {
|
|
if (script != null && !(script is DummyScript)) {
|
|
Logs.trace('Reloading global script...', WARNING, YELLOW);
|
|
script.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 (script is DummyScript)
|
|
Logs.trace('Global script not found. Are you sure "data/global.hx" exists?', ERROR, RED);
|
|
else
|
|
Logs.trace('Global script successfully loaded.', WARNING, GREEN);
|
|
}
|
|
}
|
|
});
|
|
FlxG.signals.preDraw.add(function() {
|
|
call("preDraw");
|
|
});
|
|
FlxG.signals.preGameReset.add(function() {
|
|
call("preGameReset");
|
|
});
|
|
FlxG.signals.preGameStart.add(function() {
|
|
call("preGameStart");
|
|
});
|
|
FlxG.signals.preStateCreate.add(function(state:FlxState) {
|
|
call("preStateCreate", [state]);
|
|
});
|
|
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);
|
|
}
|
|
|
|
public static function call(name:String, ?args:Array<Dynamic>) {
|
|
if (script == null) return;
|
|
script.call(name, args);
|
|
}
|
|
public static function onModSwitch(newMod:String) {
|
|
trace(newMod);
|
|
if (script != null) {
|
|
script.destroy();
|
|
script = null;
|
|
}
|
|
script = Script.create(Paths.script('data/global'));
|
|
script.load();
|
|
}
|
|
|
|
public static function beatHit(curBeat:Int) {
|
|
call("beatHit", [curBeat]);
|
|
}
|
|
|
|
public static function stepHit(curStep:Int) {
|
|
call("stepHit", [curStep]);
|
|
}
|
|
}
|
|
#end |