Compare commits
4 Commits
f88e9ce7d0
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| ce9f71470f | |||
| 34f56e93df | |||
| e64d86ee03 | |||
| 370ee3aabf |
@@ -25,4 +25,5 @@
|
|||||||
--macro keep("Main")
|
--macro keep("Main")
|
||||||
--macro keep("Assets")
|
--macro keep("Assets")
|
||||||
--macro keep("AssetMacro")
|
--macro keep("AssetMacro")
|
||||||
|
--macro macros.AssetMacro.includeAssets()
|
||||||
# --macro macros.MacroLoader.run()
|
# --macro macros.MacroLoader.run()
|
||||||
@@ -25,7 +25,7 @@ class Main extends Sprite {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// test a data asset
|
// test a data asset
|
||||||
var testAsset = dataLibrary.getText("img/placeholder.txt");
|
var testAsset = dataLibrary.getText("txt/placeholder.txt");
|
||||||
trace("Successfully loaded asset: " + testAsset);
|
trace("Successfully loaded asset: " + testAsset);
|
||||||
// test an image asset
|
// test an image asset
|
||||||
var testImage = imageLibrary.getImage("logo.png");
|
var testImage = imageLibrary.getImage("logo.png");
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package macros;
|
package macros;
|
||||||
|
|
||||||
|
#if macro
|
||||||
import haxe.macro.Context;
|
import haxe.macro.Context;
|
||||||
import haxe.macro.Expr;
|
import haxe.macro.Expr;
|
||||||
import haxe.macro.Type;
|
|
||||||
import sys.FileSystem;
|
import sys.FileSystem;
|
||||||
import sys.io.File;
|
import sys.io.File;
|
||||||
import haxe.Json;
|
import haxe.Json;
|
||||||
@@ -16,6 +16,11 @@ class AssetMacro {
|
|||||||
// Track all assets processed
|
// Track all assets processed
|
||||||
private static var assetMap:Map<String, Array<{id:String, path:String, size:Int, type:String}>> = new Map();
|
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
|
* Entry point for the macro - called during compilation
|
||||||
*/
|
*/
|
||||||
@@ -41,7 +46,10 @@ class AssetMacro {
|
|||||||
var manifestDir = outputDir + "/manifest";
|
var manifestDir = outputDir + "/manifest";
|
||||||
var assetsOutputDir = outputDir + "/assets";
|
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(manifestDir);
|
||||||
createDirectory(assetsOutputDir);
|
createDirectory(assetsOutputDir);
|
||||||
copyLimeNativeLibrary(outputDir);
|
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. */
|
/** Stage the Lime CFFI module that matches the selected haxelib version. */
|
||||||
private static function copyLimeNativeLibrary(outputDir:String):Void {
|
private static function copyLimeNativeLibrary(outputDir:String):Void {
|
||||||
var platformDirectory = if (Context.defined("linux")) {
|
var platformDirectory = if (Context.defined("linux")) {
|
||||||
@@ -313,3 +335,4 @@ class AssetMacro {
|
|||||||
}).toUpperCase();
|
}).toUpperCase();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#end
|
||||||
|
|||||||
Reference in New Issue
Block a user