package funkin.util.macro; import haxe.rtti.Meta; /** * A complement to `ClassMacro`. See `ClassMacro` for more information. */ class CompiledClassList { static var classLists:Map>>; /** * Class lists are injected into this class's metadata during the typing phase. * This function extracts the metadata, at runtime, and stores it in `classLists`. */ static function init():Void { classLists = []; // Meta.getType returns Dynamic>. var metaData = Meta.getType(CompiledClassList); if (metaData.classLists != null) { for (list in metaData.classLists) { var data:Array = cast list; // First element is the list ID. var id:String = cast data[0]; // All other elements are class types. var classes:List> = new List(); for (i in 1...data.length) { var className:String = cast data[i]; // var classType:Class = cast data[i]; var classType:Class = cast Type.resolveClass(className); classes.push(classType); } classLists.set(id, classes); } } else { throw "Class lists not properly generated. Try cleaning out your export folder, restarting your IDE, and rebuilding your project."; } } public static function get(request:String):List> { if (classLists == null) init(); if (!classLists.exists(request)) { trace('[WARNING] Class list $request not properly generated. Please debug the build macro.'); classLists.set(request, new List()); // Make the error only appear once. } return classLists.get(request); } public static inline function getTyped(request:String, type:Class):List> { return cast get(request); } }