Compare commits
3 Commits
d73b8bb02e
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 31d458f8b7 | |||
| 3c35a616cc | |||
| e01cc817ef |
@@ -24,6 +24,6 @@ class Assets {
|
||||
public static var data:String;
|
||||
|
||||
// You can also define individual files if needed
|
||||
@:Assets("assets/images/logo.png", "images", "logo.png")
|
||||
public static var logo:String;
|
||||
// @:Assets("assets/images/logo.png", "images", "logo.png")
|
||||
// public static var logo:String;
|
||||
}
|
||||
@@ -16,7 +16,29 @@ class Main extends Sprite {
|
||||
graphics.drawRect(0, 0, 800, 600);
|
||||
graphics.endFill();
|
||||
|
||||
var testAsset = openfl.Assets.getText("img/placeholder.txt");
|
||||
|
||||
// Get data asset library
|
||||
var dataLibrary = openfl.utils.Assets.getLibrary("data");
|
||||
var imageLibrary = openfl.utils.Assets.getLibrary("images");
|
||||
if (dataLibrary == null) {
|
||||
trace("Data library not found");
|
||||
return;
|
||||
}
|
||||
if (imageLibrary == null) {
|
||||
trace("Image library not found");
|
||||
return;
|
||||
}
|
||||
|
||||
// test a data asset
|
||||
var testAsset = dataLibrary.getText("img/placeholder.txt");
|
||||
trace("Successfully loaded asset: " + testAsset);
|
||||
// test an image asset
|
||||
var testImage = imageLibrary.getImage("logo.png");
|
||||
trace("Successfully loaded image asset: " + testImage);
|
||||
var bitmapData = openfl.display.BitmapData.fromImage(testImage);
|
||||
this.addChild(new openfl.display.Bitmap(bitmapData));
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
package;
|
||||
|
||||
#if sys
|
||||
import haxe.io.Path;
|
||||
import lime.utils.AssetLibrary;
|
||||
import lime.utils.AssetManifest;
|
||||
import lime.utils.Assets as LimeAssets;
|
||||
import openfl.utils.AssetLibrary;
|
||||
import openfl.utils.AssetManifest;
|
||||
import openfl.utils.Assets as LimeAssets;
|
||||
import sys.FileSystem;
|
||||
|
||||
@:access(lime.utils.Assets)
|
||||
@@ -15,22 +16,37 @@ import sys.FileSystem;
|
||||
public static function init(config:Dynamic):Void {
|
||||
rootPath = "";
|
||||
|
||||
#if sys
|
||||
var manifestPath = Path.join(["manifest", "data.json"]);
|
||||
var manifestDirPath = Path.join(["manifest"]);
|
||||
var manifests = FileSystem.readDirectory(manifestDirPath);
|
||||
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");
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function loadManifest(manifestPath, manifestName) {
|
||||
if (!FileSystem.exists(manifestPath)) {
|
||||
trace("Manifest file not found: " + manifestPath);
|
||||
return;
|
||||
}
|
||||
#end
|
||||
|
||||
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("default");
|
||||
LimeAssets.registerLibrary("default", library);
|
||||
preloadLibraryNames.push(manifestName);
|
||||
// LimeAssets.registerLibrary(manifestName, library);
|
||||
openfl.utils.Assets.registerLibrary(manifestName, library);
|
||||
}
|
||||
}
|
||||
} catch (e:Dynamic) {
|
||||
@@ -38,3 +54,4 @@ import sys.FileSystem;
|
||||
}
|
||||
}
|
||||
}
|
||||
#end
|
||||
|
||||
@@ -164,6 +164,10 @@ class AssetMacro {
|
||||
* Build manifest JSON files for each library
|
||||
*/
|
||||
private static function buildManifests(manifestDir:String) {
|
||||
// Create an array to hold all assets for the default manifest
|
||||
var allAssets = [];
|
||||
|
||||
// First, process individual library manifests
|
||||
for (library in assetMap.keys()) {
|
||||
var assets = assetMap.get(library);
|
||||
var manifest = {
|
||||
@@ -172,6 +176,16 @@ class AssetMacro {
|
||||
rootPath: "../assets/" + library + "/"
|
||||
};
|
||||
|
||||
// Add assets to combined collection with library prefix
|
||||
for (asset in assets) {
|
||||
allAssets.push({
|
||||
id: library + "/" + asset.id,
|
||||
path: library + "/" + asset.path,
|
||||
size: asset.size,
|
||||
type: asset.type
|
||||
});
|
||||
}
|
||||
|
||||
var manifestPath = manifestDir + "/" + library + ".json";
|
||||
try {
|
||||
var content = Json.stringify(manifest, null, " ");
|
||||
@@ -181,6 +195,23 @@ class AssetMacro {
|
||||
Context.warning('Failed to write manifest: ${manifestPath}. Error: ${e}', Context.currentPos());
|
||||
}
|
||||
}
|
||||
|
||||
// Create the default manifest with all assets
|
||||
var defaultManifest = {
|
||||
name: "default",
|
||||
assets: allAssets,
|
||||
rootPath: "../assets/"
|
||||
};
|
||||
|
||||
// Save the default manifest
|
||||
var defaultManifestPath = manifestDir + "/default.json";
|
||||
try {
|
||||
var content = Json.stringify(defaultManifest, null, " ");
|
||||
File.saveContent(defaultManifestPath, content);
|
||||
Context.info('Built default manifest: ${defaultManifestPath} with ${allAssets.length} assets', Context.currentPos());
|
||||
} catch (e) {
|
||||
Context.warning('Failed to write default manifest: ${defaultManifestPath}. Error: ${e}', Context.currentPos());
|
||||
}
|
||||
}
|
||||
|
||||
// Helper functions
|
||||
|
||||
Reference in New Issue
Block a user