From f153ed36961345fc449affb2f43d78c3237889dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=8D=9A=7ENex?= <87421482+NexIsDumb@users.noreply.github.com> Date: Tue, 9 Apr 2024 01:42:24 +0200 Subject: [PATCH] uuugh --- .../backend/assets/TranslatedAssetLibrary.hx | 71 +++++++------------ source/funkin/backend/system/Main.hx | 5 +- .../funkin/backend/utils/TranslationUtil.hx | 2 + 3 files changed, 30 insertions(+), 48 deletions(-) diff --git a/source/funkin/backend/assets/TranslatedAssetLibrary.hx b/source/funkin/backend/assets/TranslatedAssetLibrary.hx index 1bb89c43..63e0ad68 100644 --- a/source/funkin/backend/assets/TranslatedAssetLibrary.hx +++ b/source/funkin/backend/assets/TranslatedAssetLibrary.hx @@ -32,14 +32,16 @@ class TranslatedAssetLibrary extends AssetLibrary implements IModsAssetLibrary { private inline function getAssetPath():String // because of the IModsAssetLibrary - Nex return basePath; + public inline function formatPath(mainPath:String, ?asset:String):String { // TO MAKE THIS WORKS GOOD - Nex + if(!mainPath.endsWith('/')) mainPath += '/'; + return mainPath + getAssetPath() + (asset == null ? "" : asset); + } + public override function getAudioBuffer(id:String):AudioBuffer { for(lib in ModsFolder.getLoadedModsLibs()) { - if(!(lib is AssetLibrary)) continue; - - var mainPath = lib.prefix; - if(!mainPath.endsWith('/')) mainPath += '/'; - var val = cast(lib, AssetLibrary).getAudioBuffer(mainPath + getAssetPath() + id); + if(lib is TranslatedAssetLibrary || !(lib is AssetLibrary)) continue; + var val = cast(lib, AssetLibrary).getAudioBuffer(formatPath(lib.basePath, id)); if(val != null) return val; } return null; @@ -48,11 +50,8 @@ class TranslatedAssetLibrary extends AssetLibrary implements IModsAssetLibrary { public override function getBytes(id:String):Bytes { for(lib in ModsFolder.getLoadedModsLibs()) { - if(!(lib is AssetLibrary)) continue; - - var mainPath = lib.prefix; - if(!mainPath.endsWith('/')) mainPath += '/'; - var val = cast(lib, AssetLibrary).getBytes(mainPath + getAssetPath() + id); + if(lib is TranslatedAssetLibrary || !(lib is AssetLibrary)) continue; + var val = cast(lib, AssetLibrary).getBytes(formatPath(lib.basePath, id)); if(val != null) return val; } return null; @@ -61,11 +60,8 @@ class TranslatedAssetLibrary extends AssetLibrary implements IModsAssetLibrary { public override function getFont(id:String):Font { for(lib in ModsFolder.getLoadedModsLibs()) { - if(!(lib is AssetLibrary)) continue; - - var mainPath = lib.prefix; - if(!mainPath.endsWith('/')) mainPath += '/'; - var val = cast(lib, AssetLibrary).getFont(mainPath + getAssetPath() + id); + if(lib is TranslatedAssetLibrary || !(lib is AssetLibrary)) continue; + var val = cast(lib, AssetLibrary).getFont(formatPath(lib.basePath, id)); if(val != null) return val; } return null; @@ -74,11 +70,8 @@ class TranslatedAssetLibrary extends AssetLibrary implements IModsAssetLibrary { public override function getImage(id:String):Image { for(lib in ModsFolder.getLoadedModsLibs()) { - if(!(lib is AssetLibrary)) continue; - - var mainPath = lib.prefix; - if(!mainPath.endsWith('/')) mainPath += '/'; - var val = cast(lib, AssetLibrary).getImage(mainPath + getAssetPath() + id); + if(lib is TranslatedAssetLibrary || !(lib is AssetLibrary)) continue; + var val = cast(lib, AssetLibrary).getImage(formatPath(lib.basePath, id)); if(val != null) return val; } return null; @@ -87,11 +80,8 @@ class TranslatedAssetLibrary extends AssetLibrary implements IModsAssetLibrary { public override function getPath(id:String):String { for(lib in ModsFolder.getLoadedModsLibs()) { - if(!(lib is AssetLibrary)) continue; - - var mainPath = lib.prefix; - if(!mainPath.endsWith('/')) mainPath += '/'; - var val = cast(lib, AssetLibrary).getPath(mainPath + getAssetPath() + id); + if(lib is TranslatedAssetLibrary || !(lib is AssetLibrary)) continue; + var val = cast(lib, AssetLibrary).getPath(formatPath(lib.basePath, id)); if(val != null) return val; } return null; @@ -103,9 +93,8 @@ class TranslatedAssetLibrary extends AssetLibrary implements IModsAssetLibrary { public function getFiles(folder:String):Array { for(lib in ModsFolder.getLoadedModsLibs()) { - var mainPath = lib.prefix; - if(!mainPath.endsWith('/')) mainPath += '/'; - var val = lib.getFiles(mainPath + getAssetPath() + folder); + if(lib is TranslatedAssetLibrary) continue; + var val = lib.getFiles(formatPath(lib.basePath, folder)); if(val != []) return val; } return []; @@ -114,9 +103,8 @@ class TranslatedAssetLibrary extends AssetLibrary implements IModsAssetLibrary { public function getFolders(folder:String):Array { for(lib in ModsFolder.getLoadedModsLibs()) { - var mainPath = lib.prefix; - if(!mainPath.endsWith('/')) mainPath += '/'; - var val = lib.getFolders(mainPath + getAssetPath() + folder); + if(lib is TranslatedAssetLibrary) continue; + var val = lib.getFolders(formatPath(lib.basePath, folder)); if(val != []) return val; } return []; @@ -125,7 +113,7 @@ class TranslatedAssetLibrary extends AssetLibrary implements IModsAssetLibrary { private function __isCacheValid(cache:Map, asset:String, isLocal:Bool = false):Bool { for(lib in ModsFolder.getLoadedModsLibs()) { - if(!(lib is AssetLibrary)) continue; + if(lib is TranslatedAssetLibrary || !(lib is AssetLibrary)) continue; // are you fucking serious (no the fucking switch doesnt work here) - Nex var _lib = cast(lib, AssetLibrary); @@ -135,33 +123,22 @@ class TranslatedAssetLibrary extends AssetLibrary implements IModsAssetLibrary { (cache == cachedImages) ? _lib.cachedImages : (cache == cachedText) ? _lib.cachedText : cache; - var mainPath = lib.prefix; - if(!mainPath.endsWith('/')) mainPath += '/'; - @:privateAccess if(lib.__isCacheValid(libCache, mainPath + getAssetPath() + asset, isLocal)) return true; + @:privateAccess if(lib.__isCacheValid(libCache, formatPath(lib.basePath, asset), isLocal)) return true; } return false; } private function __parseAsset(asset:String):Bool { - for(lib in ModsFolder.getLoadedModsLibs()) { - var mainPath = lib.prefix; - if(!mainPath.endsWith('/')) mainPath += '/'; - @:privateAccess if(lib.__parseAsset(mainPath + getAssetPath() + asset)) return true; - } + @:privateAccess + for(lib in ModsFolder.getLoadedModsLibs()) if(!(lib is TranslatedAssetLibrary) && lib.__parseAsset(formatPath(lib.basePath, asset))) return true; return false; } #end public override function exists(id:String, type:String):Bool { - for(lib in ModsFolder.getLoadedModsLibs()) { - if(!(lib is AssetLibrary)) continue; - - var mainPath = lib.prefix; - if(!mainPath.endsWith('/')) mainPath += '/'; - if(cast(lib, AssetLibrary).exists(mainPath + getAssetPath() + id, type)) return true; - } + for(lib in ModsFolder.getLoadedModsLibs()) if(!(lib is TranslatedAssetLibrary) && lib is AssetLibrary && cast(lib, AssetLibrary).exists(formatPath(lib.basePath, id), type)) return true; return false; } } \ No newline at end of file diff --git a/source/funkin/backend/system/Main.hx b/source/funkin/backend/system/Main.hx index cad2266e..94c7f85c 100644 --- a/source/funkin/backend/system/Main.hx +++ b/source/funkin/backend/system/Main.hx @@ -114,6 +114,10 @@ class Main extends Sprite FunkinCache.init(); Paths.assetsTree = new AssetsLibraryList(); + #if TRANSLATIONS_SUPPORT + Paths.assetsTree.__defaultLibraries.insert(0, new funkin.backend.assets.TranslatedAssetLibrary()); + #end + #if UPDATE_CHECKING funkin.backend.system.updating.UpdateUtil.init(); #end @@ -135,7 +139,6 @@ class Main extends Sprite Paths.assetsTree.__defaultLibraries.push(ModsFolder.loadLibraryFromFolder('assets', './assets/', true)); #end - var lib = new AssetLibrary(); @:privateAccess lib.__proxy = Paths.assetsTree; diff --git a/source/funkin/backend/utils/TranslationUtil.hx b/source/funkin/backend/utils/TranslationUtil.hx index 493d94c5..048e1706 100644 --- a/source/funkin/backend/utils/TranslationUtil.hx +++ b/source/funkin/backend/utils/TranslationUtil.hx @@ -67,11 +67,13 @@ class TranslationUtil * If `name` is not `null`, it will load the translations for the given language. */ public static function setLanguage(?name:String) { + #if TRANSLATIONS_SUPPORT if(name == null) name = curLanguage; transMap = loadLanguage(name); for(mod in ModsFolder.getLoadedModsLibs()) if(mod is TranslatedAssetLibrary) cast(mod, TranslatedAssetLibrary).langFolder = name.split("/")[0]; + #end } /**