Merge branch 'main' of https://github.com/FNF-CNE-Devs/CodenameEngine-Dev
This commit is contained in:
@@ -123,7 +123,7 @@ class MusicBeatState extends FlxState implements IBeatReceiver
|
||||
var path = Paths.script('data/states/${scriptName}/LIB_$i');
|
||||
var script = Script.create(path);
|
||||
if (script is DummyScript) continue;
|
||||
script.fileName = '$i:$scriptName';
|
||||
script.remappedNames.set(script.fileName, '$i:${script.fileName}');
|
||||
stateScripts.add(script);
|
||||
script.load();
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@ class MusicBeatSubstate extends FlxSubState implements IBeatReceiver
|
||||
var path = Paths.script('data/states/${scriptName}/LIB_$i');
|
||||
var script = Script.create(path);
|
||||
if (script is DummyScript) continue;
|
||||
script.fileName = '$i:$scriptName';
|
||||
script.remappedNames.set(script.fileName, '$i:${script.fileName}');
|
||||
stateScripts.add(script);
|
||||
script.load();
|
||||
}
|
||||
|
||||
@@ -6,9 +6,6 @@ import lime.utils.AssetLibrary;
|
||||
class AssetsLibraryList extends AssetLibrary {
|
||||
public var libraries:Array<AssetLibrary> = [];
|
||||
|
||||
public var rootLibs:Array<AssetLibrary> = [];
|
||||
public var assetsLibs:Array<AssetLibrary> = [];
|
||||
|
||||
@:allow(funkin.backend.system.Main)
|
||||
@:allow(funkin.backend.system.MainState)
|
||||
private var __defaultLibraries:Array<AssetLibrary> = [];
|
||||
@@ -19,7 +16,6 @@ class AssetsLibraryList extends AssetLibrary {
|
||||
libraries.remove(lib);
|
||||
return lib;
|
||||
}
|
||||
|
||||
public function existsSpecific(id:String, type:String, source:AssetSource = BOTH) {
|
||||
if (!id.startsWith("assets/") && exists('assets/$id', type))
|
||||
return true;
|
||||
@@ -98,29 +94,23 @@ class AssetsLibraryList extends AssetLibrary {
|
||||
return content;
|
||||
}
|
||||
|
||||
public function getSpecificAsset(id:String, type:String, source:AssetSource = BOTH, ?avoidRoot:Bool = false):Dynamic {
|
||||
public function getSpecificAsset(id:String, type:String, source:AssetSource = BOTH):Dynamic {
|
||||
try {
|
||||
if (!id.startsWith("assets/")) {
|
||||
var ass = getSpecificAsset('assets/$id', type, source);
|
||||
if (ass != null)
|
||||
if (ass != null) {
|
||||
return ass;
|
||||
} else {
|
||||
for (lib in assetsLibs) {
|
||||
if (shouldSkipLib(libraries.indexOf(lib), source)) continue;
|
||||
|
||||
var asset = lib.getAsset(id, type);
|
||||
if (asset != null)
|
||||
return asset;
|
||||
}
|
||||
}
|
||||
for(k=>e in libraries) {
|
||||
if (shouldSkipLib(k, source)) continue;
|
||||
|
||||
if (!avoidRoot) {
|
||||
for (lib in rootLibs) {
|
||||
if (shouldSkipLib(libraries.indexOf(lib), source)) continue;
|
||||
|
||||
var asset = lib.getAsset(id, type);
|
||||
if (asset != null)
|
||||
@:privateAccess
|
||||
if (e.exists(id, e.types.get(id))) {
|
||||
var asset = e.getAsset(id, type);
|
||||
if (asset != null) {
|
||||
return asset;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
@@ -140,9 +130,6 @@ class AssetsLibraryList extends AssetLibrary {
|
||||
public override inline function getAsset(id:String, type:String):Dynamic
|
||||
return getSpecificAsset(id, type, BOTH);
|
||||
|
||||
public inline function getAssetSafe(id:String, type:String):Dynamic
|
||||
return getSpecificAsset(id, type, BOTH, true);
|
||||
|
||||
public override function isLocal(id:String, type:String) {
|
||||
return true;
|
||||
}
|
||||
@@ -171,17 +158,8 @@ class AssetsLibraryList extends AssetLibrary {
|
||||
addLibrary(d);
|
||||
}
|
||||
|
||||
public function addLibrary(lib:AssetLibrary) @:privateAccess {
|
||||
public function addLibrary(lib:AssetLibrary) {
|
||||
libraries.insert(0, lib);
|
||||
|
||||
var finalLib:AssetLibrary = lib;
|
||||
if (finalLib is openfl.utils.AssetLibrary)
|
||||
finalLib = cast(finalLib, openfl.utils.AssetLibrary).__proxy;
|
||||
|
||||
if (finalLib is IModsAssetLibrary)
|
||||
assetsLibs.insert(0, finalLib);
|
||||
else
|
||||
rootLibs.insert(0, finalLib);
|
||||
return lib;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -302,6 +302,23 @@ class Paths
|
||||
return content;
|
||||
*/
|
||||
}
|
||||
|
||||
// Used in Script.hx
|
||||
@:noCompletion public static function getFilenameFromLibFile(path:String) {
|
||||
var file = new haxe.io.Path(path);
|
||||
if(file.file.startsWith("LIB_")) {
|
||||
return file.dir + "." + file.ext;
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
@:noCompletion public static function getLibFromLibFile(path:String) {
|
||||
var file = new haxe.io.Path(path);
|
||||
if(file.file.startsWith("LIB_")) {
|
||||
return file.file.substr(4);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
class ScriptPathInfo {
|
||||
|
||||
@@ -94,7 +94,7 @@ class GlobalScript {
|
||||
var path = Paths.script('data/global/LIB_$i');
|
||||
var script = Script.create(path);
|
||||
if (script is DummyScript) continue;
|
||||
script.fileName = '$i:global.hx';
|
||||
script.remappedNames.set(script.fileName, '$i:${script.fileName}');
|
||||
scripts.add(script);
|
||||
script.load();
|
||||
}
|
||||
|
||||
@@ -1,21 +1,17 @@
|
||||
package funkin.backend.scripting;
|
||||
|
||||
import haxe.io.Path;
|
||||
import hscript.Expr.ClassDecl;
|
||||
import hscript.Expr.ModuleDecl;
|
||||
import hscript.Expr.Error;
|
||||
import hscript.Parser;
|
||||
import openfl.Assets;
|
||||
import lime.utils.AssetType;
|
||||
import hscript.*;
|
||||
|
||||
class HScript extends Script {
|
||||
public var interp:Interp;
|
||||
public var parser:Parser;
|
||||
public var expr:Expr;
|
||||
public var decls:Array<ModuleDecl> = null;
|
||||
public var code:String;
|
||||
public var folderlessPath:String;
|
||||
public var code:String = null;
|
||||
//public var folderlessPath:String;
|
||||
var __importedPaths:Array<String>;
|
||||
|
||||
public static function initParser() {
|
||||
@@ -30,10 +26,12 @@ class HScript extends Script {
|
||||
|
||||
interp = new Interp();
|
||||
|
||||
// We use getAssetSafe to prevent crash from empty file (null which would check root (big crash)) -lunar
|
||||
code = Assets.exists(path) ? Paths.assetsTree.getAssetSafe(path, TEXT) : null;
|
||||
try {
|
||||
if(Assets.exists(rawPath)) code = Assets.getText(rawPath);
|
||||
} catch(e) Logs.trace('Error while reading $path: ${Std.string(e)}', ERROR);
|
||||
|
||||
parser = initParser();
|
||||
folderlessPath = Path.directory(path);
|
||||
//folderlessPath = Path.directory(path);
|
||||
__importedPaths = [path];
|
||||
|
||||
interp.errorHandler = _errorHandler;
|
||||
@@ -48,14 +46,13 @@ class HScript extends Script {
|
||||
}));
|
||||
|
||||
funkin.backend.scripting.GlobalScript.call("onScriptCreated", [this, "hscript"]);
|
||||
|
||||
if (code != null && code.trim() != "")
|
||||
loadFromString(code);
|
||||
loadFromString(code);
|
||||
}
|
||||
|
||||
public override function loadFromString(code:String) {
|
||||
try {
|
||||
expr = parser.parseString(code, fileName);
|
||||
if (code != null && code.trim() != "")
|
||||
expr = parser.parseString(code, fileName);
|
||||
} catch(e:Error) {
|
||||
_errorHandler(e);
|
||||
} catch(e) {
|
||||
@@ -94,7 +91,9 @@ class HScript extends Script {
|
||||
}
|
||||
|
||||
private function _errorHandler(error:Error) {
|
||||
|
||||
var fileName = error.origin;
|
||||
if(remappedNames.exists(fileName))
|
||||
fileName = remappedNames.get(fileName);
|
||||
var fn = '$fileName:${error.line}: ';
|
||||
var err = error.toString();
|
||||
if (err.startsWith(fn)) err = err.substr(fn.length);
|
||||
|
||||
@@ -124,13 +124,22 @@ class Script extends FlxBasic implements IFlxDestroyable {
|
||||
*/
|
||||
public var fileName:String;
|
||||
|
||||
/**
|
||||
* Script Extension
|
||||
*/
|
||||
public var extension:String;
|
||||
|
||||
/**
|
||||
* Path to the script.
|
||||
*/
|
||||
public var path:String = null;
|
||||
|
||||
private var rawPath:String = null;
|
||||
|
||||
private var didLoad:Bool = false;
|
||||
|
||||
public var remappedNames:Map<String, String> = [];
|
||||
|
||||
/**
|
||||
* Creates a script from the specified asset path. The language is automatically determined.
|
||||
* @param path Path in assets
|
||||
@@ -177,7 +186,11 @@ class Script extends FlxBasic implements IFlxDestroyable {
|
||||
public function new(path:String) {
|
||||
super();
|
||||
|
||||
rawPath = path;
|
||||
path = Paths.getFilenameFromLibFile(path);
|
||||
|
||||
fileName = Path.withoutDirectory(path);
|
||||
extension = Path.extension(path);
|
||||
this.path = path;
|
||||
onCreate(path);
|
||||
for(k=>e in getDefaultVariables(this)) {
|
||||
@@ -223,6 +236,9 @@ class Script extends FlxBasic implements IFlxDestroyable {
|
||||
* Traces something as this script.
|
||||
*/
|
||||
public function trace(v:Dynamic) {
|
||||
var fileName = this.fileName;
|
||||
if(remappedNames.exists(fileName))
|
||||
fileName = remappedNames.get(fileName);
|
||||
Logs.traceColored([
|
||||
Logs.logText('${fileName}: ', GREEN),
|
||||
Logs.logText(Std.string(v))
|
||||
@@ -280,6 +296,9 @@ class Script extends FlxBasic implements IFlxDestroyable {
|
||||
* @param additionalInfo Additional information you could provide.
|
||||
*/
|
||||
public function error(text:String, ?additionalInfo:Dynamic):Void {
|
||||
var fileName = this.fileName;
|
||||
if(remappedNames.exists(fileName))
|
||||
fileName = remappedNames.get(fileName);
|
||||
Logs.traceColored([
|
||||
Logs.logText(fileName, RED),
|
||||
Logs.logText(text)
|
||||
|
||||
@@ -16,7 +16,7 @@ final class GameOverCreationEvent extends CancellableEvent
|
||||
|
||||
public var gameOverSong:String;
|
||||
|
||||
public var bpm:Int;
|
||||
public var bpm:Float;
|
||||
|
||||
public var lossSFX:String;
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ class BitmapUtil {
|
||||
for(x in 0...bmap.width) {
|
||||
color = bmap.getPixel32(x, y);
|
||||
fixedColor = 0xFF000000 + (color % 0x1000000);
|
||||
if (colorMap[fixedColor] == null)
|
||||
if (!colorMap.exists(fixedColor))
|
||||
colorMap[fixedColor] = 0;
|
||||
colorMap[fixedColor] += color.alphaFloat;
|
||||
}
|
||||
@@ -50,7 +50,7 @@ class BitmapUtil {
|
||||
for(x in 0...bmap.width) {
|
||||
color = bmap.getPixel32(x, y);
|
||||
fixedColor = 0xFF000000 + (color % 0x1000000);
|
||||
if (colorMap[fixedColor] == null)
|
||||
if (!colorMap.exists(fixedColor))
|
||||
colorMap[fixedColor] = 0;
|
||||
colorMap[fixedColor] += color.alphaFloat * 0.33 + (0.67 * (color.saturation * (2 * (color.lightness > 0.5 ? 0.5 - (color.lightness) : color.lightness))));
|
||||
}
|
||||
|
||||
@@ -618,7 +618,7 @@ class CoolUtil
|
||||
frontEnd.music = music;
|
||||
}
|
||||
|
||||
public static inline function flxeaseFromString(mainEase:String, suffix:String)
|
||||
@:noUsing public static inline function flxeaseFromString(mainEase:String, suffix:String)
|
||||
return Reflect.field(FlxEase, mainEase + (mainEase == "linear" ? "" : suffix));
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ class GameOverSubstate extends MusicBeatSubstate
|
||||
|
||||
public var characterName:String;
|
||||
public var gameOverSong:String;
|
||||
public var gameOverSongBPM:Int;
|
||||
public var gameOverSongBPM:Float;
|
||||
public var lossSFXName:String;
|
||||
public var retrySFX:String;
|
||||
public var player:Bool;
|
||||
|
||||
Reference in New Issue
Block a user