WIP
This commit is contained in:
@@ -1,15 +1,9 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
# Compile the project using the Haxe compiler with the specified build.hxml configuration
|
||||
haxe build.hxml
|
||||
|
||||
# Check if the compilation was successful
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "Compilation successful!"
|
||||
else
|
||||
echo "Compilation failed!"
|
||||
fi
|
||||
|
||||
# Run the compiled project
|
||||
# We need to run ApplicationMain-debug within the bin/cpp directory as the current working directory
|
||||
(cd ./bin/cpp; ./ApplicationMain-debug)
|
||||
# Run beside the staged manifest, assets and native libraries.
|
||||
(cd ./bin/cpp; ./ApplicationMain)
|
||||
@@ -9,8 +9,6 @@ class Main extends Sprite {
|
||||
public function new() {
|
||||
super();
|
||||
|
||||
Lib.current.addChild(this);
|
||||
|
||||
// Draw background to verify app is running
|
||||
graphics.beginFill(0x3498db, 1);
|
||||
graphics.drawRect(0, 0, 800, 600);
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
package;
|
||||
|
||||
#if sys
|
||||
import haxe.io.Path;
|
||||
import openfl.utils.AssetLibrary;
|
||||
import openfl.utils.AssetManifest;
|
||||
import openfl.utils.Assets as LimeAssets;
|
||||
import lime.utils.AssetLibrary;
|
||||
import lime.utils.Assets;
|
||||
import sys.FileSystem;
|
||||
|
||||
@:access(lime.utils.Assets)
|
||||
@@ -14,44 +12,32 @@ import sys.FileSystem;
|
||||
public static var rootPath:String;
|
||||
|
||||
public static function init(config:Dynamic):Void {
|
||||
rootPath = "";
|
||||
preloadLibraries = [];
|
||||
preloadLibraryNames = [];
|
||||
rootPath = null;
|
||||
|
||||
if (config != null && Reflect.hasField(config, "rootPath")) {
|
||||
rootPath = Reflect.field(config, "rootPath");
|
||||
if (!StringTools.endsWith(rootPath, "/")) rootPath += "/";
|
||||
}
|
||||
if (rootPath == null) rootPath = lime.system.System.applicationDirectory;
|
||||
|
||||
var manifestDirPath = Path.join([rootPath, "manifest"]);
|
||||
if (!FileSystem.exists(manifestDirPath) || !FileSystem.isDirectory(manifestDirPath)) {
|
||||
throw 'Asset manifest directory not found: $manifestDirPath';
|
||||
}
|
||||
|
||||
var manifestDirPath = Path.join(["manifest"]);
|
||||
var manifests = FileSystem.readDirectory(manifestDirPath);
|
||||
manifests.sort(Reflect.compare);
|
||||
for (manifest in manifests) {
|
||||
trace(manifest);
|
||||
if (StringTools.endsWith(manifest, ".json")) {
|
||||
var manifestPath = Path.join([manifestDirPath, manifest]);
|
||||
loadManifest(manifestPath, manifest.split(".json")[0]);
|
||||
}
|
||||
else{
|
||||
throw("we eating shit tonight");
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
var manifestName = Path.withoutExtension(manifest);
|
||||
Assets.libraryPaths[manifestName] = Path.join([manifestDirPath, manifest]);
|
||||
|
||||
public static function loadManifest(manifestPath, manifestName) {
|
||||
if (!FileSystem.exists(manifestPath)) {
|
||||
trace("Manifest file not found: " + manifestPath);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
var manifest = AssetManifest.fromFile(manifestPath);
|
||||
if (manifest != null) {
|
||||
var library = AssetLibrary.fromManifest(manifest);
|
||||
if (library != null) {
|
||||
trace("Library: `"+library+"`");
|
||||
trace("manifestName: `"+manifestName+"`");
|
||||
preloadLibraries.push(library);
|
||||
preloadLibraryNames.push(manifestName);
|
||||
// LimeAssets.registerLibrary(manifestName, library);
|
||||
openfl.utils.Assets.registerLibrary(manifestName, library);
|
||||
}
|
||||
var library = Assets.getLibrary(manifestName);
|
||||
if (library != null) preloadLibraries.push(library);
|
||||
else preloadLibraryNames.push(manifestName);
|
||||
}
|
||||
} catch (e:Dynamic) {
|
||||
trace("Error loading asset manifest: " + e);
|
||||
}
|
||||
}
|
||||
}
|
||||
#end
|
||||
|
||||
@@ -25,6 +25,9 @@ class AssetMacro {
|
||||
Context.warning("AssetMacro is running", Context.currentPos());
|
||||
#end
|
||||
|
||||
// A compilation server can retain macro statics between builds.
|
||||
assetMap = new Map();
|
||||
|
||||
// Get current build context
|
||||
var fields = Context.getBuildFields();
|
||||
var localClass = Context.getLocalClass().get();
|
||||
@@ -41,6 +44,7 @@ class AssetMacro {
|
||||
// Create directories if they don't exist
|
||||
createDirectory(manifestDir);
|
||||
createDirectory(assetsOutputDir);
|
||||
copyLimeNativeLibrary(outputDir);
|
||||
|
||||
// Process asset fields
|
||||
for (field in fields) {
|
||||
@@ -237,6 +241,44 @@ class AssetMacro {
|
||||
}
|
||||
}
|
||||
|
||||
/** Stage the Lime CFFI module that matches the selected haxelib version. */
|
||||
private static function copyLimeNativeLibrary(outputDir:String):Void {
|
||||
var platformDirectory = if (Context.defined("linux")) {
|
||||
"Linux64";
|
||||
} else if (Context.defined("windows")) {
|
||||
"Windows64";
|
||||
} else if (Context.defined("mac")) {
|
||||
Context.defined("arm64") ? "MacArm64" : "Mac64";
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
var limeRoot:String = null;
|
||||
for (classPath in Context.getClassPath()) {
|
||||
var normalized = classPath.split("\\").join("/");
|
||||
if (normalized.indexOf("/lime/") != -1 && normalized.endsWith("/src/")) {
|
||||
limeRoot = normalized.substr(0, normalized.length - 4);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (limeRoot == null) {
|
||||
Context.warning("Could not locate Lime native library from the compiler class path", Context.currentPos());
|
||||
return;
|
||||
}
|
||||
|
||||
var source = limeRoot + "ndll/" + platformDirectory + "/lime.ndll";
|
||||
if (!FileSystem.exists(source)) {
|
||||
Context.warning("Lime native library not found: " + source, Context.currentPos());
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
File.copy(source, outputDir + "/lime.ndll");
|
||||
} catch (e:Dynamic) {
|
||||
Context.error("Failed to copy Lime native library: " + e, Context.currentPos());
|
||||
}
|
||||
}
|
||||
|
||||
private static function findAssetsMeta(metaAccess:Array<MetadataEntry>):MetadataEntry {
|
||||
if (metaAccess == null) return null;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user