Fixed bug + Cleaner Code
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
package funkin.backend.assets;
|
||||
|
||||
enum abstract AssetSource(Null<Bool>) from Bool from Null<Bool> to Null<Bool> {
|
||||
var SOURCE = true;
|
||||
var MODS = false;
|
||||
var BOTH = null;
|
||||
enum abstract AssetSource(Null<Int>)/* from Null<Bool>*/ from Null<Int> to Null<Int> {
|
||||
var SOURCE = 0;
|
||||
var MODS = 1;
|
||||
var BOTH = -1;
|
||||
|
||||
@:from public static function fromString(string:String):AssetSource
|
||||
@:from public static function fromString(str:String):AssetSource
|
||||
{
|
||||
return switch (string.trim().toLowerCase())
|
||||
return switch (StringTools.trim(str).toLowerCase())
|
||||
{
|
||||
case "source": SOURCE;
|
||||
case "mods": MODS;
|
||||
@@ -16,6 +16,17 @@ enum abstract AssetSource(Null<Bool>) from Bool from Null<Bool> to Null<Bool> {
|
||||
}
|
||||
}
|
||||
|
||||
/*@:from public static function fromBool(b:Null<Bool>):AssetSource
|
||||
{
|
||||
return switch (b)
|
||||
{
|
||||
case true: SOURCE;
|
||||
case false: MODS;
|
||||
case null: BOTH;
|
||||
default: MODS;
|
||||
}
|
||||
}*/
|
||||
|
||||
@:to public inline function toString():String
|
||||
{
|
||||
return switch (this)
|
||||
@@ -23,6 +34,7 @@ enum abstract AssetSource(Null<Bool>) from Bool from Null<Bool> to Null<Bool> {
|
||||
case SOURCE: "source";
|
||||
case MODS: "mods";
|
||||
case BOTH: "both";
|
||||
default: "mods";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,17 +17,16 @@ class AssetsLibraryList extends AssetLibrary {
|
||||
#end
|
||||
|
||||
public function removeLibrary(lib:AssetLibrary) {
|
||||
if (lib == null) return lib;
|
||||
libraries.remove(lib);
|
||||
if (lib != null)
|
||||
libraries.remove(lib);
|
||||
return lib;
|
||||
}
|
||||
public function existsSpecific(id:String, type:String, source:AssetSource = BOTH) {
|
||||
if (!id.startsWith("assets/") && existsSpecific('assets/$id', type, source))
|
||||
return true;
|
||||
for(k=>e in libraries) {
|
||||
if (shouldSkipLib(e, source)) continue;
|
||||
if (e.exists(id, type)) {
|
||||
trace('$k $e ${e.tag.toString()} $id exists');
|
||||
for(k=>l in libraries) {
|
||||
if (shouldSkipLib(l, source)) continue;
|
||||
if (l.exists(id, type)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -55,15 +54,10 @@ class AssetsLibraryList extends AssetLibrary {
|
||||
|
||||
public function getFiles(folder:String, source:AssetSource = BOTH):Array<String> {
|
||||
var content:Array<String> = [];
|
||||
for(k=>e in libraries) {
|
||||
if (shouldSkipLib(e, source)) continue;
|
||||
for(k=>l in libraries) {
|
||||
if (shouldSkipLib(l, source)) continue;
|
||||
|
||||
var l = e;
|
||||
|
||||
if (l is openfl.utils.AssetLibrary) {
|
||||
@:privateAccess
|
||||
l = cast(l, openfl.utils.AssetLibrary).__proxy;
|
||||
}
|
||||
l = getCleanLibrary(l);
|
||||
|
||||
// TODO: do base folder scanning
|
||||
#if MOD_SUPPORT
|
||||
@@ -79,15 +73,10 @@ class AssetsLibraryList extends AssetLibrary {
|
||||
|
||||
public function getFolders(folder:String, source:AssetSource = BOTH):Array<String> {
|
||||
var content:Array<String> = [];
|
||||
for(k=>e in libraries) {
|
||||
if (shouldSkipLib(e, source)) continue;
|
||||
for(k=>l in libraries) {
|
||||
if (shouldSkipLib(l, source)) continue;
|
||||
|
||||
var l = e;
|
||||
|
||||
if (l is openfl.utils.AssetLibrary) {
|
||||
@:privateAccess
|
||||
l = cast(l, openfl.utils.AssetLibrary).__proxy;
|
||||
}
|
||||
l = getCleanLibrary(l);
|
||||
|
||||
// TODO: do base folder scanning
|
||||
#if MOD_SUPPORT
|
||||
@@ -109,24 +98,20 @@ class AssetsLibraryList extends AssetLibrary {
|
||||
return ass;
|
||||
}
|
||||
}
|
||||
for(k=>e in libraries) {
|
||||
if (shouldSkipLib(e, source)) continue;
|
||||
for(k=>l in libraries) {
|
||||
if (shouldSkipLib(l, source)) continue;
|
||||
|
||||
@:privateAccess
|
||||
if (e.exists(id, e.types.get(id))) {
|
||||
var asset = e.getAsset(id, type);
|
||||
if (l.exists(id, l.types.get(id))) {
|
||||
var asset = l.getAsset(id, type);
|
||||
if (asset != null) {
|
||||
if(asset.length > 512) {
|
||||
trace('$k $e ${e.tag.toString()} $id asset of length ${asset.length}');
|
||||
} else {
|
||||
trace('$k $e ${e.tag.toString()} $id returned asset $asset');
|
||||
}
|
||||
return asset;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
} catch(e) {
|
||||
// TODO: trace the error
|
||||
throw e;
|
||||
}
|
||||
return null;
|
||||
@@ -167,9 +152,24 @@ class AssetsLibraryList extends AssetLibrary {
|
||||
addLibrary(d);
|
||||
}
|
||||
|
||||
public function addLibrary(lib:AssetLibrary, tag:AssetSource = MODS) {
|
||||
public function addLibrary(lib:AssetLibrary, ?tag:AssetSource) {
|
||||
libraries.insert(#if TRANSLATIONS_SUPPORT libraries.indexOf(transLib) + 1 #else 0 #end, lib);
|
||||
lib.tag = tag;
|
||||
if(tag != null)
|
||||
lib.tag = tag;
|
||||
if(lib.tag == null) {
|
||||
lib.tag = MODS;
|
||||
//trace('AssetLibrary ${getCleanLibrary(lib)} tag not set, defaulting to MODS');
|
||||
}
|
||||
return lib;
|
||||
}
|
||||
|
||||
public static function getCleanLibrary(e:AssetLibrary):AssetLibrary {
|
||||
var l = e;
|
||||
if (l is openfl.utils.AssetLibrary) {
|
||||
var al = cast(l, openfl.utils.AssetLibrary);
|
||||
@:privateAccess
|
||||
if (al.__proxy != null) l = al.__proxy;
|
||||
}
|
||||
return l;
|
||||
}
|
||||
}
|
||||
@@ -111,12 +111,7 @@ class ModsFolder {
|
||||
public static function getLoadedModsLibs(skipTranslated:Bool = false):Array<IModsAssetLibrary> {
|
||||
var libs = [];
|
||||
for (i in Paths.assetsTree.libraries) {
|
||||
var l = i;
|
||||
if (l is openfl.utils.AssetLibrary) {
|
||||
var al = cast(l, openfl.utils.AssetLibrary);
|
||||
@:privateAccess
|
||||
if (al.__proxy != null) l = al.__proxy;
|
||||
}
|
||||
var l = AssetsLibraryList.getCleanLibrary(i);
|
||||
if(skipTranslated && (l is TranslatedAssetLibrary)) continue;
|
||||
if (l is ScriptedAssetLibrary || l is IModsAssetLibrary) libs.push(cast(l, IModsAssetLibrary));
|
||||
}
|
||||
@@ -143,21 +138,25 @@ class ModsFolder {
|
||||
return font;
|
||||
}
|
||||
|
||||
public static function prepareModLibrary(libName:String, lib:IModsAssetLibrary, force:Bool = false) {
|
||||
public static function prepareModLibrary(libName:String, lib:IModsAssetLibrary, force:Bool = false, ?tag:AssetSource = MODS) {
|
||||
var openLib = prepareLibrary(libName, force);
|
||||
lib.prefix = 'assets/';
|
||||
@:privateAccess
|
||||
openLib.__proxy = cast(lib, lime.utils.AssetLibrary);
|
||||
if(tag != null) {
|
||||
openLib.tag = tag;
|
||||
cast(lib, lime.utils.AssetLibrary).tag = tag;
|
||||
}
|
||||
return openLib;
|
||||
}
|
||||
|
||||
#if MOD_SUPPORT
|
||||
public static function loadLibraryFromFolder(libName:String, folder:String, force:Bool = false, ?modName:String) {
|
||||
return prepareModLibrary(libName, new ModsFolderLibrary(folder, libName, modName), force);
|
||||
public static function loadLibraryFromFolder(libName:String, folder:String, force:Bool = false, ?modName:String, ?tag:AssetSource = MODS) {
|
||||
return prepareModLibrary(libName, new ModsFolderLibrary(folder, libName, modName), force, tag);
|
||||
}
|
||||
|
||||
public static function loadLibraryFromZip(libName:String, zipPath:String, force:Bool = false, ?modName:String) {
|
||||
return prepareModLibrary(libName, new ZipFolderLibrary(zipPath, libName, modName), force);
|
||||
public static function loadLibraryFromZip(libName:String, zipPath:String, force:Bool = false, ?modName:String, ?tag:AssetSource = MODS) {
|
||||
return prepareModLibrary(libName, new ZipFolderLibrary(zipPath, libName, modName), force, tag);
|
||||
}
|
||||
#end
|
||||
}
|
||||
@@ -29,7 +29,7 @@ class ModsFolderLibrary extends AssetLibrary implements IModsAssetLibrary {
|
||||
}
|
||||
|
||||
function toString():String {
|
||||
return '(ModsFolderLibrary: $libName/$modName)';
|
||||
return '(ModsFolderLibrary: $modName)';
|
||||
}
|
||||
|
||||
#if MOD_SUPPORT
|
||||
|
||||
@@ -27,7 +27,7 @@ class TranslatedAssetLibrary extends AssetLibrary implements IModsAssetLibrary {
|
||||
}
|
||||
|
||||
function toString():String
|
||||
return '(TranslatedAssetLibrary: The language folder is $libName)';
|
||||
return '(TranslatedAssetLibrary: Lang: $libName)';
|
||||
|
||||
private inline function getAssetPath():String // because of the IModsAssetLibrary - Nex
|
||||
return basePath;
|
||||
|
||||
@@ -67,7 +67,7 @@ class Chart {
|
||||
data.setFieldDefault("parsedColor", data.color.getColorFromDynamic().getDefault(defaultColor));
|
||||
|
||||
if (data.difficulties.length <= 0) {
|
||||
data.difficulties = [for(f in Paths.getFolderContent('songs/${songName.toLowerCase()}/charts/', false, !fromMods)) if (Path.extension(f = f.toUpperCase()) == "JSON") Path.withoutExtension(f)];
|
||||
data.difficulties = [for(f in Paths.getFolderContent('songs/${songName.toLowerCase()}/charts/', false, fromMods ? MODS : SOURCE)) if (Path.extension(f = f.toUpperCase()) == "JSON") Path.withoutExtension(f)];
|
||||
if (data.difficulties.length == 3) {
|
||||
var hasHard = false, hasNormal = false, hasEasy = false;
|
||||
for(d in data.difficulties) {
|
||||
|
||||
@@ -130,9 +130,9 @@ class Main extends Sprite
|
||||
ModsFolder.modsPath = './${pathBack}mods/';
|
||||
ModsFolder.addonsPath = './${pathBack}addons/';
|
||||
#end
|
||||
Paths.assetsTree.__defaultLibraries.push(ModsFolder.loadLibraryFromFolder('assets', './${pathBack}assets/', true));
|
||||
Paths.assetsTree.__defaultLibraries.push(ModsFolder.loadLibraryFromFolder('assets', './${pathBack}assets/', true, SOURCE));
|
||||
#elseif USE_ADAPTED_ASSETS
|
||||
Paths.assetsTree.__defaultLibraries.push(ModsFolder.loadLibraryFromFolder('assets', './assets/', true));
|
||||
Paths.assetsTree.__defaultLibraries.push(ModsFolder.loadLibraryFromFolder('assets', './assets/', true, SOURCE));
|
||||
#end
|
||||
|
||||
var lib = new AssetLibrary();
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package funkin.backend.system.framerate;
|
||||
|
||||
import funkin.backend.assets.AssetsLibraryList;
|
||||
import funkin.backend.assets.IModsAssetLibrary;
|
||||
import funkin.backend.assets.ScriptedAssetLibrary;
|
||||
|
||||
@@ -13,20 +14,17 @@ class AssetTreeInfo extends FramerateCategory {
|
||||
var text = 'Not initialized yet\n';
|
||||
if (Paths.assetsTree != null){
|
||||
text = "";
|
||||
for(e in Paths.assetsTree.libraries) {
|
||||
var l = e;
|
||||
if (l is openfl.utils.AssetLibrary) {
|
||||
var al = cast(l, openfl.utils.AssetLibrary);
|
||||
@:privateAccess
|
||||
if (al.__proxy != null) l = al.__proxy;
|
||||
}
|
||||
for(l in Paths.assetsTree.libraries) {
|
||||
var l = AssetsLibraryList.getCleanLibrary(l);
|
||||
|
||||
var tag = l.tag.toString().toUpperCase();
|
||||
|
||||
if (l is ScriptedAssetLibrary)
|
||||
text += '${Type.getClassName(Type.getClass(l))} - ${cast(l, ScriptedAssetLibrary).scriptName} (${cast(l, ScriptedAssetLibrary).modName} | ${cast(l, ScriptedAssetLibrary).libName} | ${cast(l, ScriptedAssetLibrary).prefix})\n';
|
||||
text += '${Type.getClassName(Type.getClass(l))} - $tag - ${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))} - ${cast(l, IModsAssetLibrary).modName} - ${cast(l, IModsAssetLibrary).libName} (${cast(l, IModsAssetLibrary).prefix})\n';
|
||||
text += '${Type.getClassName(Type.getClass(l))} - $tag - ${cast(l, IModsAssetLibrary).modName} - ${cast(l, IModsAssetLibrary).libName} (${cast(l, IModsAssetLibrary).prefix})\n';
|
||||
else
|
||||
text += Std.string(e) + "\n";
|
||||
text += Std.string(l) + ' - $tag\n';
|
||||
}
|
||||
}
|
||||
if (text != "")
|
||||
|
||||
@@ -601,7 +601,7 @@ class PlayState extends MusicBeatState
|
||||
|
||||
// PRECACHING
|
||||
#if REGION
|
||||
for(content in Paths.getFolderContent('images/game/score/', true, true))
|
||||
for(content in Paths.getFolderContent('images/game/score/', true, BOTH))
|
||||
graphicCache.cache(Paths.getPath(content));
|
||||
|
||||
for(i in 1...4) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package funkin.menus.credits;
|
||||
|
||||
import funkin.backend.assets.AssetSource;
|
||||
import funkin.options.OptionsScreen;
|
||||
import funkin.options.type.*;
|
||||
import funkin.options.TreeMenu;
|
||||
@@ -50,7 +51,7 @@ class CreditsMain extends TreeMenu {
|
||||
/**
|
||||
* XML STUFF
|
||||
*/
|
||||
public function parseCreditsFromXML(xml:Access, source:Bool):Array<OptionType> {
|
||||
public function parseCreditsFromXML(xml:Access, source:AssetSource):Array<OptionType> {
|
||||
var credsMenus:Array<OptionType> = [];
|
||||
|
||||
for(node in xml.elements) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package funkin.menus.ui;
|
||||
|
||||
import funkin.backend.assets.AssetsLibraryList;
|
||||
import openfl.utils.AssetLibrary;
|
||||
import haxe.xml.Access;
|
||||
import funkin.backend.assets.LimeLibrarySymbol;
|
||||
@@ -91,12 +92,7 @@ class Alphabet extends FlxSpriteGroup
|
||||
#if MOD_SUPPORT else {
|
||||
var libThing = new LimeLibrarySymbol(alphabetPath);
|
||||
if (libThing.library is AssetLibrary) {
|
||||
var library = cast(libThing.library, AssetLibrary);
|
||||
@:privateAccess
|
||||
if (library.__proxy != null && library.__proxy is AssetLibrary) {
|
||||
@:privateAccess
|
||||
library = cast(library.__proxy, AssetLibrary);
|
||||
}
|
||||
var library = AssetsLibraryList.getCleanLibrary(libThing.library);
|
||||
if (library is IModsAssetLibrary) {
|
||||
var modLib = cast(library, IModsAssetLibrary);
|
||||
@:privateAccess
|
||||
|
||||
Reference in New Issue
Block a user