Improved Macros + Libraries (WIP)
Co-Authored-By: ⍚~Nex <87421482+NexIsDumb@users.noreply.github.com>
This commit is contained in:
committed by
⍚~Nex
co-authored by
⍚~Nex
parent
f9c74c5a2d
commit
e068300cf1
@@ -42,6 +42,9 @@ class Update {
|
||||
case "git":
|
||||
prettyPrint((lib.global == "true" ? "Globally installing" : "Locally installing") + ' "${lib.name}" from git url "${lib.url}"');
|
||||
Sys.command('haxelib git ${lib.name} ${lib.url}${lib.ref != null ? ' ${lib.ref}' : ''}${globalism != null ? ' $globalism' : ''} --always');
|
||||
case "custom":
|
||||
Sys.command('haxelib dev ${lib.name} "./libraries/${lib.name}"');
|
||||
|
||||
default:
|
||||
prettyPrint('Cannot resolve library of type "${lib.type}"');
|
||||
}
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
--macro macros.CustomFieldMacro.init()
|
||||
--macro macros.HashLinkFixer.init()
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"name": "custom-fields-macro",
|
||||
"url": "https://example.com/",
|
||||
"license": "Public",
|
||||
"description": "A fix",
|
||||
"version": "1.0.0",
|
||||
"releasenote": "NOTHING",
|
||||
"contributors": ["NeeEoo"]
|
||||
}
|
||||
+3
-3
@@ -1,4 +1,4 @@
|
||||
package funkin.backend.system.macros;
|
||||
package macros;
|
||||
|
||||
#if macro
|
||||
import haxe.macro.Context;
|
||||
@@ -12,7 +12,7 @@ using StringTools;
|
||||
*/
|
||||
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"))');
|
||||
Compiler.addGlobalMetadata("lime.utils", '@:build(macros.CustomFieldMacro.build("lime.utils.AssetLibrary", "tag", "funkin.backend.assets.AssetSource"))');
|
||||
}
|
||||
|
||||
// TODO: Add support for default values
|
||||
@@ -25,7 +25,7 @@ class CustomFieldMacro {
|
||||
var key = cl.module;
|
||||
var fkey = cl.module + "." + cl.name;
|
||||
|
||||
if(fkey != lib) {
|
||||
if(lib != cl.module) {
|
||||
return fields;
|
||||
}
|
||||
|
||||
+3
-3
@@ -1,4 +1,4 @@
|
||||
package funkin.backend.system.macros;
|
||||
package macros;
|
||||
|
||||
#if macro
|
||||
import haxe.macro.Expr;
|
||||
@@ -8,7 +8,7 @@ using StringTools;
|
||||
using haxe.macro.PositionTools;
|
||||
|
||||
class HashLinkFixer {
|
||||
public static var buildMacroString = '@:build(funkin.backend.system.macros.HashLinkFixer.build())';
|
||||
public static var buildMacroString = '@:build(macros.HashLinkFixer.build())';
|
||||
|
||||
public static var applyOn:Array<String> = [
|
||||
"lime",
|
||||
@@ -133,7 +133,7 @@ class HashLinkFixer {
|
||||
helperClass.name = hcClassName;
|
||||
|
||||
if(definedFields.length > 0) {
|
||||
trace(cl.module);
|
||||
//trace(cl.module);
|
||||
|
||||
/*for(m in metas.copy()) {
|
||||
trace(" " + m.name);
|
||||
@@ -19,4 +19,6 @@
|
||||
<!-- <lib name="dox" /> -->
|
||||
<lib name="format" />
|
||||
<lib name="markdown" />
|
||||
|
||||
<custom name="macro-fixer" />
|
||||
</libraries>
|
||||
|
||||
@@ -183,6 +183,9 @@
|
||||
<haxelib name="hxdiscord_rpc" if="DISCORD_RPC"/>
|
||||
<haxelib name="markdown" />
|
||||
|
||||
<!-- Custom Libraries -->
|
||||
<haxelib name="macro-fixer" />
|
||||
|
||||
<!-- _________________________________ Additional stuff _______________________________ -->
|
||||
|
||||
<section if="COMPILE_ALL_CLASSES">
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package funkin.backend.assets;
|
||||
|
||||
enum abstract AssetSource(Null<Bool>) from Bool from Null<Bool> to Null<Bool> {
|
||||
var SOURCE = true;
|
||||
var MODS = false;
|
||||
var BOTH = null;
|
||||
}
|
||||
@@ -22,10 +22,10 @@ class AssetsLibraryList extends AssetLibrary {
|
||||
return lib;
|
||||
}
|
||||
public function existsSpecific(id:String, type:String, source:AssetSource = BOTH) {
|
||||
if (!id.startsWith("assets/") && exists('assets/$id', type))
|
||||
if (!id.startsWith("assets/") && existsSpecific('assets/$id', type, source))
|
||||
return true;
|
||||
for(k=>e in libraries) {
|
||||
if (shouldSkipLib(k, source)) continue;
|
||||
if (shouldSkipLib(e, source)) continue;
|
||||
if (e.exists(id, type))
|
||||
return true;
|
||||
}
|
||||
@@ -36,7 +36,7 @@ class AssetsLibraryList extends AssetLibrary {
|
||||
|
||||
public function getSpecificPath(id:String, source:AssetSource = BOTH) {
|
||||
for(k=>e in libraries) {
|
||||
if (shouldSkipLib(k, source)) continue;
|
||||
if (shouldSkipLib(e, source)) continue;
|
||||
|
||||
@:privateAccess
|
||||
if (e.exists(id, e.types.get(id))) {
|
||||
@@ -54,7 +54,7 @@ class AssetsLibraryList extends AssetLibrary {
|
||||
public function getFiles(folder:String, source:AssetSource = BOTH):Array<String> {
|
||||
var content:Array<String> = [];
|
||||
for(k=>e in libraries) {
|
||||
if (shouldSkipLib(k, source)) continue;
|
||||
if (shouldSkipLib(e, source)) continue;
|
||||
|
||||
var l = e;
|
||||
|
||||
@@ -78,7 +78,7 @@ class AssetsLibraryList extends AssetLibrary {
|
||||
public function getFolders(folder:String, source:AssetSource = BOTH):Array<String> {
|
||||
var content:Array<String> = [];
|
||||
for(k=>e in libraries) {
|
||||
if (shouldSkipLib(k, source)) continue;
|
||||
if (shouldSkipLib(e, source)) continue;
|
||||
|
||||
var l = e;
|
||||
|
||||
@@ -108,7 +108,7 @@ class AssetsLibraryList extends AssetLibrary {
|
||||
}
|
||||
}
|
||||
for(k=>e in libraries) {
|
||||
if (shouldSkipLib(k, source)) continue;
|
||||
if (shouldSkipLib(e, source)) continue;
|
||||
|
||||
@:privateAccess
|
||||
if (e.exists(id, e.types.get(id))) {
|
||||
@@ -125,15 +125,9 @@ class AssetsLibraryList extends AssetLibrary {
|
||||
return null;
|
||||
}
|
||||
|
||||
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;
|
||||
case MODS: k >= libraries.length - __defaultLibraries.length;
|
||||
};
|
||||
private function shouldSkipLib(lib:AssetLibrary, source:AssetSource) {
|
||||
if (source == BOTH || lib.tag == BOTH) return false;
|
||||
return source != lib.tag;
|
||||
}
|
||||
public override inline function getAsset(id:String, type:String):Dynamic
|
||||
return getSpecificAsset(id, type, BOTH);
|
||||
@@ -171,10 +165,4 @@ class AssetsLibraryList extends AssetLibrary {
|
||||
lib.tag = tag;
|
||||
return lib;
|
||||
}
|
||||
}
|
||||
|
||||
enum abstract AssetSource(Null<Bool>) from Bool from Null<Bool> to Null<Bool> {
|
||||
var SOURCE = true;
|
||||
var MODS = false;
|
||||
var BOTH = null;
|
||||
}
|
||||
@@ -48,8 +48,10 @@ class ModsFolder {
|
||||
* Initialises `mods` folder.
|
||||
*/
|
||||
public static function init() {
|
||||
if(!getModsList().contains(Options.lastLoadedMod))
|
||||
if(!getModsList().contains(Options.lastLoadedMod)) {
|
||||
Options.lastLoadedMod = null;
|
||||
Logs.trace("Mod not found in mods list, switching to base game!", WARNING, YELLOW);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -59,6 +61,10 @@ class ModsFolder {
|
||||
public static function switchMod(mod:String) {
|
||||
Options.lastLoadedMod = currentModFolder = mod;
|
||||
reloadMods();
|
||||
Logs.traceColored([
|
||||
Logs.logText('Switched to mod ', GRAY),
|
||||
Logs.logText(mod, GREEN)
|
||||
], VERBOSE);
|
||||
}
|
||||
|
||||
public static function reloadMods() {
|
||||
|
||||
@@ -236,7 +236,7 @@ class Paths
|
||||
return graph.imageFrame;
|
||||
}
|
||||
|
||||
public static function getFolderDirectories(key:String, addPath:Bool = false, source:AssetsLibraryList.AssetSource = BOTH):Array<String> {
|
||||
public static function getFolderDirectories(key:String, addPath:Bool = false, source:AssetSource = BOTH):Array<String> {
|
||||
if (!key.endsWith("/")) key += "/";
|
||||
var content = assetsTree.getFolders('assets/$key', source);
|
||||
if (addPath) {
|
||||
@@ -246,7 +246,7 @@ class Paths
|
||||
return content;
|
||||
}
|
||||
|
||||
public static function getFolderContent(key:String, addPath:Bool = false, source:AssetsLibraryList.AssetSource = BOTH):Array<String> {
|
||||
public static function getFolderContent(key:String, addPath:Bool = false, source:AssetSource = BOTH):Array<String> {
|
||||
// designed to work both on windows and web
|
||||
if (!key.endsWith("/")) key += "/";
|
||||
var content = assetsTree.getFiles('assets/$key', source);
|
||||
|
||||
@@ -57,6 +57,16 @@ class TranslatedAssetLibrary extends AssetLibrary implements IModsAssetLibrary {
|
||||
return null;
|
||||
}
|
||||
|
||||
public override function getText(id:String):String
|
||||
{
|
||||
for(lib in ModsFolder.getLoadedModsLibs(true)) {
|
||||
if(!(lib is AssetLibrary)) continue;
|
||||
var val = cast(lib, AssetLibrary).getText(formatPath(lib.prefix, id));
|
||||
if(val != null) return val;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public override function getFont(id:String):Font
|
||||
{
|
||||
for(lib in ModsFolder.getLoadedModsLibs(true)) {
|
||||
|
||||
@@ -43,10 +43,6 @@ class Macros {
|
||||
}
|
||||
|
||||
public static function initMacros() {
|
||||
if(Context.defined("hl"))
|
||||
HashLinkFixer.init();
|
||||
|
||||
CustomFieldsMacro.init();
|
||||
}
|
||||
}
|
||||
#end
|
||||
@@ -125,7 +125,7 @@ class TranslationUtil
|
||||
}
|
||||
if (xml == null) return [];
|
||||
if (!xml.hasNode.translations) {
|
||||
FlxG.log.warn("A translation xml file requires a translations root element.");
|
||||
Logs.trace("A translation xml file requires a translations root element.", WARNING, YELLOW);
|
||||
return [];
|
||||
}
|
||||
|
||||
|
||||
@@ -430,7 +430,7 @@ class FreeplaySonglist {
|
||||
|
||||
public function new() {}
|
||||
|
||||
public function getSongsFromSource(source:funkin.backend.assets.AssetsLibraryList.AssetSource, useTxt:Bool = true) {
|
||||
public function getSongsFromSource(source:funkin.backend.assets.AssetSource, useTxt:Bool = true) {
|
||||
var path:String = Paths.txt('freeplaySonglist');
|
||||
var songsFound:Array<String> = [];
|
||||
if (useTxt && Paths.assetsTree.existsSpecific(path, "TEXT", source)) {
|
||||
|
||||
@@ -297,7 +297,7 @@ class StoryMenuState extends MusicBeatState {
|
||||
characters[charName] = charObj;
|
||||
}
|
||||
|
||||
public function getWeeksFromSource(weeks:Array<String>, source:funkin.backend.assets.AssetsLibraryList.AssetSource) {
|
||||
public function getWeeksFromSource(weeks:Array<String>, source:funkin.backend.assets.AssetSource) {
|
||||
var path:String = Paths.txt('freeplaySonglist');
|
||||
var weeksFound:Array<String> = [];
|
||||
if (Paths.assetsTree.existsSpecific(path, "TEXT", source)) {
|
||||
|
||||
@@ -20,7 +20,7 @@ class CreditsMain extends TreeMenu {
|
||||
|
||||
var selectables:Array<OptionType> = [];
|
||||
var xmlPath = Paths.xml('config/credits');
|
||||
for(source in [funkin.backend.assets.AssetsLibraryList.AssetSource.SOURCE, funkin.backend.assets.AssetsLibraryList.AssetSource.MODS]) {
|
||||
for(source in [funkin.backend.assets.AssetSource.SOURCE, funkin.backend.assets.AssetSource.MODS]) {
|
||||
if (Paths.assetsTree.existsSpecific(xmlPath, "TEXT", source)) {
|
||||
var access:Access = null;
|
||||
try {
|
||||
|
||||
@@ -69,7 +69,7 @@ class OptionsMenu extends TreeMenu {
|
||||
})]);
|
||||
|
||||
var xmlPath = Paths.xml("config/options");
|
||||
for(source in [funkin.backend.assets.AssetsLibraryList.AssetSource.SOURCE, funkin.backend.assets.AssetsLibraryList.AssetSource.MODS]) {
|
||||
for(source in [funkin.backend.assets.AssetSource.SOURCE, funkin.backend.assets.AssetSource.MODS]) {
|
||||
if (Paths.assetsTree.existsSpecific(xmlPath, "TEXT", source)) {
|
||||
var access:Access = null;
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user