Added some more documentation

This commit is contained in:
Ne_Eo
2024-12-16 04:37:18 +01:00
parent a6c99754fd
commit aec73ab2b6
25 changed files with 298 additions and 12 deletions
+61 -1
View File
@@ -3,6 +3,9 @@ package funkin.backend.scripting;
import flixel.util.FlxStringUtil;
import funkin.backend.scripting.events.CancellableEvent;
/**
* Used to group multiple scripts together, and easily be able to call them.
**/
@:access(CancellableEvent)
class ScriptPack extends Script {
public var scripts:Array<Script> = [];
@@ -10,12 +13,19 @@ class ScriptPack extends Script {
public var publicVariables:Map<String, Dynamic> = [];
public var parent:Dynamic = null;
/**
* Loads all scripts in the pack.
**/
public override function load() {
for(e in scripts) {
e.load();
}
}
/**
* Checks if the script pack contains a script with a specific path.
* @param path Path to check
*/
public function contains(path:String) {
for(e in scripts)
if (e.path == path)
@@ -27,6 +37,10 @@ class ScriptPack extends Script {
super(name);
}
/**
* Gets a script by path.
* @param name Path to the script
**/
public function getByPath(name:String) {
for(s in scripts)
if (s.path == name)
@@ -34,12 +48,22 @@ class ScriptPack extends Script {
return null;
}
/**
* Gets a script by name.
* @param name Name of the script
**/
public function getByName(name:String) {
for(s in scripts)
if (s.fileName == name)
return s;
return null;
}
/**
* Imports a script by path.
* @param path Path to the script
* @throws Error if the script does not exist
**/
public function importScript(path:String):Script {
var script = Script.create(Paths.script(path));
if (script is DummyScript) {
@@ -51,6 +75,12 @@ class ScriptPack extends Script {
return script;
}
/**
* Calls a function on every single script.
* Only calls on scripts that are active.
* @param func Function to call
* @param parameters Parameters to pass to the function
**/
public override function call(func:String, ?parameters:Array<Dynamic>):Dynamic {
for(e in scripts)
if(e.active)
@@ -74,6 +104,10 @@ class ScriptPack extends Script {
return event;
}
/**
* Gets the first script that has a variable with a specific name.
* @param val Name of the variable
**/
public override function get(val:String):Dynamic {
for(e in scripts) {
var v = e.get(val);
@@ -82,40 +116,66 @@ class ScriptPack extends Script {
return null;
}
/**
* Reloads all scripts in the pack.
**/
public override function reload() {
for(e in scripts) e.reload();
}
/**
* Sets a variable in every script.
**/
public override function set(val:String, value:Dynamic) {
for(e in scripts) e.set(val, value);
}
/**
* Sets the parent/this of every script in the pack.
*/
public override function setParent(parent:Dynamic) {
this.parent = parent;
for(e in scripts) e.setParent(parent);
}
/**
* Destroys all scripts in the pack.
**/
public override function destroy() {
super.destroy();
for(e in scripts) e.destroy();
}
public override function onCreate(path:String) {}
@:dox(hide) public override function onCreate(path:String) {}
/**
* Adds a script to the pack, and sets the parent/this of the script.
**/
public function add(script:Script) {
scripts.push(script);
__configureNewScript(script);
}
/**
* Removes a script from the pack.
* Does not reset the parent/this.
**/
public function remove(script:Script) {
scripts.remove(script);
}
/**
* Inserts a script into the pack, and sets the parent/this of the script.
**/
public function insert(pos:Int, script:Script) {
scripts.insert(pos, script);
__configureNewScript(script);
}
/**
* Configures a new script.
* @param script Script to configure
**/
private function __configureNewScript(script:Script) {
if (parent != null) script.setParent(parent);
script.setPublicMap(publicVariables);