OKAY IT HALF WORKS
Co-Authored-By: Ne_Eo <NeeEoo@users.noreply.github.com>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package funkin.backend.assets;
|
||||
|
||||
import funkin.backend.assets.TranslatedAssetLibrary;
|
||||
import funkin.backend.assets.IModsAssetLibrary;
|
||||
import lime.utils.AssetLibrary;
|
||||
|
||||
@@ -11,6 +12,10 @@ class AssetsLibraryList extends AssetLibrary {
|
||||
private var __defaultLibraries:Array<AssetLibrary> = [];
|
||||
public var base:AssetLibrary;
|
||||
|
||||
#if TRANSLATIONS_SUPPORT
|
||||
public var transLib:TranslatedAssetLibrary;
|
||||
#end
|
||||
|
||||
public function removeLibrary(lib:AssetLibrary) {
|
||||
if (lib == null) return lib;
|
||||
libraries.remove(lib);
|
||||
@@ -121,6 +126,9 @@ class AssetsLibraryList extends AssetLibrary {
|
||||
}
|
||||
|
||||
private function shouldSkipLib(k:Int, source:AssetSource) {
|
||||
#if TRANSLATIONS_SUPPORT
|
||||
k -= libraries.indexOf(transLib) + 1;
|
||||
#end
|
||||
return switch(source) {
|
||||
case BOTH: false;
|
||||
case SOURCE: k < libraries.length - __defaultLibraries.length;
|
||||
@@ -136,10 +144,10 @@ class AssetsLibraryList extends AssetLibrary {
|
||||
|
||||
public function new(?base:AssetLibrary) {
|
||||
super();
|
||||
if (base == null)
|
||||
base = Assets.getLibrary("default");
|
||||
addLibrary(this.base = base);
|
||||
__defaultLibraries.push(base);
|
||||
#if TRANSLATIONS_SUPPORT
|
||||
__defaultLibraries.push(addLibrary(transLib = new TranslatedAssetLibrary(), BOTH));
|
||||
#end
|
||||
__defaultLibraries.push(addLibrary(this.base = (base == null ? Assets.getLibrary("default") : base), SOURCE));
|
||||
}
|
||||
|
||||
public function unloadLibraries() {
|
||||
@@ -158,8 +166,9 @@ class AssetsLibraryList extends AssetLibrary {
|
||||
addLibrary(d);
|
||||
}
|
||||
|
||||
public function addLibrary(lib:AssetLibrary) {
|
||||
libraries.insert(0, lib);
|
||||
public function addLibrary(lib:AssetLibrary, tag:AssetSource = MODS) {
|
||||
libraries.insert(#if TRANSLATIONS_SUPPORT libraries.indexOf(transLib) + 1 #else 0 #end, lib);
|
||||
lib.tag = tag;
|
||||
return lib;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,7 +102,7 @@ class ModsFolder {
|
||||
#end
|
||||
return mods;
|
||||
}
|
||||
public static function getLoadedModsLibs():Array<IModsAssetLibrary> {
|
||||
public static function getLoadedModsLibs(skipTranslated:Bool = false):Array<IModsAssetLibrary> {
|
||||
var libs = [];
|
||||
for (i in Paths.assetsTree.libraries) {
|
||||
var l = i;
|
||||
@@ -111,12 +111,13 @@ class ModsFolder {
|
||||
@:privateAccess
|
||||
if (al.__proxy != null) l = al.__proxy;
|
||||
}
|
||||
if(skipTranslated && (l is TranslatedAssetLibrary)) continue;
|
||||
if (l is ScriptedAssetLibrary || l is IModsAssetLibrary) libs.push(cast(l, IModsAssetLibrary));
|
||||
}
|
||||
return libs;
|
||||
}
|
||||
public static function getLoadedMods():Array<String>
|
||||
return [for (modLib in getLoadedModsLibs()) modLib.modName];
|
||||
public static function getLoadedMods(skipTranslated:Bool = false):Array<String>
|
||||
return [for (modLib in getLoadedModsLibs(skipTranslated)) modLib.modName];
|
||||
|
||||
public static function prepareLibrary(libName:String, force:Bool = false) {
|
||||
var assets:AssetManifest = new AssetManifest();
|
||||
|
||||
@@ -32,16 +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
|
||||
public inline function formatPath(mainPath:String, ?asset:String):String {
|
||||
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 TranslatedAssetLibrary || !(lib is AssetLibrary)) continue;
|
||||
var val = cast(lib, AssetLibrary).getAudioBuffer(formatPath(lib.basePath, id));
|
||||
for(lib in ModsFolder.getLoadedModsLibs(true)) {
|
||||
if(!(lib is AssetLibrary)) continue;
|
||||
var val = cast(lib, AssetLibrary).getAudioBuffer(formatPath(lib.prefix, id));
|
||||
if(val != null) return val;
|
||||
}
|
||||
return null;
|
||||
@@ -49,9 +49,9 @@ class TranslatedAssetLibrary extends AssetLibrary implements IModsAssetLibrary {
|
||||
|
||||
public override function getBytes(id:String):Bytes
|
||||
{
|
||||
for(lib in ModsFolder.getLoadedModsLibs()) {
|
||||
if(lib is TranslatedAssetLibrary || !(lib is AssetLibrary)) continue;
|
||||
var val = cast(lib, AssetLibrary).getBytes(formatPath(lib.basePath, id));
|
||||
for(lib in ModsFolder.getLoadedModsLibs(true)) {
|
||||
if(!(lib is AssetLibrary)) continue;
|
||||
var val = cast(lib, AssetLibrary).getBytes(formatPath(lib.prefix, id));
|
||||
if(val != null) return val;
|
||||
}
|
||||
return null;
|
||||
@@ -59,9 +59,9 @@ class TranslatedAssetLibrary extends AssetLibrary implements IModsAssetLibrary {
|
||||
|
||||
public override function getFont(id:String):Font
|
||||
{
|
||||
for(lib in ModsFolder.getLoadedModsLibs()) {
|
||||
if(lib is TranslatedAssetLibrary || !(lib is AssetLibrary)) continue;
|
||||
var val = cast(lib, AssetLibrary).getFont(formatPath(lib.basePath, id));
|
||||
for(lib in ModsFolder.getLoadedModsLibs(true)) {
|
||||
if(!(lib is AssetLibrary)) continue;
|
||||
var val = cast(lib, AssetLibrary).getFont(formatPath(lib.prefix, id));
|
||||
if(val != null) return val;
|
||||
}
|
||||
return null;
|
||||
@@ -69,9 +69,9 @@ class TranslatedAssetLibrary extends AssetLibrary implements IModsAssetLibrary {
|
||||
|
||||
public override function getImage(id:String):Image
|
||||
{
|
||||
for(lib in ModsFolder.getLoadedModsLibs()) {
|
||||
if(lib is TranslatedAssetLibrary || !(lib is AssetLibrary)) continue;
|
||||
var val = cast(lib, AssetLibrary).getImage(formatPath(lib.basePath, id));
|
||||
for(lib in ModsFolder.getLoadedModsLibs(true)) {
|
||||
if(!(lib is AssetLibrary)) continue;
|
||||
var val = cast(lib, AssetLibrary).getImage(formatPath(lib.prefix, id));
|
||||
if(val != null) return val;
|
||||
}
|
||||
return null;
|
||||
@@ -79,9 +79,9 @@ class TranslatedAssetLibrary extends AssetLibrary implements IModsAssetLibrary {
|
||||
|
||||
public override function getPath(id:String):String
|
||||
{
|
||||
for(lib in ModsFolder.getLoadedModsLibs()) {
|
||||
if(lib is TranslatedAssetLibrary || !(lib is AssetLibrary)) continue;
|
||||
var val = cast(lib, AssetLibrary).getPath(formatPath(lib.basePath, id));
|
||||
for(lib in ModsFolder.getLoadedModsLibs(true)) {
|
||||
if(!(lib is AssetLibrary)) continue;
|
||||
var val = cast(lib, AssetLibrary).getPath(formatPath(lib.prefix, id));
|
||||
if(val != null) return val;
|
||||
}
|
||||
return null;
|
||||
@@ -92,28 +92,28 @@ class TranslatedAssetLibrary extends AssetLibrary implements IModsAssetLibrary {
|
||||
|
||||
public function getFiles(folder:String):Array<String>
|
||||
{
|
||||
for(lib in ModsFolder.getLoadedModsLibs()) {
|
||||
if(lib is TranslatedAssetLibrary) continue;
|
||||
var val = lib.getFiles(formatPath(lib.basePath, folder));
|
||||
if(val != []) return val;
|
||||
for(lib in ModsFolder.getLoadedModsLibs(true)) {
|
||||
if(!(lib is AssetLibrary)) continue;
|
||||
var val = lib.getFiles(formatPath(lib.prefix, folder));
|
||||
if(val != null && val.length > 0) return val;
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getFolders(folder:String):Array<String>
|
||||
{
|
||||
for(lib in ModsFolder.getLoadedModsLibs()) {
|
||||
if(lib is TranslatedAssetLibrary) continue;
|
||||
var val = lib.getFolders(formatPath(lib.basePath, folder));
|
||||
if(val != []) return val;
|
||||
for(lib in ModsFolder.getLoadedModsLibs(true)) {
|
||||
if(!(lib is AssetLibrary)) continue;
|
||||
var val = lib.getFolders(formatPath(lib.prefix, folder));
|
||||
if(val != null && val.length > 0) return val;
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
private function __isCacheValid(cache:Map<String, Dynamic>, asset:String, isLocal:Bool = false):Bool
|
||||
{
|
||||
for(lib in ModsFolder.getLoadedModsLibs()) {
|
||||
if(lib is TranslatedAssetLibrary || !(lib is AssetLibrary)) continue;
|
||||
for(lib in ModsFolder.getLoadedModsLibs(true)) {
|
||||
if(!(lib is AssetLibrary)) continue;
|
||||
|
||||
// are you fucking serious (no the fucking switch doesnt work here) - Nex
|
||||
var _lib = cast(lib, AssetLibrary);
|
||||
@@ -123,7 +123,7 @@ class TranslatedAssetLibrary extends AssetLibrary implements IModsAssetLibrary {
|
||||
(cache == cachedImages) ? _lib.cachedImages :
|
||||
(cache == cachedText) ? _lib.cachedText : cache;
|
||||
|
||||
@:privateAccess if(lib.__isCacheValid(libCache, formatPath(lib.basePath, asset), isLocal)) return true;
|
||||
@:privateAccess if(lib.__isCacheValid(libCache, formatPath(lib.prefix, asset), isLocal)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -131,14 +131,17 @@ class TranslatedAssetLibrary extends AssetLibrary implements IModsAssetLibrary {
|
||||
private function __parseAsset(asset:String):Bool
|
||||
{
|
||||
@:privateAccess
|
||||
for(lib in ModsFolder.getLoadedModsLibs()) if(!(lib is TranslatedAssetLibrary) && lib.__parseAsset(formatPath(lib.basePath, asset))) return true;
|
||||
for(lib in ModsFolder.getLoadedModsLibs(true)) {
|
||||
if(!(lib is AssetLibrary)) continue;
|
||||
if(lib.__parseAsset(formatPath(lib.prefix, asset))) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
#end
|
||||
|
||||
public override function exists(id:String, type:String):Bool
|
||||
{
|
||||
for(lib in ModsFolder.getLoadedModsLibs()) if(!(lib is TranslatedAssetLibrary) && lib is AssetLibrary && cast(lib, AssetLibrary).exists(formatPath(lib.basePath, id), type)) return true;
|
||||
for(lib in ModsFolder.getLoadedModsLibs(true)) if(lib is AssetLibrary && cast(lib, AssetLibrary).exists(formatPath(lib.prefix, id), type)) return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -114,10 +114,6 @@ 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
|
||||
|
||||
@@ -72,7 +72,6 @@ class MainState extends FlxState {
|
||||
#if windows
|
||||
try new funkin.backend.utils.native.HiddenProcess("attrib +h .temp")
|
||||
catch(e) Logs.trace('Failed to set hidden attribute on .temp folder', WARNING);
|
||||
#end
|
||||
#end
|
||||
#end #end
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package funkin.backend.system.macros;
|
||||
|
||||
#if macro
|
||||
import haxe.macro.Context;
|
||||
import haxe.macro.Expr;
|
||||
import haxe.macro.Compiler;
|
||||
|
||||
using StringTools;
|
||||
|
||||
/**
|
||||
* Macro used to add custom fields to classes without having to override the entire file.
|
||||
*/
|
||||
class CustomFieldMacro {
|
||||
public static function init() {
|
||||
Compiler.addGlobalMetadata("lime.utils", '@:build(funkin.backend.system.macros.UsingHandler.build("lime.utils.AssetLibrary", "tag", "funkin.backend.assets.AssetSource"))');
|
||||
}
|
||||
|
||||
// TODO: Add support for default values
|
||||
public static function build(lib:String, fieldName:String, type:String) {
|
||||
var fields = Context.getBuildFields();
|
||||
var clRef = Context.getLocalClass();
|
||||
if (clRef == null) return fields;
|
||||
var cl = clRef.get();
|
||||
|
||||
var key = cl.module;
|
||||
var fkey = cl.module + "." + cl.name;
|
||||
|
||||
if(fkey != lib) {
|
||||
return fields;
|
||||
}
|
||||
|
||||
var fields = Context.getBuildFields();
|
||||
|
||||
fields.push({
|
||||
name: fieldName,
|
||||
access: [APublic],
|
||||
kind: FVar(getTPath(type)),
|
||||
pos: Context.currentPos()
|
||||
});
|
||||
|
||||
return fields;
|
||||
}
|
||||
|
||||
public static function getTPath(type:String) {
|
||||
var arr = type.split(".");
|
||||
return TPath({
|
||||
pack: arr.slice(0, arr.length - 1),
|
||||
name: arr[arr.length - 1]
|
||||
});
|
||||
}
|
||||
}
|
||||
#end
|
||||
@@ -45,6 +45,8 @@ class Macros {
|
||||
public static function initMacros() {
|
||||
if(Context.defined("hl"))
|
||||
HashLinkFixer.init();
|
||||
|
||||
CustomFieldsMacro.init();
|
||||
}
|
||||
}
|
||||
#end
|
||||
Reference in New Issue
Block a user