OKAY IT HALF WORKS

Co-Authored-By: Ne_Eo <NeeEoo@users.noreply.github.com>
This commit is contained in:
⍚~Nex
2024-04-09 17:18:29 +02:00
co-authored by Ne_Eo
parent f153ed3696
commit f9c74c5a2d
7 changed files with 106 additions and 44 deletions
-4
View File
@@ -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
+1 -2
View File
@@ -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