Improved code for packed events
This commit is contained in:
@@ -45,12 +45,15 @@ class EventsData {
|
||||
if (Path.extension(file) != "json" && Path.extension(file) != "pack") continue;
|
||||
var eventName:String = Path.withoutExtension(Path.withoutDirectory(file));
|
||||
var fileTxt:String = Assets.getText(file);
|
||||
if (fileTxt.trim() == "") continue;
|
||||
|
||||
if (Path.extension(file) == "pack") {
|
||||
eventName = Path.withoutExtension(fileTxt.split("________PACKSEP________")[0]);
|
||||
fileTxt = fileTxt.split("________PACKSEP________")[2];
|
||||
var arr = fileTxt.split("________PACKSEP________");
|
||||
eventName = Path.withoutExtension(arr[0]);
|
||||
fileTxt = arr[2];
|
||||
}
|
||||
|
||||
if (fileTxt.trim() == "") continue;
|
||||
|
||||
eventsList.push(eventName);
|
||||
eventsParams.set(eventName, []);
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ class HScript extends Script {
|
||||
|
||||
interp = new Interp();
|
||||
|
||||
code = Assets.getText(path);
|
||||
code = Assets.exists(path) ? Assets.getText(path) : null;
|
||||
parser = initParser();
|
||||
folderlessPath = Path.directory(path);
|
||||
__importedPaths = [path];
|
||||
|
||||
@@ -109,6 +109,7 @@ class Script extends FlxBasic implements IFlxDestroyable {
|
||||
*/
|
||||
public static var scriptExtensions:Array<String> = [
|
||||
"hx", "hscript", "hsc", "hxs",
|
||||
"pack", // combined file
|
||||
"lua" /** ACTUALLY NOT SUPPORTED, ONLY FOR THE MESSAGE **/
|
||||
];
|
||||
|
||||
@@ -138,6 +139,9 @@ class Script extends FlxBasic implements IFlxDestroyable {
|
||||
return switch(Path.extension(path).toLowerCase()) {
|
||||
case "hx" | "hscript" | "hsc" | "hxs":
|
||||
new HScript(path);
|
||||
case "pack":
|
||||
var arr = Assets.getText(path).split("________PACKSEP________");
|
||||
fromString(arr[1], arr[0]);
|
||||
case "lua":
|
||||
Logs.trace("Lua is not supported in this engine. Use HScript instead.", ERROR);
|
||||
new DummyScript(path);
|
||||
@@ -149,11 +153,12 @@ class Script extends FlxBasic implements IFlxDestroyable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a script from the specified asset path. The language is automatically determined.
|
||||
* @param path Path in assets
|
||||
* Creates a script from the string. The language is determined based on the path.
|
||||
* @param code code
|
||||
* @param path filename
|
||||
*/
|
||||
public static function fromString(code:String, ext:String, path:String):Script {
|
||||
return switch(ext.toLowerCase()) {
|
||||
public static function fromString(code:String, path:String):Script {
|
||||
return switch(Path.extension(path).toLowerCase()) {
|
||||
case "hx" | "hscript" | "hsc" | "hxs":
|
||||
new HScript(path).loadFromString(code);
|
||||
case "lua":
|
||||
|
||||
@@ -577,11 +577,7 @@ class PlayState extends MusicBeatState
|
||||
for (file in Paths.getFolderContent('data/events/', true, fromMods ? MODS : BOTH)) {
|
||||
var fileName:String = Path.withoutExtension(Path.withoutDirectory(file));
|
||||
if (EventsData.eventsList.contains(fileName) && songEvents.contains(fileName)) {
|
||||
if (Path.extension(file) == "pack"){
|
||||
var txtArray:Array<String> = Assets.getText(Paths.pack('events/$fileName')).split("________PACKSEP________");
|
||||
scripts.add(Script.fromString(txtArray[1], Path.extension(txtArray[0]), Path.withoutExtension(txtArray[0])));
|
||||
}
|
||||
else addScript(file);
|
||||
addScript(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user