mirror of
https://github.com/FunkinCrew/Funkin.git
synced 2025-08-28 16:39:16 -04:00
Working events in chart editor
This commit is contained in:
parent
7f9171203a
commit
6d7913786e
44 changed files with 13661 additions and 12007 deletions
|
@ -11,132 +11,137 @@ import funkin.modding.module.ScriptedModule;
|
|||
*/
|
||||
class ModuleHandler
|
||||
{
|
||||
static final moduleCache:Map<String, Module> = new Map<String, Module>();
|
||||
static var modulePriorityOrder:Array<String> = [];
|
||||
static final moduleCache:Map<String, Module> = new Map<String, Module>();
|
||||
static var modulePriorityOrder:Array<String> = [];
|
||||
|
||||
/**
|
||||
* 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...");
|
||||
/**
|
||||
* 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);
|
||||
if (module != null)
|
||||
{
|
||||
trace(' Loaded module: ${moduleCls}');
|
||||
var scriptedModuleClassNames:Array<String> = ScriptedModule.listScriptClasses();
|
||||
trace(' Instantiating ${scriptedModuleClassNames.length} modules...');
|
||||
for (moduleCls in scriptedModuleClassNames)
|
||||
{
|
||||
var module:Module = ScriptedModule.init(moduleCls, moduleCls);
|
||||
if (module != null)
|
||||
{
|
||||
trace(' Loaded module: ${moduleCls}');
|
||||
|
||||
// Then store it.
|
||||
addToModuleCache(module);
|
||||
}
|
||||
else
|
||||
{
|
||||
trace(' Failed to instantiate module: ${moduleCls}');
|
||||
}
|
||||
}
|
||||
reorderModuleCache();
|
||||
// Then store it.
|
||||
addToModuleCache(module);
|
||||
}
|
||||
else
|
||||
{
|
||||
trace(' Failed to instantiate module: ${moduleCls}');
|
||||
}
|
||||
}
|
||||
reorderModuleCache();
|
||||
|
||||
trace("[MODULEHANDLER] Module cache loaded.");
|
||||
}
|
||||
trace("[MODULEHANDLER] Module cache loaded.");
|
||||
}
|
||||
|
||||
public static function buildModuleCallbacks():Void
|
||||
{
|
||||
FlxG.signals.postStateSwitch.add(onStateSwitchComplete);
|
||||
}
|
||||
public static function buildModuleCallbacks():Void
|
||||
{
|
||||
FlxG.signals.postStateSwitch.add(onStateSwitchComplete);
|
||||
}
|
||||
|
||||
static function onStateSwitchComplete():Void
|
||||
{
|
||||
callEvent(new StateChangeScriptEvent(ScriptEvent.STATE_CHANGE_END, FlxG.state, true));
|
||||
}
|
||||
static function onStateSwitchComplete():Void
|
||||
{
|
||||
callEvent(new StateChangeScriptEvent(ScriptEvent.STATE_CHANGE_END, FlxG.state, true));
|
||||
}
|
||||
|
||||
static function addToModuleCache(module:Module):Void
|
||||
{
|
||||
moduleCache.set(module.moduleId, module);
|
||||
}
|
||||
static function addToModuleCache(module:Module):Void
|
||||
{
|
||||
moduleCache.set(module.moduleId, module);
|
||||
}
|
||||
|
||||
static function reorderModuleCache():Void
|
||||
{
|
||||
modulePriorityOrder = moduleCache.keys().array();
|
||||
static function reorderModuleCache():Void
|
||||
{
|
||||
modulePriorityOrder = moduleCache.keys().array();
|
||||
|
||||
modulePriorityOrder.sort(function(a:String, b:String):Int
|
||||
{
|
||||
var aModule:Module = moduleCache.get(a);
|
||||
var bModule:Module = moduleCache.get(b);
|
||||
modulePriorityOrder.sort(function(a:String, b:String):Int
|
||||
{
|
||||
var aModule:Module = moduleCache.get(a);
|
||||
var bModule:Module = moduleCache.get(b);
|
||||
|
||||
if (aModule.priority != bModule.priority)
|
||||
{
|
||||
return aModule.priority - bModule.priority;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Sort alphabetically. Yes that's how this works.
|
||||
return a > b ? 1 : -1;
|
||||
}
|
||||
});
|
||||
}
|
||||
if (aModule.priority != bModule.priority)
|
||||
{
|
||||
return aModule.priority - bModule.priority;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Sort alphabetically. Yes that's how this works.
|
||||
return a > b ? 1 : -1;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static function getModule(moduleId:String):Module
|
||||
{
|
||||
return moduleCache.get(moduleId);
|
||||
}
|
||||
public static function getModule(moduleId:String):Module
|
||||
{
|
||||
return moduleCache.get(moduleId);
|
||||
}
|
||||
|
||||
public static function activateModule(moduleId:String):Void
|
||||
{
|
||||
var module:Module = getModule(moduleId);
|
||||
if (module != null)
|
||||
{
|
||||
module.active = true;
|
||||
}
|
||||
}
|
||||
public static function activateModule(moduleId:String):Void
|
||||
{
|
||||
var module:Module = getModule(moduleId);
|
||||
if (module != null)
|
||||
{
|
||||
module.active = true;
|
||||
}
|
||||
}
|
||||
|
||||
public static function deactivateModule(moduleId:String):Void
|
||||
{
|
||||
var module:Module = getModule(moduleId);
|
||||
if (module != null)
|
||||
{
|
||||
module.active = false;
|
||||
}
|
||||
}
|
||||
public static function deactivateModule(moduleId:String):Void
|
||||
{
|
||||
var module:Module = getModule(moduleId);
|
||||
if (module != null)
|
||||
{
|
||||
module.active = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the module cache, forcing all modules to call shutdown events.
|
||||
*/
|
||||
public static function clearModuleCache():Void
|
||||
{
|
||||
if (moduleCache != null)
|
||||
{
|
||||
var event = new ScriptEvent(ScriptEvent.DESTROY, false);
|
||||
/**
|
||||
* Clear the module cache, forcing all modules to call shutdown events.
|
||||
*/
|
||||
public static function clearModuleCache():Void
|
||||
{
|
||||
if (moduleCache != null)
|
||||
{
|
||||
var event = new ScriptEvent(ScriptEvent.DESTROY, false);
|
||||
|
||||
// Note: Ignore stopPropagation()
|
||||
for (key => value in moduleCache)
|
||||
{
|
||||
ScriptEventDispatcher.callEvent(value, event);
|
||||
moduleCache.remove(key);
|
||||
}
|
||||
// Note: Ignore stopPropagation()
|
||||
for (key => value in moduleCache)
|
||||
{
|
||||
ScriptEventDispatcher.callEvent(value, event);
|
||||
moduleCache.remove(key);
|
||||
}
|
||||
|
||||
moduleCache.clear();
|
||||
modulePriorityOrder = [];
|
||||
}
|
||||
}
|
||||
moduleCache.clear();
|
||||
modulePriorityOrder = [];
|
||||
}
|
||||
}
|
||||
|
||||
public static function callEvent(event:ScriptEvent):Void
|
||||
{
|
||||
for (moduleId in modulePriorityOrder)
|
||||
{
|
||||
var module:Module = moduleCache.get(moduleId);
|
||||
// The module needs to be active to receive events.
|
||||
if (module != null && module.active)
|
||||
{
|
||||
ScriptEventDispatcher.callEvent(module, event);
|
||||
}
|
||||
}
|
||||
}
|
||||
public static function callEvent(event:ScriptEvent):Void
|
||||
{
|
||||
for (moduleId in modulePriorityOrder)
|
||||
{
|
||||
var module:Module = moduleCache.get(moduleId);
|
||||
// The module needs to be active to receive events.
|
||||
if (module != null && module.active)
|
||||
{
|
||||
ScriptEventDispatcher.callEvent(module, event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static inline function callOnCreate():Void
|
||||
{
|
||||
callEvent(new ScriptEvent(ScriptEvent.CREATE, false));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue