diff --git a/Project.xml b/Project.xml index ebb1404e..39552f87 100644 --- a/Project.xml +++ b/Project.xml @@ -154,7 +154,9 @@ - + @@ -167,4 +169,10 @@ + + + + + + diff --git a/buildnumber.txt b/buildnumber.txt index 5e94329c..5b2b555c 100644 --- a/buildnumber.txt +++ b/buildnumber.txt @@ -1 +1 @@ -1333 \ No newline at end of file +1340 \ No newline at end of file diff --git a/source/funkin/mods/ModdableAssetsFolder.hx b/source/funkin/mods/ModdableAssetsFolder.hx new file mode 100644 index 00000000..8d593ba3 --- /dev/null +++ b/source/funkin/mods/ModdableAssetsFolder.hx @@ -0,0 +1,35 @@ +package funkin.mods; + +import lime.utils.AssetLibrary; + +/** + * Used to prevent crashes + */ +class ModdableAssetsFolder extends ModsFolderLibrary { + public var oldLibrary:AssetLibrary; + + public override function exists(id:String, type:String) { + if (!id.startsWith("assets/")) + return oldLibrary.exists(id, type); + return super.exists(id, type); + } + + public override function getAsset(id:String, type:String) { + if (!id.startsWith("assets/")) + return oldLibrary.getAsset(id, type); + return super.getAsset(id, type); + } + + public function new(folder:String, libName:String, oldLib:AssetLibrary) { + super(folder, libName); + oldLibrary = oldLib; + trace(Type.getClassName(Type.getClass(oldLibrary))); + } + + private override function __parseAsset(asset:String):Bool { + var prefix = 'assets/'; + if (!asset.startsWith(prefix)) return false; + _parsedAsset = asset.substr(prefix.length); + return true; + } +} \ No newline at end of file diff --git a/source/funkin/mods/ModsFolder.hx b/source/funkin/mods/ModsFolder.hx index fec4675b..7e38c298 100644 --- a/source/funkin/mods/ModsFolder.hx +++ b/source/funkin/mods/ModsFolder.hx @@ -111,10 +111,11 @@ class ModsFolder { return lib; } - public static function loadLibraryFromFolder(libName:String, folder:String, force:Bool = false) { + public static function loadLibraryFromFolder(libName:String, folder:String, force:Bool = false, useOldWhenMissing:Bool = false) { + var oldLib = useOldWhenMissing ? Assets.getLibrary(libName) : null; var lib = prepareLibrary(libName, force); @:privateAccess - lib.__proxy = new ModsFolderLibrary(folder, libName); + lib.__proxy = useOldWhenMissing ? new ModdableAssetsFolder(folder, libName, oldLib) : new ModsFolderLibrary(folder, libName); Assets.registerLibrary(libName, lib); return lib; } diff --git a/source/funkin/system/Main.hx b/source/funkin/system/Main.hx index 686065c3..19aadcf1 100644 --- a/source/funkin/system/Main.hx +++ b/source/funkin/system/Main.hx @@ -125,14 +125,18 @@ class Main extends Sprite #if sys if (Sys.args().contains("-livereload")) { + #if USE_SOURCE_ASSETS trace("Used lime test windows. Switching into source assets."); - ModsFolder.loadLibraryFromFolder('sourceassets', './../../../../assets/'); - @:privateAccess - Paths.__useSourceAssets = true; + ModsFolder.loadLibraryFromFolder('default', './../../../../assets/', true, true); + #end var buildNum:Int = Std.parseInt(File.getContent("./../../../../buildnumber.txt")); buildNum++; File.saveContent("./../../../../buildnumber.txt", Std.string(buildNum)); + } else { + #if USE_ADAPTED_ASSETS + ModsFolder.loadLibraryFromFolder('default', './assets/', true, true); + #end } #end diff --git a/source/funkin/system/Paths.hx b/source/funkin/system/Paths.hx index d2057117..b7946d76 100644 --- a/source/funkin/system/Paths.hx +++ b/source/funkin/system/Paths.hx @@ -18,7 +18,6 @@ class Paths * Currently is set to `mp3` for web targets, and `ogg` for other targets. */ inline public static var SOUND_EXT = #if web "mp3" #else "ogg" #end; - private static var __useSourceAssets = false; public static function getPath(file:String, type:AssetType, library:Null, skipModsVerification:Bool = false) { @@ -32,16 +31,16 @@ class Paths if (library != null) return getLibraryPath(file, library); - return getPreloadPath(file); + return getAssetsPath(file); } static public function video(key:String) { return getPath('videos/$key.mp4', BINARY, null); } - static public function getLibraryPath(file:String, library = "preload") + static public function getLibraryPath(file:String, library = "default") { - return if (library == "preload" || library == "default") getPreloadPath(file); else getLibraryPathForce(file, library); + return if (library == "preload" || library == "default") getAssetsPath(file); else getLibraryPathForce(file, library); } inline static function getLibraryPathForce(file:String, library:String) @@ -50,9 +49,9 @@ class Paths return '$library:assets/$library/$file'; } - inline static function getPreloadPath(file:String) + inline static function getAssetsPath(file:String) { - return (__useSourceAssets) ? getLibraryPathForce(file, 'sourceassets') : 'assets/$file'; + return 'assets/$file'; } inline static public function file(file:String, type:AssetType = TEXT, ?library:String)