Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions source/funkin/modding/module/ModuleHandler.hx
Original file line number Diff line number Diff line change
Expand Up @@ -146,19 +146,31 @@ class ModuleHandler
// The module needs to be active to receive events.
if (module != null && module.active)
{
if (module.state != null)
{
// Only call the event if the current state is what the module's state is.
if (!(Type.getClass(FlxG.state) == module.state) && !(Type.getClass(FlxG.state?.subState) == module.state))
{
continue;
}
}
// Only call the event if the module's state is active.
if (!isStateActive(module.state)) continue;

ScriptEventDispatcher.callEvent(module, event);
}
}
}

static function isStateActive(stateToFind:Null<Class<Dynamic>>):Bool
{
if (stateToFind == null) return true;

var statesReading:Array<Class<Dynamic>> = [Type.getClass(FlxG.state)];
while (statesReading.length > 0)
{
var state:Null<Class<Dynamic>> = statesReading.shift();
if (state == null) continue;

if (state == stateToFind) return true;
else if (state.subState != null) statesReading.push(Type.getClass(state.subState));
}

return false;
}

public static inline function callOnCreate():Void
{
callEvent(new ScriptEvent(CREATE, false));
Expand Down
Loading