Skip to content

Commit

Permalink
add exit code to game close event
Browse files Browse the repository at this point in the history
  • Loading branch information
cyn0x8 committed Feb 18, 2025
1 parent 8aeb104 commit fd2ffd3
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion source/funkin/modding/IScriptedClass.hx
Original file line number Diff line number Diff line change
Expand Up @@ -212,5 +212,5 @@ interface IGlobalScriptedClass extends IPlayStateScriptedClass extends IStateCha
* Called when the game is closed for any reason.
* This event is only called once.
*/
public function onGameClose(event:ScriptEvent):Void;
public function onGameClose(event:GameCloseScriptEvent):Void;
}
17 changes: 17 additions & 0 deletions source/funkin/modding/events/ScriptEvent.hx
Original file line number Diff line number Diff line change
Expand Up @@ -512,3 +512,20 @@ class PauseScriptEvent extends ScriptEvent
this.gitaroo = gitaroo;
}
}

/**
* An event which is called when the game is closed for any reason.
*/
class GameCloseScriptEvent extends ScriptEvent
{
/**
* The exit code. Any non-zero value is likely an error.
*/
public var exitCode(default, null):Int;

public function new(exitCode:Int):Void
{
super(GAME_CLOSE, false);
this.exitCode = exitCode;
}
}
2 changes: 1 addition & 1 deletion source/funkin/modding/events/ScriptEventDispatcher.hx
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ class ScriptEventDispatcher
t.onGameInit(event);
return;
case GAME_CLOSE:
t.onGameClose(event);
t.onGameClose(cast event);
return;
default: // Continue;
}
Expand Down
2 changes: 1 addition & 1 deletion source/funkin/modding/module/Module.hx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class Module implements IGlobalScriptedClass
* Called when the game is closed for any reason.
* This happens only once, immediately before the module's last `onDestroy` event.
*/
public function onGameClose(event:ScriptEvent) {}
public function onGameClose(event:GameCloseScriptEvent) {}

/**
* Called when the module is created.
Expand Down
2 changes: 1 addition & 1 deletion source/funkin/modding/module/ModuleHandler.hx
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,6 @@ class ModuleHandler

public static inline function callOnGameClose(exitCode:Int):Void
{
callEvent(new ScriptEvent(GAME_CLOSE, false));
callEvent(new GameCloseScriptEvent(exitCode));
}
}

0 comments on commit fd2ffd3

Please sign in to comment.