File tree Expand file tree Collapse file tree
source/funkin/modding/module Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -39,16 +39,27 @@ class Module implements IPlayStateScriptedClass implements IStateChangingScripte
3939 return value ;
4040 }
4141
42+ /**
43+ * The state this module is associated with.
44+ * If set, this module will only receive events when the game is in this state.
45+ */
46+ public var state : Null <Class <Dynamic >> = null ;
47+
4248 /**
4349 * Called when the module is initialized.
4450 * It may not be safe to reference other modules here since they may not be loaded yet.
4551 *
4652 * NOTE: To make the module start inactive, call `this.active = false` in the constructor.
4753 */
48- public function new (moduleId : String , priority : Int = 1000 ): Void
54+ public function new (moduleId : String , priority : Int = 1000 , state : Null < Class < Dynamic >> = null ): Void
4955 {
5056 this .moduleId = moduleId ;
5157 this .priority = priority ;
58+
59+ if (state != null )
60+ {
61+ this .state = state ;
62+ }
5263 }
5364
5465 public function toString ()
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ import funkin.modding.events.ScriptEvent;
66import funkin .modding .events .ScriptEventDispatcher ;
77import funkin .modding .module .Module ;
88import funkin .modding .module .ScriptedModule ;
9+ import flixel .FlxG ;
910
1011/**
1112 * Utility functions for loading and manipulating active modules.
@@ -145,6 +146,14 @@ class ModuleHandler
145146 // The module needs to be active to receive events.
146147 if (module != null && module .active )
147148 {
149+ if (module .state != null )
150+ {
151+ // Only call the event if the current state is what the module's state is.
152+ if (! (Type .getClass (FlxG .state ) == module .state ) && ! (Type .getClass (FlxG .state ?. subState ) == module .state ))
153+ {
154+ continue ;
155+ }
156+ }
148157 ScriptEventDispatcher .callEvent (module , event );
149158 }
150159 }
You can’t perform that action at this time.
0 commit comments