Merge remote-tracking branch 'public/main'

This commit is contained in:
⍚~Nex
2024-09-20 13:09:32 +02:00
3 changed files with 82 additions and 34 deletions
+1 -1
View File
@@ -283,7 +283,7 @@ class Script extends FlxBasic implements IFlxDestroyable {
public function get(variable:String):Dynamic {return null;}
/**
* Gets the variable `variable` from the script's variables.
* Sets the variable `variable` from the script's variables.
* @param variable Name of the variable.
* @return Variable (or null if it doesn't exists)
*/
+9 -1
View File
@@ -242,7 +242,7 @@ class PlayState extends MusicBeatState
/**
* Current stage name
*/
public var curStage:String = "";
public var curStage(get, set):String;
/**
* Interval at which Girlfriend dances.
@@ -525,6 +525,14 @@ class PlayState extends MusicBeatState
return this.maxHealth = v;
}
private inline function get_curStage()
return stage == null ? "" : stage.stageName;
private inline function set_curStage(name:String) {
if (stage != null) stage.stageName = name;
return name;
}
@:dox(hide) override public function create()
{
Note.__customNoteTypeExists = [];
+72 -32
View File
@@ -13,19 +13,22 @@ import haxe.xml.Access;
using StringTools;
class Stage extends FlxBasic implements IBeatReceiver {
public var stageName:String = "";
public var stageXML:Access;
public var stagePath:String;
public var stageSprites:Map<String, FlxSprite> = [];
public var stageScript:Script;
public var state:FlxState;
public var characterPoses:Map<String, StageCharPos> = [];
public var xmlImportedScripts:Map<String, Bool> = [];
public var xmlImportedScripts:Array<XMLImportedScriptInfo> = [];
private var spritesParentFolder = "";
public function getSprite(name:String) {
public function getSprite(name:String)
return stageSprites[name];
}
public function setStagesSprites(script:Script)
for (k=>e in stageSprites) script.set(k, e);
public function new(stage:String, ?state:FlxState) {
super();
@@ -35,11 +38,8 @@ class Stage extends FlxBasic implements IBeatReceiver {
this.state = state;
stagePath = Paths.xml('stages/$stage');
try {
if (Assets.exists(stagePath)) stageXML = new Access(Xml.parse(Assets.getText(stagePath)).firstElement());
} catch(e) {
Logs.trace('Couldn\'t load stage "$stage": ${e.message}', ERROR);
}
try if (Assets.exists(stagePath)) stageXML = new Access(Xml.parse(Assets.getText(stagePath)).firstElement())
catch(e) Logs.trace('Couldn\'t load stage "$stage": ${e.message}', ERROR);
if (PlayState.instance != null) {
stageScript = Script.create(Paths.script('data/stages/$stage'));
@@ -49,12 +49,13 @@ class Stage extends FlxBasic implements IBeatReceiver {
var event = null;
if (stageXML != null) {
stageName = stageXML.getAtt("name").getDefault(stage);
if (PlayState.instance != null) {
var parsed:Null<Float>;
if(stageXML.has.startCamPosX && (parsed = Std.parseFloat(stageXML.att.startCamPosX)) != null) PlayState.instance.camFollow.x = parsed;
if(stageXML.has.startCamPosY && (parsed = Std.parseFloat(stageXML.att.startCamPosY)) != null) PlayState.instance.camFollow.y = parsed;
if(stageXML.has.zoom && (parsed = Std.parseFloat(stageXML.att.zoom)) != null) PlayState.instance.defaultCamZoom = parsed;
PlayState.instance.curStage = stageXML.has.name ? stageXML.att.name : stage;
}
if (stageXML.has.folder) {
spritesParentFolder = stageXML.att.folder;
@@ -63,11 +64,8 @@ class Stage extends FlxBasic implements IBeatReceiver {
var elems = [];
for(node in stageXML.elements) {
if (node.name == "high-memory" && !Options.lowMemoryMode)
for(e in node.elements)
elems.push(e);
else
elems.push(node);
if (node.name == "high-memory" && !Options.lowMemoryMode) for(e in node.elements) __pushNcheckNode(elems, e);
else __pushNcheckNode(elems, node);
}
if (PlayState.instance != null) {
@@ -138,20 +136,7 @@ class Stage extends FlxBasic implements IBeatReceiver {
PlayState.instance.add(PlayState.instance.comboGroup);
PlayState.instance.comboGroup;
case "use-extension" | "extension" | "ext":
if (!node.has.script || PlayState.instance == null) continue;
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 at ${path} does not exist.', ERROR);
else {
xmlImportedScripts.set(path, node.getAtt("isShortLived") == "true");
PlayState.instance.scripts.add(daScript);
daScript.load();
}
if (__shouldLoadBefore(node) || XMLImportedScriptInfo.prepareInfos(node, this) == null) continue;
null;
default: null;
}
@@ -193,15 +178,20 @@ class Stage extends FlxBasic implements IBeatReceiver {
if (PlayState.instance == null) return;
for (k=>e in stageSprites)
stageScript.set(k, e);
setStagesSprites(stageScript);
// i know this for gets run twice under, but its better like this in case a script modifies the short lived ones, i dont wanna save them in an array; more dynamic like this - Nex
for (info in xmlImportedScripts) if (info.importStageSprites) {
var script = info.getScript();
if (script != null) setStagesSprites(script);
}
// idk lemme check anyways just in case scripts did smth - Nex
if (event != null) PlayState.instance.scripts.event("onPostStageCreation", event);
// shortlived scripts destroy when the stage finishes setting up - Nex
for (p=>b in xmlImportedScripts) if (b) {
var script = PlayState.instance.scripts.getByPath(p);
for (info in xmlImportedScripts) if (info.shortLived) {
var script = info.getScript();
if (script == null) continue;
PlayState.instance.scripts.remove(script);
@@ -209,6 +199,15 @@ class Stage extends FlxBasic implements IBeatReceiver {
}
}
@:dox(hide) private function __pushNcheckNode(array:Array<Access>, node:Access) {
array.push(node);
if ((node.name == "use-extension" || node.name == "extension" || node.name == "ext") && __shouldLoadBefore(node))
XMLImportedScriptInfo.prepareInfos(node, this);
}
@: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 {
var charPos = new StageCharPos();
charPos.visible = charPos.active = false;
@@ -318,4 +317,45 @@ typedef StageCharPosInfo = {
var y:Float;
var flip:Bool;
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;
}
}