//An example of a luxe early alpha preload parcel macro. //The macro loads a preload json file, and applies it //to a static member that the config function can use. //You could also use filesystem reads to populate this as an exercise. #if !macro @:build(PreloadAssetList.build()) class PreloadAssets { //this class gets populated by the build macro! //it looks like this, a variable named parcel: //var parcel: { json:[...], text:[...], } //and it is exactly the contents in the json } #end private typedef PreloadParcel = { ? bytes: Array, ? texts: Array, ? jsons: Array, ? textures: Array, ? fonts: Array, ? shaders: Array, ? sounds: Array } class PreloadAssetList { macro public static function build():Array { #if macro var path = haxe.macro.Context.resolvePath('preload.json'); var contents = sys.io.File.getContent(path); //instead of parsing the json file, you could use sys.Filesystem var parcel:PreloadParcel = haxe.Json.parse(contents); //The fields array is the list of class fields/members in our PreloadAssets class. var fields:Array = haxe.macro.Context.getBuildFields(); //we add one, and fill it with the contents of our parcel json fields.push({ name: "parcel", doc: "The parcel, as defined inside of preload.json", access: [APublic, AStatic], kind: FVar(macro :PreloadParcel, macro $v{parcel}), pos: haxe.macro.Context.currentPos(), }); return fields; #end } }