11import funkin.modding.module.Module;
22import funkin.modding.ModStore;
33import lime.app.Application;
4+ import funkin.play.PlayState;
5+ import flixel.util.FlxTimer;
46
57class LastRemnantsCharHelper extends Module
68{
@@ -9,25 +11,41 @@ class LastRemnantsCharHelper extends Module
911 super('lastRemnantsCharHelper', 0);
1012 }
1113
12- var dontActivate:Bool;
14+ var shouldSave:Bool;
15+ var timer:FlxTimer;
1316
14- public function onDestroy(event:ScriptEvent):Void
17+ public function onDestroy(event:ScriptEvent)
1518 {
16- dontActivate = true; // Dont allow the onExit code to run
19+ super.onDestroy(event);
20+ if (PlayState.instance != null)
21+ {
22+ if (timer?.active ?? false)
23+ {
24+ shouldSave = false;
25+ timer?.cancel();
26+ return;
27+ }
28+ timer = FlxTimer.wait(0.1, () -> {timer = null;});
29+ }
30+ else
31+ {
32+ shouldSave = false;
33+ }
1734 }
18-
35+
1936 public function onCreate(event:ScriptEvent):Void
2037 {
2138 RemnantsContentUtil.loadLastRemnantsChar();
2239
23- dontActivate = false;
40+ shouldSave = true;
41+
2442 if (!ModStore.stores.exists('lastRemnantsCharHelperInit'))
2543 {
26- Application.current.onExit. add((exitCode ) -> {
27- if (dontActivate ?? true) return; // No more NOR
44+ Application.current.window.onClose. add(() -> {
45+ if (!(shouldSave ?? false)) return;
2846 RemnantsContentUtil.saveLastRemnantsChar();
2947 trace('Saved Remnants(?) Char!');
30- });
48+ }, false, 1000 );
3149 ModStore.register('lastRemnantsCharHelperInit');
3250 }
3351 }
0 commit comments