Compare commits
4 Commits
f88e9ce7d0
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| ce9f71470f | |||
| 34f56e93df | |||
| e64d86ee03 | |||
| 370ee3aabf |
@@ -25,4 +25,5 @@
|
||||
--macro keep("Main")
|
||||
--macro keep("Assets")
|
||||
--macro keep("AssetMacro")
|
||||
--macro macros.AssetMacro.includeAssets()
|
||||
# --macro macros.MacroLoader.run()
|
||||
@@ -25,7 +25,7 @@ class Main extends Sprite {
|
||||
}
|
||||
|
||||
// test a data asset
|
||||
var testAsset = dataLibrary.getText("img/placeholder.txt");
|
||||
var testAsset = dataLibrary.getText("txt/placeholder.txt");
|
||||
trace("Successfully loaded asset: " + testAsset);
|
||||
// test an image asset
|
||||
var testImage = imageLibrary.getImage("logo.png");
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package macros;
|
||||
|
||||
#if macro
|
||||
import haxe.macro.Context;
|
||||
import haxe.macro.Expr;
|
||||
import haxe.macro.Type;
|
||||
import sys.FileSystem;
|
||||
import sys.io.File;
|
||||
import haxe.Json;
|
||||
@@ -15,6 +15,11 @@ using StringTools;
|
||||
class AssetMacro {
|
||||
// Track all assets processed
|
||||
private static var assetMap:Map<String, Array<{id:String, path:String, size:Int, type:String}>> = new Map();
|
||||
|
||||
/** Force Assets to be typed, which invokes its @:build macro. */
|
||||
public static function includeAssets():Void {
|
||||
Context.getType("Assets");
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point for the macro - called during compilation
|
||||
@@ -41,7 +46,10 @@ class AssetMacro {
|
||||
var manifestDir = outputDir + "/manifest";
|
||||
var assetsOutputDir = outputDir + "/assets";
|
||||
|
||||
// Create directories if they don't exist
|
||||
// These directories are owned by this macro. Recreate them so removed or
|
||||
// renamed source assets cannot survive as stale build output.
|
||||
removeDirectory(manifestDir);
|
||||
removeDirectory(assetsOutputDir);
|
||||
createDirectory(manifestDir);
|
||||
createDirectory(assetsOutputDir);
|
||||
copyLimeNativeLibrary(outputDir);
|
||||
@@ -241,6 +249,20 @@ class AssetMacro {
|
||||
}
|
||||
}
|
||||
|
||||
private static function removeDirectory(path:String):Void {
|
||||
if (!FileSystem.exists(path)) return;
|
||||
|
||||
for (entry in FileSystem.readDirectory(path)) {
|
||||
var entryPath = path + "/" + entry;
|
||||
if (FileSystem.isDirectory(entryPath)) {
|
||||
removeDirectory(entryPath);
|
||||
} else {
|
||||
FileSystem.deleteFile(entryPath);
|
||||
}
|
||||
}
|
||||
FileSystem.deleteDirectory(path);
|
||||
}
|
||||
|
||||
/** Stage the Lime CFFI module that matches the selected haxelib version. */
|
||||
private static function copyLimeNativeLibrary(outputDir:String):Void {
|
||||
var platformDirectory = if (Context.defined("linux")) {
|
||||
@@ -312,4 +334,5 @@ class AssetMacro {
|
||||
default: "binary";
|
||||
}).toUpperCase();
|
||||
}
|
||||
}
|
||||
}
|
||||
#end
|
||||
|
||||
Reference in New Issue
Block a user