From 38997b47651630fcefa6cfc8a563cf622d54eae1 Mon Sep 17 00:00:00 2001 From: Ralty <78720179+Raltyro@users.noreply.github.com> Date: Mon, 4 Aug 2025 18:08:21 +0700 Subject: [PATCH] Don't duplicate default asset library --- .../backend/assets/AssetsLibraryList.hx | 28 ++++++++++++------- source/funkin/backend/assets/ModsFolder.hx | 4 +-- source/funkin/backend/system/Main.hx | 11 -------- source/funkin/backend/system/MainState.hx | 14 +++++----- source/funkin/menus/FreeplayState.hx | 26 +++++++++++------ 5 files changed, 44 insertions(+), 39 deletions(-) diff --git a/source/funkin/backend/assets/AssetsLibraryList.hx b/source/funkin/backend/assets/AssetsLibraryList.hx index d031ae2c..2f6682e2 100644 --- a/source/funkin/backend/assets/AssetsLibraryList.hx +++ b/source/funkin/backend/assets/AssetsLibraryList.hx @@ -147,7 +147,21 @@ class AssetsLibraryList extends AssetLibrary { public function new(?base:AssetLibrary) { super(); - __defaultLibraries.push(addLibrary(this.base = (base == null ? Assets.getLibrary("default") : base), SOURCE)); + #if (sys && TEST_BUILD) + Logs.infos("Used cne test / cne build. Switching into source assets."); + #if MOD_SUPPORT + ModsFolder.modsPath = './${pathBack}mods/'; + ModsFolder.addonsPath = './${pathBack}addons/'; + #end + __defaultLibraries.push(ModsFolder.loadLibraryFromFolder('assets', './${pathBack}assets/', true, SOURCE)); + #elseif USE_ADAPTED_ASSETS + __defaultLibraries.push(ModsFolder.loadLibraryFromFolder('assets', './assets/', true, SOURCE)); + #else + if (base == null) (this.base = Assets.getLibrary("default")).tag = SOURCE; + else this.base = base; + __defaultLibraries.push(this.base); + #end + for (d in __defaultLibraries) addLibrary(d); } public function unloadLibraries() { @@ -162,19 +176,13 @@ class AssetsLibraryList extends AssetLibrary { libraries = []; // adds default libraries in again - for(d in __defaultLibraries) - addLibrary(d); + for (d in __defaultLibraries) addLibrary(d); } 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 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 (tag != null) lib.tag = tag; + else if (lib.tag == null) lib.tag = MODS; #if TRANSLATIONS_SUPPORT if(addTransLib) { var cleanLib = getCleanLibrary(lib); diff --git a/source/funkin/backend/assets/ModsFolder.hx b/source/funkin/backend/assets/ModsFolder.hx index 81460a99..b59b605c 100644 --- a/source/funkin/backend/assets/ModsFolder.hx +++ b/source/funkin/backend/assets/ModsFolder.hx @@ -153,12 +153,12 @@ class ModsFolder { return font; } - public static function prepareModLibrary(libName:String, lib:IModsAssetLibrary, force:Bool = false, ?tag:AssetSource = MODS) { + public static function prepareModLibrary(libName:String, lib:IModsAssetLibrary, force:Bool = false, ?tag:AssetSource) { var openLib = prepareLibrary(libName, force); lib.prefix = 'assets/'; @:privateAccess openLib.__proxy = cast(lib, lime.utils.AssetLibrary); - if(tag != null) { + if (tag != null) { openLib.tag = tag; cast(lib, lime.utils.AssetLibrary).tag = tag; } diff --git a/source/funkin/backend/system/Main.hx b/source/funkin/backend/system/Main.hx index 00758ed9..da44cf1d 100644 --- a/source/funkin/backend/system/Main.hx +++ b/source/funkin/backend/system/Main.hx @@ -138,17 +138,6 @@ class Main extends Sprite funkin.backend.scripting.GlobalScript.init(); #end - #if (sys && TEST_BUILD) - Logs.infos("Used cne test / cne build. Switching into source assets."); - #if MOD_SUPPORT - ModsFolder.modsPath = './${pathBack}mods/'; - ModsFolder.addonsPath = './${pathBack}addons/'; - #end - Paths.assetsTree.__defaultLibraries.push(ModsFolder.loadLibraryFromFolder('assets', './${pathBack}assets/', true, SOURCE)); - #elseif USE_ADAPTED_ASSETS - Paths.assetsTree.__defaultLibraries.push(ModsFolder.loadLibraryFromFolder('assets', './assets/', true, SOURCE)); - #end - var lib = new AssetLibrary(); @:privateAccess lib.__proxy = Paths.assetsTree; diff --git a/source/funkin/backend/system/MainState.hx b/source/funkin/backend/system/MainState.hx index 520b2816..2b860c69 100644 --- a/source/funkin/backend/system/MainState.hx +++ b/source/funkin/backend/system/MainState.hx @@ -4,6 +4,7 @@ package funkin.backend.system; import sys.FileSystem; #end import flixel.FlxState; +import funkin.backend.assets.AssetsLibraryList; import funkin.backend.assets.ModsFolder; import funkin.backend.assets.ModsFolderLibrary; import funkin.backend.chart.EventsData; @@ -127,14 +128,13 @@ class MainState extends FlxState { if (Options.devMode && Options.allowConfigWarning) { var lib:ModsFolderLibrary; - for (e in Paths.assetsTree.libraries) { - @:privateAccess if (!(e is openfl.utils.AssetLibrary) || !((lib = cast cast(e, openfl.utils.AssetLibrary).__proxy) is ModsFolderLibrary)) continue; - if (lib.modName == ModsFolder.currentModFolder) { - if (lib.exists(Paths.ini("config/modpack"), lime.utils.AssetType.TEXT)) break; + for (e in Paths.assetsTree.libraries) if ((lib = cast AssetsLibraryList.getCleanLibrary(e)) is ModsFolderLibrary + && lib.modName == ModsFolder.currentModFolder) + { + if (lib.exists(Paths.ini("config/modpack"), lime.utils.AssetType.TEXT)) break; - FlxG.switchState(new ModConfigWarning(lib)); - return; - } + FlxG.switchState(new ModConfigWarning(lib)); + return; } } diff --git a/source/funkin/menus/FreeplayState.hx b/source/funkin/menus/FreeplayState.hx index 824abdf6..6c8bdf5b 100644 --- a/source/funkin/menus/FreeplayState.hx +++ b/source/funkin/menus/FreeplayState.hx @@ -473,14 +473,22 @@ class FreeplaySonglist { public function new() {} public function getSongsFromSource(source:funkin.backend.assets.AssetSource, useTxt:Bool = true) { - var oldPath = Paths.txt("freeplaySonglist"); - var newPath = Paths.txt("config/freeplaySonglist"); - var path:String = useTxt && !Paths.assetsTree.existsSpecific(newPath, "TEXT", source) && Paths.assetsTree.existsSpecific(oldPath, "TEXT", source) ? { - Logs.warn("data/freeplaySonglist.txt is deprecated and will be removed in the future. Please move the file to data/config/", DARKYELLOW, "FreeplaySonglist"); - oldPath; - } : newPath; - - var songsFound:Array = useTxt && Paths.assetsTree.existsSpecific(path, "TEXT", source) ? CoolUtil.coolTextFile(path): Paths.getFolderDirectories("songs", false, source); + var songsFound:Array = null; + if (useTxt) { + var oldPath = Paths.txt('freeplaySonglist'); + var newPath = Paths.txt('config/freeplaySonglist'); + trace(oldPath, newPath, source); + if (Paths.assetsTree.existsSpecific(newPath, "TEXT", source)) { + trace('new'); + songsFound = CoolUtil.coolTextFile(newPath); + } + else if (Paths.assetsTree.existsSpecific(oldPath, "TEXT", source)) { + trace('old'); + Logs.warn("data/freeplaySonglist.txt is deprecated and will be removed in the future. Please move the file to data/config/", DARKYELLOW, "FreeplaySonglist"); + songsFound = CoolUtil.coolTextFile(oldPath); + } + } + if (songsFound == null) songsFound = Paths.getFolderDirectories("songs", false, source); if (songsFound.length > 0) { for (s in songsFound) songs.push(Chart.loadChartMeta(s, Flags.DEFAULT_DIFFICULTY, source == MODS)); return false; @@ -499,7 +507,7 @@ class FreeplaySonglist { songList.getSongsFromSource(SOURCE, useTxt); songList.getSongsFromSource(MODS, useTxt); default /*case 'override'*/: - if (songList.getSongsFromSource(MODS, useTxt)) + if (!songList.getSongsFromSource(MODS, useTxt)) songList.getSongsFromSource(SOURCE, useTxt); }