mirror of
https://github.com/FunkinCrew/Funkin.git
synced 2025-08-28 16:39:16 -04:00
Scripted module and script event systems, reworked strumlines.
This commit is contained in:
parent
fe109f878f
commit
49b2907a30
32 changed files with 1992 additions and 1047 deletions
67
source/funkin/modding/module/ModuleHandler.hx
Normal file
67
source/funkin/modding/module/ModuleHandler.hx
Normal file
|
@ -0,0 +1,67 @@
|
|||
package funkin.modding.module;
|
||||
|
||||
import funkin.modding.events.ScriptEventDispatcher;
|
||||
import funkin.modding.events.ScriptEvent;
|
||||
import funkin.modding.events.ScriptEvent.UpdateScriptEvent;
|
||||
|
||||
/**
|
||||
* Utility functions for loading and manipulating active modules.
|
||||
*/
|
||||
class ModuleHandler
|
||||
{
|
||||
static final moduleCache:Map<String, Module> = new Map<String, Module>();
|
||||
|
||||
/**
|
||||
* Whether modules start active by default.
|
||||
*/
|
||||
static final DEFAULT_STARTACTIVE:Bool = true;
|
||||
|
||||
/**
|
||||
* Parses and preloads the game's stage data and scripts when the game starts.
|
||||
*
|
||||
* If you want to force stages to be reloaded, you can just call this function again.
|
||||
*/
|
||||
public static function loadModuleCache():Void
|
||||
{
|
||||
// Clear any stages that are cached if there were any.
|
||||
clearModuleCache();
|
||||
trace("[MODULEHANDLER] Loading module cache...");
|
||||
|
||||
var scriptedModuleClassNames:Array<String> = ScriptedModule.listScriptClasses();
|
||||
trace(' Instantiating ${scriptedModuleClassNames.length} modules...');
|
||||
for (moduleCls in scriptedModuleClassNames)
|
||||
{
|
||||
var module:Module = ScriptedModule.init(moduleCls, moduleCls, DEFAULT_STARTACTIVE);
|
||||
if (module != null)
|
||||
{
|
||||
trace(' Loaded module: ${moduleCls}');
|
||||
|
||||
// Then store it.
|
||||
moduleCache.set(module.moduleId, module);
|
||||
}
|
||||
else
|
||||
{
|
||||
trace(' Failed to instantiate module: ${moduleCls}');
|
||||
}
|
||||
}
|
||||
|
||||
trace("[MODULEHANDLER] Module cache loaded.");
|
||||
}
|
||||
|
||||
public static function clearModuleCache():Void
|
||||
{
|
||||
if (moduleCache != null)
|
||||
{
|
||||
// for (module in moduleCache)
|
||||
// {
|
||||
// module.destroy();
|
||||
// }
|
||||
moduleCache.clear();
|
||||
}
|
||||
}
|
||||
|
||||
public static function callEvent(event:ScriptEvent):Void
|
||||
{
|
||||
ScriptEventDispatcher.callEventOnAllTargets(moduleCache.iterator(), event);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue