characters xml events + script extensions too!
Co-Authored-By: Ne_Eo <NeeEoo@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,21 @@
|
|||||||
|
package funkin.backend.scripting.events;
|
||||||
|
|
||||||
|
import funkin.game.Character;
|
||||||
|
import haxe.xml.Access;
|
||||||
|
|
||||||
|
final class CharacterNodeEvent extends CancellableEvent {
|
||||||
|
/**
|
||||||
|
* The character instance
|
||||||
|
*/
|
||||||
|
public var character:Character;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The node which is currently being parsed
|
||||||
|
*/
|
||||||
|
public var node:Access;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The name of the node, quicker access than e.node.name
|
||||||
|
*/
|
||||||
|
public var name:String;
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package funkin.backend.scripting.events;
|
||||||
|
|
||||||
|
import funkin.game.Character;
|
||||||
|
import haxe.xml.Access;
|
||||||
|
|
||||||
|
final class CharacterXMLEvent extends CancellableEvent {
|
||||||
|
/**
|
||||||
|
* The character instance
|
||||||
|
*/
|
||||||
|
public var character:Character;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The xml
|
||||||
|
*/
|
||||||
|
public var xml:Access;
|
||||||
|
}
|
||||||
@@ -62,6 +62,7 @@ class AudioSwitchFix {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@:dox(hide)
|
||||||
typedef PlayingSound = {
|
typedef PlayingSound = {
|
||||||
var sound:FlxSound;
|
var sound:FlxSound;
|
||||||
var time:Float;
|
var time:Float;
|
||||||
|
|||||||
@@ -6,6 +6,9 @@ import funkin.backend.system.ErrorCode;
|
|||||||
import funkin.backend.FunkinSprite.XMLAnimType;
|
import funkin.backend.FunkinSprite.XMLAnimType;
|
||||||
import flixel.util.FlxColor;
|
import flixel.util.FlxColor;
|
||||||
import haxe.xml.Access;
|
import haxe.xml.Access;
|
||||||
|
import funkin.backend.scripting.Script;
|
||||||
|
import funkin.backend.scripting.DummyScript;
|
||||||
|
import funkin.backend.scripting.ScriptPack;
|
||||||
import flixel.util.typeLimit.OneOfTwo;
|
import flixel.util.typeLimit.OneOfTwo;
|
||||||
import funkin.backend.system.interfaces.IOffsetCompatible;
|
import funkin.backend.system.interfaces.IOffsetCompatible;
|
||||||
|
|
||||||
@@ -326,6 +329,51 @@ class XMLUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class XMLImportedScriptInfo {
|
||||||
|
public var path:String;
|
||||||
|
public var shortLived:Bool = false;
|
||||||
|
public var loadBefore:Bool = true;
|
||||||
|
public var importStageSprites:Bool = false; // maybe will change later?? - Nex
|
||||||
|
public var parentScriptPack:ScriptPack = null;
|
||||||
|
|
||||||
|
public function new(path:String, parentScriptPack:ScriptPack) {
|
||||||
|
this.parentScriptPack = parentScriptPack;
|
||||||
|
this.path = path;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getScript():Script
|
||||||
|
return parentScriptPack == null ? null : parentScriptPack.getByPath(path);
|
||||||
|
|
||||||
|
public static function prepareInfos(node:Access, parentScriptPack:ScriptPack, ?onScriptPreLoad:XMLImportedScriptInfo->Void):XMLImportedScriptInfo {
|
||||||
|
if (!node.has.script || parentScriptPack == null) return null;
|
||||||
|
|
||||||
|
var folder = node.getAtt("folder").getDefault("data/scripts/");
|
||||||
|
if (!folder.endsWith("/")) folder += "/";
|
||||||
|
|
||||||
|
var path = Paths.script(folder + node.getAtt("script"));
|
||||||
|
var daScript = Script.create(path);
|
||||||
|
if (daScript is DummyScript) {
|
||||||
|
Logs.trace('Script Extension at ${path} does not exist.', ERROR);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
var infos = new XMLImportedScriptInfo(daScript.path, parentScriptPack);
|
||||||
|
infos.shortLived = node.getAtt("isShortLived") == "true" || node.getAtt("shortLived") == "true";
|
||||||
|
infos.importStageSprites = node.getAtt("importStageSprites") == "true";
|
||||||
|
@:privateAccess infos.loadBefore = shouldLoadBefore(node);
|
||||||
|
|
||||||
|
if (onScriptPreLoad != null) onScriptPreLoad(infos);
|
||||||
|
parentScriptPack.add(daScript);
|
||||||
|
daScript.set("scriptInfo", infos);
|
||||||
|
daScript.load();
|
||||||
|
|
||||||
|
return infos;
|
||||||
|
}
|
||||||
|
|
||||||
|
@:dox(hide) public static inline function shouldLoadBefore(node:Access):Bool
|
||||||
|
return node.getAtt("loadBefore") != "false";
|
||||||
|
}
|
||||||
|
|
||||||
typedef AnimData = {
|
typedef AnimData = {
|
||||||
var name:String;
|
var name:String;
|
||||||
var anim:String;
|
var anim:String;
|
||||||
|
|||||||
@@ -8,6 +8,9 @@ import flixel.util.FlxColor;
|
|||||||
import funkin.backend.FunkinSprite;
|
import funkin.backend.FunkinSprite;
|
||||||
import funkin.backend.scripting.DummyScript;
|
import funkin.backend.scripting.DummyScript;
|
||||||
import funkin.backend.scripting.Script;
|
import funkin.backend.scripting.Script;
|
||||||
|
import funkin.backend.scripting.ScriptPack;
|
||||||
|
import funkin.backend.scripting.events.CharacterNodeEvent;
|
||||||
|
import funkin.backend.scripting.events.CharacterXMLEvent;
|
||||||
import funkin.backend.scripting.events.DanceEvent;
|
import funkin.backend.scripting.events.DanceEvent;
|
||||||
import funkin.backend.scripting.events.DirectionAnimEvent;
|
import funkin.backend.scripting.events.DirectionAnimEvent;
|
||||||
import funkin.backend.scripting.events.PlayAnimEvent;
|
import funkin.backend.scripting.events.PlayAnimEvent;
|
||||||
@@ -44,8 +47,22 @@ class Character extends FunkinSprite implements IBeatReceiver implements IOffset
|
|||||||
public var cameraOffset:FlxPoint = FlxPoint.get(0, 0);
|
public var cameraOffset:FlxPoint = FlxPoint.get(0, 0);
|
||||||
public var globalOffset:FlxPoint = FlxPoint.get(0, 0);
|
public var globalOffset:FlxPoint = FlxPoint.get(0, 0);
|
||||||
|
|
||||||
public var script:Script;
|
|
||||||
public var xml:Access;
|
public var xml:Access;
|
||||||
|
public var scripts:ScriptPack;
|
||||||
|
public var xmlImportedScripts:Array<XMLImportedScriptInfo> = [];
|
||||||
|
public var script(default, set):Script;
|
||||||
|
|
||||||
|
public function prepareInfos(node:Access)
|
||||||
|
return XMLImportedScriptInfo.prepareInfos(node, scripts, (infos) -> xmlImportedScripts.push(infos));
|
||||||
|
|
||||||
|
// backward compat - Nex
|
||||||
|
private function set_script(script:Script):Script {
|
||||||
|
if (scripts == null) (scripts = new ScriptPack("Character")).setParent(this);
|
||||||
|
else scripts.remove(scripts.scripts[0]);
|
||||||
|
if(script != null) scripts.insert(0, script);
|
||||||
|
this.script = script;
|
||||||
|
return script;
|
||||||
|
}
|
||||||
|
|
||||||
public var idleSuffix:String = "";
|
public var idleSuffix:String = "";
|
||||||
public var stunned(default, set):Bool = false;
|
public var stunned(default, set):Bool = false;
|
||||||
@@ -71,16 +88,15 @@ class Character extends FunkinSprite implements IBeatReceiver implements IOffset
|
|||||||
script = Script.create(Paths.script(Path.withoutExtension(Paths.xml('characters/$curCharacter')), null, true));
|
script = Script.create(Paths.script(Path.withoutExtension(Paths.xml('characters/$curCharacter')), null, true));
|
||||||
else
|
else
|
||||||
script = new DummyScript(curCharacter);
|
script = new DummyScript(curCharacter);
|
||||||
script.setParent(this);
|
|
||||||
script.load();
|
script.load();
|
||||||
|
|
||||||
buildCharacter(xml);
|
buildCharacter(xml);
|
||||||
script.call("create");
|
scripts.call("create");
|
||||||
|
|
||||||
if (script == null)
|
if (script == null)
|
||||||
script = new DummyScript(curCharacter);
|
script = new DummyScript(curCharacter);
|
||||||
|
|
||||||
script.call("postCreate");
|
scripts.call("postCreate");
|
||||||
}
|
}
|
||||||
|
|
||||||
@:noCompletion var __swappedLeftRightAnims:Bool = false;
|
@:noCompletion var __swappedLeftRightAnims:Bool = false;
|
||||||
@@ -92,9 +108,9 @@ class Character extends FunkinSprite implements IBeatReceiver implements IOffset
|
|||||||
__autoInterval = autoInterval;
|
__autoInterval = autoInterval;
|
||||||
|
|
||||||
// character is flipped
|
// character is flipped
|
||||||
if (isPlayer != playerOffsets && switchAnims)
|
if (isPlayer != playerOffsets && switchAnims)
|
||||||
swapLeftRightAnimations();
|
swapLeftRightAnimations();
|
||||||
|
|
||||||
frameOffset.set(getAnimOffset(getAnimName()).x, getAnimOffset(getAnimName()).y);
|
frameOffset.set(getAnimOffset(getAnimName()).x, getAnimOffset(getAnimName()).y);
|
||||||
if (isPlayer) flipX = !flipX;
|
if (isPlayer) flipX = !flipX;
|
||||||
__baseFlipped = flipX;
|
__baseFlipped = flipX;
|
||||||
@@ -115,7 +131,7 @@ class Character extends FunkinSprite implements IBeatReceiver implements IOffset
|
|||||||
|
|
||||||
override function update(elapsed:Float) {
|
override function update(elapsed:Float) {
|
||||||
super.update(elapsed);
|
super.update(elapsed);
|
||||||
script.call("update", [elapsed]);
|
scripts.call("update", [elapsed]);
|
||||||
if (stunned) {
|
if (stunned) {
|
||||||
__stunnedTime += elapsed;
|
__stunnedTime += elapsed;
|
||||||
if (__stunnedTime > 5 / 60)
|
if (__stunnedTime > 5 / 60)
|
||||||
@@ -134,7 +150,7 @@ class Character extends FunkinSprite implements IBeatReceiver implements IOffset
|
|||||||
if(debugMode) return;
|
if(debugMode) return;
|
||||||
|
|
||||||
var event = EventManager.get(DanceEvent).recycle(danced);
|
var event = EventManager.get(DanceEvent).recycle(danced);
|
||||||
script.call("onDance", [event]);
|
scripts.call("onDance", [event]);
|
||||||
if (event.cancelled) return;
|
if (event.cancelled) return;
|
||||||
|
|
||||||
if (isDanceLeftDanceRight)
|
if (isDanceLeftDanceRight)
|
||||||
@@ -164,14 +180,14 @@ class Character extends FunkinSprite implements IBeatReceiver implements IOffset
|
|||||||
*/
|
*/
|
||||||
public var danceOnBeat:Bool = true;
|
public var danceOnBeat:Bool = true;
|
||||||
public override function beatHit(curBeat:Int) {
|
public override function beatHit(curBeat:Int) {
|
||||||
script.call("beatHit", [curBeat]);
|
scripts.call("beatHit", [curBeat]);
|
||||||
|
|
||||||
if (danceOnBeat && (curBeat + beatOffset) % beatInterval == 0 && !__lockAnimThisFrame)
|
if (danceOnBeat && (curBeat + beatOffset) % beatInterval == 0 && !__lockAnimThisFrame)
|
||||||
tryDance();
|
tryDance();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override function stepHit(curStep:Int)
|
public override function stepHit(curStep:Int)
|
||||||
script.call("stepHit", [curStep]);
|
scripts.call("stepHit", [curStep]);
|
||||||
|
|
||||||
@:noCompletion var __reverseDrawProcedure:Bool = false;
|
@:noCompletion var __reverseDrawProcedure:Bool = false;
|
||||||
public override function getScreenBounds(?newRect:FlxRect, ?camera:FlxCamera):FlxRect {
|
public override function getScreenBounds(?newRect:FlxRect, ?camera:FlxCamera):FlxRect {
|
||||||
@@ -209,14 +225,14 @@ class Character extends FunkinSprite implements IBeatReceiver implements IOffset
|
|||||||
public var singAnims = ["singLEFT", "singDOWN", "singUP", "singRIGHT"];
|
public var singAnims = ["singLEFT", "singDOWN", "singUP", "singRIGHT"];
|
||||||
public function playSingAnim(direction:Int, suffix:String = "", Context:PlayAnimContext = SING, ?Force:Null<Bool> = null, Reversed:Bool = false, Frame:Int = 0) {
|
public function playSingAnim(direction:Int, suffix:String = "", Context:PlayAnimContext = SING, ?Force:Null<Bool> = null, Reversed:Bool = false, Frame:Int = 0) {
|
||||||
var event = EventManager.get(DirectionAnimEvent).recycle(singAnims[direction % singAnims.length] + suffix, direction, suffix, Context, Reversed, Frame, Force);
|
var event = EventManager.get(DirectionAnimEvent).recycle(singAnims[direction % singAnims.length] + suffix, direction, suffix, Context, Reversed, Frame, Force);
|
||||||
script.call("onPlaySingAnim", [event]);
|
scripts.call("onPlaySingAnim", [event]);
|
||||||
if (!event.cancelled)
|
if (!event.cancelled)
|
||||||
playAnim(event.animName, event.force, event.context, event.reversed, event.frame);
|
playAnim(event.animName, event.force, event.context, event.reversed, event.frame);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override function playAnim(AnimName:String, ?Force:Bool, Context:PlayAnimContext = NONE, Reversed:Bool = false, Frame:Int = 0) {
|
public override function playAnim(AnimName:String, ?Force:Bool, Context:PlayAnimContext = NONE, Reversed:Bool = false, Frame:Int = 0) {
|
||||||
var event = EventManager.get(PlayAnimEvent).recycle(AnimName, Force, Reversed, Frame, Context);
|
var event = EventManager.get(PlayAnimEvent).recycle(AnimName, Force, Reversed, Frame, Context);
|
||||||
script.call("onPlayAnim", [event]);
|
scripts.call("onPlayAnim", [event]);
|
||||||
if (event.cancelled) return;
|
if (event.cancelled) return;
|
||||||
|
|
||||||
super.playAnim(event.animName, event.force, event.context, event.reverse, event.startingFrame);
|
super.playAnim(event.animName, event.force, event.context, event.reverse, event.startingFrame);
|
||||||
@@ -231,15 +247,15 @@ class Character extends FunkinSprite implements IBeatReceiver implements IOffset
|
|||||||
var event = EventManager.get(PointEvent).recycle(
|
var event = EventManager.get(PointEvent).recycle(
|
||||||
midpoint.x + (isPlayer ? -100 : 150) + globalOffset.x + cameraOffset.x,
|
midpoint.x + (isPlayer ? -100 : 150) + globalOffset.x + cameraOffset.x,
|
||||||
midpoint.y - 100 + globalOffset.y + cameraOffset.y);
|
midpoint.y - 100 + globalOffset.y + cameraOffset.y);
|
||||||
script.call("onGetCamPos", [event]);
|
scripts.call("onGetCamPos", [event]);
|
||||||
|
|
||||||
midpoint.put();
|
midpoint.put();
|
||||||
return new FlxPoint(event.x, event.y);
|
return new FlxPoint(event.x, event.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override function destroy() {
|
public override function destroy() {
|
||||||
script.call('destroy');
|
scripts.call('destroy');
|
||||||
script.destroy();
|
scripts.destroy();
|
||||||
super.destroy();
|
super.destroy();
|
||||||
|
|
||||||
cameraOffset.put();
|
cameraOffset.put();
|
||||||
@@ -281,9 +297,18 @@ class Character extends FunkinSprite implements IBeatReceiver implements IOffset
|
|||||||
}
|
}
|
||||||
|
|
||||||
public inline function buildCharacter(xml:Access) {
|
public inline function buildCharacter(xml:Access) {
|
||||||
this.xml = xml; // Modders wassup :D
|
for(node in xml.elements)
|
||||||
|
switch(node.name) {
|
||||||
|
case "use-extension" | "extension" | "ext":
|
||||||
|
if (!XMLImportedScriptInfo.shouldLoadBefore(node)) continue;
|
||||||
|
prepareInfos(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
xml = scripts.event("onCharacterXMLParsed", EventManager.get(CharacterXMLEvent).recycle(this, xml)).xml;
|
||||||
|
|
||||||
sprite = curCharacter;
|
sprite = curCharacter;
|
||||||
spriteAnimType = BEAT;
|
spriteAnimType = BEAT;
|
||||||
|
this.xml = xml; // Modders wassup :D
|
||||||
|
|
||||||
if (xml.x.exists("isPlayer")) playerOffsets = (xml.x.get("isPlayer") == "true");
|
if (xml.x.exists("isPlayer")) playerOffsets = (xml.x.get("isPlayer") == "true");
|
||||||
if (xml.x.exists("x")) globalOffset.x = Std.parseFloat(xml.x.get("x"));
|
if (xml.x.exists("x")) globalOffset.x = Std.parseFloat(xml.x.get("x"));
|
||||||
@@ -307,9 +332,19 @@ class Character extends FunkinSprite implements IBeatReceiver implements IOffset
|
|||||||
if (hasInterval) beatInterval = Std.parseInt(xml.x.get("interval"));
|
if (hasInterval) beatInterval = Std.parseInt(xml.x.get("interval"));
|
||||||
|
|
||||||
loadSprite(Paths.image('characters/$sprite'));
|
loadSprite(Paths.image('characters/$sprite'));
|
||||||
|
for(node in xml.elements) {
|
||||||
|
switch(node.name) {
|
||||||
|
case "anim":
|
||||||
|
XMLUtil.addXMLAnimation(this, node);
|
||||||
|
case "use-extension" | "extension" | "ext":
|
||||||
|
if (XMLImportedScriptInfo.shouldLoadBefore(node)) continue;
|
||||||
|
prepareInfos(node);
|
||||||
|
default:
|
||||||
|
// nothing
|
||||||
|
}
|
||||||
|
|
||||||
for (anim in xml.nodes.anim)
|
scripts.event("onCharacterNodeParsed", EventManager.get(CharacterNodeEvent).recycle(this, node, node.name));
|
||||||
XMLUtil.addXMLAnimation(this, anim);
|
}
|
||||||
|
|
||||||
for (attribute in xml.x.attributes())
|
for (attribute in xml.x.attributes())
|
||||||
if (!characterProperties.contains(attribute))
|
if (!characterProperties.contains(attribute))
|
||||||
@@ -317,11 +352,19 @@ class Character extends FunkinSprite implements IBeatReceiver implements IOffset
|
|||||||
|
|
||||||
fixChar(__switchAnims, !hasInterval);
|
fixChar(__switchAnims, !hasInterval);
|
||||||
dance();
|
dance();
|
||||||
|
|
||||||
|
for (info in xmlImportedScripts) if (info.shortLived) {
|
||||||
|
var script = info.getScript();
|
||||||
|
if (script == null) continue;
|
||||||
|
|
||||||
|
scripts.remove(script);
|
||||||
|
script.destroy();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static var characterProperties:Array<String> = [
|
public static var characterProperties:Array<String> = [
|
||||||
"x", "y", "sprite", "scale", "antialiasing",
|
"x", "y", "sprite", "scale", "antialiasing",
|
||||||
"flipX", "camx", "camy", "isPlayer", "icon",
|
"flipX", "camx", "camy", "isPlayer", "icon",
|
||||||
"color", "gameOverChar", "holdTime"
|
"color", "gameOverChar", "holdTime"
|
||||||
];
|
];
|
||||||
public static var characterAnimProperties:Array<String> = [
|
public static var characterAnimProperties:Array<String> = [
|
||||||
@@ -331,7 +374,7 @@ class Character extends FunkinSprite implements IBeatReceiver implements IOffset
|
|||||||
public inline function buildXML(?animsOrder:Array<String>):Xml {
|
public inline function buildXML(?animsOrder:Array<String>):Xml {
|
||||||
var xml:Xml = Xml.createElement("character");
|
var xml:Xml = Xml.createElement("character");
|
||||||
xml.attributeOrder = characterProperties.copy();
|
xml.attributeOrder = characterProperties.copy();
|
||||||
|
|
||||||
if (globalOffset.x != 0) xml.set("x", Std.string(FlxMath.roundDecimal(globalOffset.x, 2)));
|
if (globalOffset.x != 0) xml.set("x", Std.string(FlxMath.roundDecimal(globalOffset.x, 2)));
|
||||||
if (globalOffset.y != 0) xml.set("y", Std.string(FlxMath.roundDecimal(globalOffset.y, 2)));
|
if (globalOffset.y != 0) xml.set("y", Std.string(FlxMath.roundDecimal(globalOffset.y, 2)));
|
||||||
|
|
||||||
@@ -436,7 +479,7 @@ class Character extends FunkinSprite implements IBeatReceiver implements IOffset
|
|||||||
Logs.trace('Error while loading character ${character}: ${e}', ERROR);
|
Logs.trace('Error while loading character ${character}: ${e}', ERROR);
|
||||||
|
|
||||||
character = FALLBACK_CHARACTER;
|
character = FALLBACK_CHARACTER;
|
||||||
if (char != null)
|
if (char != null)
|
||||||
char.curCharacter = character;
|
char.curCharacter = character;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import funkin.backend.scripting.events.StageNodeEvent;
|
|||||||
import flixel.math.FlxPoint;
|
import flixel.math.FlxPoint;
|
||||||
import flixel.FlxState;
|
import flixel.FlxState;
|
||||||
import haxe.xml.Access;
|
import haxe.xml.Access;
|
||||||
|
import funkin.backend.utils.XMLUtil.XMLImportedScriptInfo;
|
||||||
import funkin.backend.system.interfaces.IBeatReceiver;
|
import funkin.backend.system.interfaces.IBeatReceiver;
|
||||||
import funkin.backend.scripting.DummyScript;
|
import funkin.backend.scripting.DummyScript;
|
||||||
import funkin.backend.scripting.Script;
|
import funkin.backend.scripting.Script;
|
||||||
@@ -30,6 +31,9 @@ class Stage extends FlxBasic implements IBeatReceiver {
|
|||||||
public function setStagesSprites(script:Script)
|
public function setStagesSprites(script:Script)
|
||||||
for (k=>e in stageSprites) script.set(k, e);
|
for (k=>e in stageSprites) script.set(k, e);
|
||||||
|
|
||||||
|
public function prepareInfos(node:Access)
|
||||||
|
return XMLImportedScriptInfo.prepareInfos(node, PlayState.instance.scripts, (infos) -> xmlImportedScripts.push(infos));
|
||||||
|
|
||||||
public function new(stage:String, ?state:FlxState) {
|
public function new(stage:String, ?state:FlxState) {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
@@ -136,7 +140,7 @@ class Stage extends FlxBasic implements IBeatReceiver {
|
|||||||
PlayState.instance.add(PlayState.instance.comboGroup);
|
PlayState.instance.add(PlayState.instance.comboGroup);
|
||||||
PlayState.instance.comboGroup;
|
PlayState.instance.comboGroup;
|
||||||
case "use-extension" | "extension" | "ext":
|
case "use-extension" | "extension" | "ext":
|
||||||
if (__shouldLoadBefore(node) || XMLImportedScriptInfo.prepareInfos(node, this) == null) continue;
|
if (XMLImportedScriptInfo.shouldLoadBefore(node) || prepareInfos(node) == null) continue;
|
||||||
null;
|
null;
|
||||||
default: null;
|
default: null;
|
||||||
}
|
}
|
||||||
@@ -201,13 +205,10 @@ class Stage extends FlxBasic implements IBeatReceiver {
|
|||||||
|
|
||||||
@:dox(hide) private function __pushNcheckNode(array:Array<Access>, node:Access) {
|
@:dox(hide) private function __pushNcheckNode(array:Array<Access>, node:Access) {
|
||||||
array.push(node);
|
array.push(node);
|
||||||
if ((node.name == "use-extension" || node.name == "extension" || node.name == "ext") && __shouldLoadBefore(node))
|
if ((node.name == "use-extension" || node.name == "extension" || node.name == "ext") && XMLImportedScriptInfo.shouldLoadBefore(node))
|
||||||
XMLImportedScriptInfo.prepareInfos(node, this);
|
prepareInfos(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
@:dox(hide) private static inline function __shouldLoadBefore(node:Access):Bool
|
|
||||||
return node.getAtt("loadBefore") != "false";
|
|
||||||
|
|
||||||
public function addCharPos(name:String, node:Access, ?nonXMLInfo:StageCharPosInfo):StageCharPos {
|
public function addCharPos(name:String, node:Access, ?nonXMLInfo:StageCharPosInfo):StageCharPos {
|
||||||
var charPos = new StageCharPos();
|
var charPos = new StageCharPos();
|
||||||
charPos.visible = charPos.active = false;
|
charPos.visible = charPos.active = false;
|
||||||
@@ -317,45 +318,4 @@ typedef StageCharPosInfo = {
|
|||||||
var y:Float;
|
var y:Float;
|
||||||
var flip:Bool;
|
var flip:Bool;
|
||||||
var scroll:Float;
|
var scroll:Float;
|
||||||
}
|
|
||||||
|
|
||||||
class XMLImportedScriptInfo {
|
|
||||||
public var path:String;
|
|
||||||
public var shortLived:Bool = false;
|
|
||||||
public var loadBefore:Bool = true;
|
|
||||||
public var importStageSprites:Bool = false;
|
|
||||||
|
|
||||||
public function new(path:String)
|
|
||||||
this.path = path;
|
|
||||||
|
|
||||||
public function getScript():Script
|
|
||||||
return PlayState.instance == null ? null : PlayState.instance.scripts.getByPath(path);
|
|
||||||
|
|
||||||
public static function prepareInfos(node:Access, ?stage:Stage):XMLImportedScriptInfo {
|
|
||||||
if (!node.has.script || PlayState.instance == null) return null;
|
|
||||||
|
|
||||||
var folder = node.getAtt("folder").getDefault("data/scripts/");
|
|
||||||
if (!folder.endsWith("/")) folder += "/";
|
|
||||||
|
|
||||||
var path = Paths.script(folder + node.getAtt("script"));
|
|
||||||
var daScript = Script.create(path);
|
|
||||||
if (daScript is DummyScript) {
|
|
||||||
var msg = 'Script Extension at ${path} does not exist';
|
|
||||||
if (stage != null) msg += ' through stage "${stage.stageName}"';
|
|
||||||
Logs.trace(msg + ".", ERROR);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
var infos = new XMLImportedScriptInfo(daScript.path);
|
|
||||||
infos.shortLived = node.getAtt("isShortLived") == "true";
|
|
||||||
infos.importStageSprites = node.getAtt("importStageSprites") == "true";
|
|
||||||
@:privateAccess infos.loadBefore = Stage.__shouldLoadBefore(node);
|
|
||||||
|
|
||||||
if (stage != null) stage.xmlImportedScripts.push(infos);
|
|
||||||
PlayState.instance.scripts.add(daScript);
|
|
||||||
daScript.set("scriptInfo", infos);
|
|
||||||
daScript.load();
|
|
||||||
|
|
||||||
return infos;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user