callbacks... events, even.

This commit is contained in:
Yoshman29
2022-10-09 14:47:42 +02:00
parent 44a5f4b1be
commit aa46bc3335
5 changed files with 50 additions and 2 deletions
+16
View File
@@ -1,5 +1,7 @@
package funkin.scripting;
import funkin.scripting.events.CancellableEvent;
class ScriptPack extends Script {
public var scripts:Array<Script> = [];
public var additionalDefaultVariables:Map<String, Dynamic> = [];
@@ -17,6 +19,20 @@ class ScriptPack extends Script {
return null;
}
/**
* Sends an event to every single script, and returns the event.
* @param func Function to call
* @param event Event (will be the first parameter of the function)
* @return Event (modified by scripts)
*/
public function event<T:CancellableEvent>(func:String, event:T):T {
for(e in scripts) {
e.call(func, [event]);
if (event.cancelled && event.__continueCalls) break;
}
return event;
}
public override function get(val:String):Dynamic {
for(e in scripts) {
var v = e.get(val);