Merge branch 'main' into translations-system
This commit is contained in:
@@ -4,7 +4,7 @@ import flixel.FlxState;
|
||||
import funkin.backend.scripting.events.*;
|
||||
|
||||
class EventManager {
|
||||
// map doesnt work for that
|
||||
// map doesn't work for that
|
||||
public static var eventValues:Array<CancellableEvent> = [];
|
||||
public static var eventKeys:Array<Class<CancellableEvent>> = [];
|
||||
|
||||
|
||||
@@ -11,11 +11,11 @@ import funkin.backend.system.Conductor;
|
||||
class GlobalScript {
|
||||
public static var scripts:ScriptPack;
|
||||
|
||||
private static var initalized:Bool = false;
|
||||
private static var initialized:Bool = false;
|
||||
|
||||
public static function init() {
|
||||
if(initalized) return;
|
||||
initalized = true;
|
||||
if(initialized) return;
|
||||
initialized = true;
|
||||
#if MOD_SUPPORT
|
||||
ModsFolder.onModSwitch.add(onModSwitch);
|
||||
#end
|
||||
|
||||
@@ -16,7 +16,7 @@ class HScript extends Script {
|
||||
public static function initParser() {
|
||||
var parser = new Parser();
|
||||
parser.allowJSON = parser.allowMetadata = parser.allowTypes = true;
|
||||
parser.preprocesorValues = Script.getDefaultPreprocessors();
|
||||
parser.preprocessorValues = Script.getDefaultPreprocessors();
|
||||
return parser;
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import lime.app.Application;
|
||||
@:allow(funkin.backend.scripting.ScriptPack)
|
||||
/**
|
||||
* Class used for scripting.
|
||||
* Use `Script.create` to create a script.
|
||||
*/
|
||||
class Script extends FlxBasic implements IFlxDestroyable {
|
||||
/**
|
||||
@@ -16,6 +17,9 @@ class Script extends FlxBasic implements IFlxDestroyable {
|
||||
*/
|
||||
public static var staticVariables:Map<String, Dynamic> = [];
|
||||
|
||||
/**
|
||||
* Gets the default variables for a script.
|
||||
*/
|
||||
public static function getDefaultVariables(?script:Script):Map<String, Dynamic> {
|
||||
return [
|
||||
// Haxe related stuff
|
||||
@@ -109,7 +113,6 @@ class Script extends FlxBasic implements IFlxDestroyable {
|
||||
**/
|
||||
public static function getDefaultImportRedirects():Map<String, String> {
|
||||
var redirects:Map<String, String> = [
|
||||
"funkin.savedata.FunkinSave" => "funkin.backend.utils.FunkinSave"
|
||||
];
|
||||
|
||||
final events = "funkin.backend.scripting.events.";
|
||||
@@ -146,6 +149,10 @@ class Script extends FlxBasic implements IFlxDestroyable {
|
||||
return redirects;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the default defines for a script.
|
||||
* Includes all of the defines that the build was compiled with.
|
||||
*/
|
||||
public static function getDefaultPreprocessors():Map<String, Dynamic> {
|
||||
var defines = funkin.backend.system.macros.DefinesMacro.defines;
|
||||
defines.set("CODENAME_ENGINE", true);
|
||||
@@ -187,6 +194,10 @@ class Script extends FlxBasic implements IFlxDestroyable {
|
||||
|
||||
private var didLoad:Bool = false;
|
||||
|
||||
/**
|
||||
* Remapped filenames.
|
||||
* Used for trace messages, to show what mod the script is from.
|
||||
*/
|
||||
public var remappedNames:Map<String, String> = [];
|
||||
|
||||
/**
|
||||
@@ -312,7 +323,7 @@ class Script extends FlxBasic implements IFlxDestroyable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the code from a string, doesnt really work after the script has been loaded
|
||||
* Loads the code from a string, doesn't really work after the script has been loaded
|
||||
* @param code The code.
|
||||
*/
|
||||
public function loadFromString(code:String) {
|
||||
@@ -371,7 +382,14 @@ class Script extends FlxBasic implements IFlxDestroyable {
|
||||
private function onCall(func:String, parameters:Array<Dynamic>):Dynamic {
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* Called when the script is created.
|
||||
* @param path Path to the script
|
||||
*/
|
||||
public function onCreate(path:String) {}
|
||||
|
||||
/**
|
||||
* Called when the script is loaded.
|
||||
*/
|
||||
public function onLoad() {}
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package funkin.backend.scripting.events;
|
||||
|
||||
import flixel.FlxState;
|
||||
|
||||
/**
|
||||
* CANCEL this event to prevent default behaviour!
|
||||
*/
|
||||
final class TransitionCreationEvent extends CancellableEvent {
|
||||
/**
|
||||
* If the transition is going out into another state
|
||||
*/
|
||||
public var transOut:Bool;
|
||||
|
||||
/**
|
||||
* The state that is about to be loaded (only on trans out)
|
||||
*/
|
||||
public var newState:FlxState;
|
||||
}
|
||||
@@ -2,11 +2,11 @@ package funkin.backend.scripting.events.menu.freeplay;
|
||||
|
||||
final class FreeplayAlphaUpdateEvent extends CancellableEvent {
|
||||
/**
|
||||
* The alpha when nothing is playing and isnt selected
|
||||
* The alpha when nothing is playing and isn't selected
|
||||
*/
|
||||
public var idleAlpha:Float;
|
||||
/**
|
||||
* The alpha when something is playing and isnt selected
|
||||
* The alpha when something is playing and isn't selected
|
||||
*/
|
||||
public var idlePlayingAlpha:Float;
|
||||
/**
|
||||
|
||||
@@ -86,7 +86,7 @@ final class NoteHitEvent extends CancellableEvent {
|
||||
*/
|
||||
public var healthGain:Float;
|
||||
/**
|
||||
* Rating name. Defaults to "sick", "good", "bad" and "shit". Customisable.
|
||||
* Rating name. Defaults to "sick", "good", "bad" and "shit". Customizable.
|
||||
*/
|
||||
public var rating:String = "sick";
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user