Fix hierarchy of libs + Cleaner Tree Info

This commit is contained in:
Ne_Eo
2024-10-02 22:24:35 +02:00
parent 6f2e97ef74
commit 9febce79c1
6 changed files with 81 additions and 23 deletions
+4
View File
@@ -380,6 +380,10 @@
<str id="uiDebug.name">UI Debug State</str>
</group>
<group name="Wiki">
<str id="wiki.name">Wiki</str>
</group>
<group name="DebugOptions">
<str id="debugOptions.name">Debug Options</str>
</group>
@@ -1,6 +1,8 @@
package funkin.backend.assets;
#if TRANSLATIONS_SUPPORT
import funkin.backend.assets.TranslatedAssetLibrary;
#end
import funkin.backend.assets.IModsAssetLibrary;
import lime.utils.AssetLibrary;
@@ -17,8 +19,23 @@ class AssetsLibraryList extends AssetLibrary {
#end
public function removeLibrary(lib:AssetLibrary) {
if (lib != null)
if (lib != null) {
libraries.remove(lib);
#if TRANSLATIONS_SUPPORT
// TODO: improve this code
for(k=>l in libraries) {
if(l == null) continue;
if(l is TranslatedAssetLibrary) {
var tlib = cast(l, TranslatedAssetLibrary);
var lib:Dynamic = lib;
if(tlib.forLibrary == lib) {
libraries.remove(tlib);
break;
}
}
}
#end
}
return lib;
}
public function existsSpecific(id:String, type:String, source:AssetSource = BOTH) {
@@ -130,9 +147,6 @@ class AssetsLibraryList extends AssetLibrary {
public function new(?base:AssetLibrary) {
super();
#if TRANSLATIONS_SUPPORT
__defaultLibraries.push(addLibrary(transLib = new TranslatedAssetLibrary(), BOTH));
#end
__defaultLibraries.push(addLibrary(this.base = (base == null ? Assets.getLibrary("default") : base), SOURCE));
}
@@ -152,14 +166,25 @@ class AssetsLibraryList extends AssetLibrary {
addLibrary(d);
}
public function addLibrary(lib:AssetLibrary, ?tag:AssetSource) {
libraries.insert(#if TRANSLATIONS_SUPPORT libraries.indexOf(transLib) + 1 #else 0 #end, lib);
public function addLibrary(lib:AssetLibrary, ?tag:AssetSource, ?addTransLib:Bool = true) {
libraries.insert(0, lib);
if(tag != null)
lib.tag = tag;
if(lib.tag == null) {
if(lib.tag == null) { // if tag is null, set it to MODS, so it doesnt set the tag on the libs that exists
lib.tag = MODS;
//trace('AssetLibrary ${getCleanLibrary(lib)} tag not set, defaulting to MODS');
}
#if TRANSLATIONS_SUPPORT
if(addTransLib) {
var cleanLib = getCleanLibrary(lib);
if(cleanLib != null && (cleanLib is IModsAssetLibrary)) {
var transLib = new TranslatedAssetLibrary(cast(cleanLib, IModsAssetLibrary));
transLib.tag = cleanLib.tag;
libraries.insert(0, transLib);
}
}
#end
return lib;
}
@@ -111,7 +111,9 @@ class ModsFolder {
var libs = [];
for (i in Paths.assetsTree.libraries) {
var l = AssetsLibraryList.getCleanLibrary(i);
#if TRANSLATIONS_SUPPORT
if(skipTranslated && (l is TranslatedAssetLibrary)) continue;
#end
if (l is ScriptedAssetLibrary || l is IModsAssetLibrary) libs.push(cast(l, IModsAssetLibrary));
}
return libs;
@@ -1,5 +1,6 @@
package funkin.backend.assets;
import lime.utils.AssetLibrary as LimeAssetLibrary;
import openfl.utils.AssetLibrary;
import lime.media.AudioBuffer;
import lime.graphics.Image;
@@ -12,6 +13,8 @@ class TranslatedAssetLibrary extends AssetLibrary implements IModsAssetLibrary {
public var basePath:String;
public var prefix:String = TranslationUtil.LANG_FOLDER + "/";
public var forLibrary:IModsAssetLibrary;
public var langFolder(get, set):String;
@:noCompletion private inline function get_langFolder():String {
return libName;
@@ -21,13 +24,14 @@ class TranslatedAssetLibrary extends AssetLibrary implements IModsAssetLibrary {
return libName;
}
public function new(?langFolder:String) {
public function new(lib:IModsAssetLibrary, ?langFolder:String) {
super();
this.forLibrary = lib;
this.langFolder = langFolder;
}
function toString():String
return '(TranslatedAssetLibrary: Lang: $libName)';
return '(TranslatedAssetLibrary: Lang: $libName | For: ${forLibrary})';
private inline function getAssetPath():String // because of the IModsAssetLibrary - Nex
return basePath;
@@ -39,7 +43,9 @@ class TranslatedAssetLibrary extends AssetLibrary implements IModsAssetLibrary {
public override function getAudioBuffer(id:String):AudioBuffer
{
for(lib in ModsFolder.getLoadedModsLibs(true)) {
// TODO: rewrite this, once it works
var libs = [forLibrary];
for(lib in libs) {
if(!(lib is AssetLibrary)) continue;
var val = cast(lib, AssetLibrary).getAudioBuffer(formatPath(lib.prefix, id));
if(val != null) return val;
@@ -49,7 +55,8 @@ class TranslatedAssetLibrary extends AssetLibrary implements IModsAssetLibrary {
public override function getBytes(id:String):Bytes
{
for(lib in ModsFolder.getLoadedModsLibs(true)) {
var libs = [forLibrary];
for(lib in libs) {
if(!(lib is AssetLibrary)) continue;
var val = cast(lib, AssetLibrary).getBytes(formatPath(lib.prefix, id));
if(val != null) return val;
@@ -59,7 +66,8 @@ class TranslatedAssetLibrary extends AssetLibrary implements IModsAssetLibrary {
public override function getText(id:String):String
{
for(lib in ModsFolder.getLoadedModsLibs(true)) {
var libs = [forLibrary];
for(lib in libs) {
if(!(lib is AssetLibrary)) continue;
var val = cast(lib, AssetLibrary).getText(formatPath(lib.prefix, id));
if(val != null) return val;
@@ -69,7 +77,8 @@ class TranslatedAssetLibrary extends AssetLibrary implements IModsAssetLibrary {
public override function getFont(id:String):Font
{
for(lib in ModsFolder.getLoadedModsLibs(true)) {
var libs = [forLibrary];
for(lib in libs) {
if(!(lib is AssetLibrary)) continue;
var val = cast(lib, AssetLibrary).getFont(formatPath(lib.prefix, id));
if(val != null) return val;
@@ -79,7 +88,8 @@ class TranslatedAssetLibrary extends AssetLibrary implements IModsAssetLibrary {
public override function getImage(id:String):Image
{
for(lib in ModsFolder.getLoadedModsLibs(true)) {
var libs = [forLibrary];
for(lib in libs) {
if(!(lib is AssetLibrary)) continue;
var val = cast(lib, AssetLibrary).getImage(formatPath(lib.prefix, id));
if(val != null) return val;
@@ -89,7 +99,8 @@ class TranslatedAssetLibrary extends AssetLibrary implements IModsAssetLibrary {
public override function getPath(id:String):String
{
for(lib in ModsFolder.getLoadedModsLibs(true)) {
var libs = [forLibrary];
for(lib in libs) {
if(!(lib is AssetLibrary)) continue;
var val = cast(lib, AssetLibrary).getPath(formatPath(lib.prefix, id));
if(val != null) return val;
@@ -102,7 +113,8 @@ class TranslatedAssetLibrary extends AssetLibrary implements IModsAssetLibrary {
public function getFiles(folder:String):Array<String>
{
for(lib in ModsFolder.getLoadedModsLibs(true)) {
var libs = [forLibrary];
for(lib in libs) {
if(!(lib is AssetLibrary)) continue;
var val = lib.getFiles(formatPath(lib.prefix, folder));
if(val != null && val.length > 0) return val;
@@ -112,7 +124,8 @@ class TranslatedAssetLibrary extends AssetLibrary implements IModsAssetLibrary {
public function getFolders(folder:String):Array<String>
{
for(lib in ModsFolder.getLoadedModsLibs(true)) {
var libs = [forLibrary];
for(lib in libs) {
if(!(lib is AssetLibrary)) continue;
var val = lib.getFolders(formatPath(lib.prefix, folder));
if(val != null && val.length > 0) return val;
@@ -122,7 +135,8 @@ class TranslatedAssetLibrary extends AssetLibrary implements IModsAssetLibrary {
private function __isCacheValid(cache:Map<String, Dynamic>, asset:String, isLocal:Bool = false):Bool
{
for(lib in ModsFolder.getLoadedModsLibs(true)) {
var libs = [forLibrary];
for(lib in libs) {
if(!(lib is AssetLibrary)) continue;
// are you fucking serious (no the fucking switch doesnt work here) - Nex
@@ -141,7 +155,8 @@ class TranslatedAssetLibrary extends AssetLibrary implements IModsAssetLibrary {
private function __parseAsset(asset:String):Bool
{
@:privateAccess
for(lib in ModsFolder.getLoadedModsLibs(true)) {
var libs = [forLibrary];
for(lib in libs) {
if(!(lib is AssetLibrary)) continue;
if(lib.__parseAsset(formatPath(lib.prefix, asset))) return true;
}
@@ -1,5 +1,8 @@
package funkin.backend.system.framerate;
#if TRANSLATIONS_SUPPORT
import funkin.backend.assets.TranslatedAssetLibrary;
#end
import funkin.backend.assets.AssetsLibraryList;
import funkin.backend.assets.IModsAssetLibrary;
import funkin.backend.assets.ScriptedAssetLibrary;
@@ -19,12 +22,20 @@ class AssetTreeInfo extends FramerateCategory {
var tag = l.tag.toString().toUpperCase();
if (l is ScriptedAssetLibrary)
text += '${Type.getClassName(Type.getClass(l))} - $tag - ${cast(l, ScriptedAssetLibrary).scriptName} (${cast(l, ScriptedAssetLibrary).modName} | ${cast(l, ScriptedAssetLibrary).libName} | ${cast(l, ScriptedAssetLibrary).prefix})\n';
text += '[$tag] ';
var className = Type.getClassName(Type.getClass(l));
className = className.substr(className.lastIndexOf(".") + 1);
#if TRANSLATIONS_SUPPORT
if (l is TranslatedAssetLibrary)
text += '${className} - ${cast(l, TranslatedAssetLibrary).langFolder} for (${cast(l, TranslatedAssetLibrary).forLibrary.modName})\n';
else #end if (l is ScriptedAssetLibrary)
text += '${className} - ${cast(l, ScriptedAssetLibrary).scriptName} (${cast(l, ScriptedAssetLibrary).modName} | ${cast(l, ScriptedAssetLibrary).libName} | ${cast(l, ScriptedAssetLibrary).prefix})\n';
else if (l is IModsAssetLibrary)
text += '${Type.getClassName(Type.getClass(l))} - $tag - ${cast(l, IModsAssetLibrary).modName} - ${cast(l, IModsAssetLibrary).libName} (${cast(l, IModsAssetLibrary).prefix})\n';
text += '${className} - ${cast(l, IModsAssetLibrary).modName} - ${cast(l, IModsAssetLibrary).libName} (${cast(l, IModsAssetLibrary).prefix})\n';
else
text += Std.string(l) + ' - $tag\n';
text += Std.string(l) + '\n';
}
}
if (text != "")
+1
View File
@@ -35,6 +35,7 @@ class EditorPicker extends MusicBeatSubstate {
#end
{
name: "Wiki",
id: "wiki",
iconID: 5,
state: null,
onClick: function() {