From 970fc7655f86e28a81248167d8c7716dbfba868f Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Thu, 24 Aug 2017 16:36:58 -0700 Subject: [PATCH] Put SWF assets in first frame for AIR, add custom HXML template for AIR --- lime/tools/helpers/FlashHelper.hx | 9 +++- lime/tools/platforms/AIRPlatform.hx | 68 ++++++++++++++++++++++++++--- templates/air/hxml/debug.hxml | 7 +++ templates/air/hxml/final.hxml | 7 +++ templates/air/hxml/release.hxml | 6 +++ 5 files changed, 90 insertions(+), 7 deletions(-) create mode 100644 templates/air/hxml/debug.hxml create mode 100644 templates/air/hxml/final.hxml create mode 100644 templates/air/hxml/release.hxml diff --git a/lime/tools/helpers/FlashHelper.hx b/lime/tools/helpers/FlashHelper.hx index 66d66acbe..823311a72 100644 --- a/lime/tools/helpers/FlashHelper.hx +++ b/lime/tools/helpers/FlashHelper.hx @@ -643,7 +643,7 @@ class FlashHelper { width : (project.window.width == 0 ? 800 : project.window.width), height : (project.window.height == 0 ? 500 : project.window.height), fps : project.window.fps * 256, - nframes : 2 + nframes : project.target == AIR ? 1 : 2 }; var tags = new Array (); @@ -651,7 +651,12 @@ class FlashHelper { var inserted = false; tags.push (TBackgroundColor (project.window.background)); - tags.push (TShowFrame); + + if (project.target != AIR) { + + tags.push (TShowFrame); + + } // Might generate ABC later, so we don't need the @:bind calls in DefaultAssetLibrary? diff --git a/lime/tools/platforms/AIRPlatform.hx b/lime/tools/platforms/AIRPlatform.hx index c529b5303..99c9b0470 100644 --- a/lime/tools/platforms/AIRPlatform.hx +++ b/lime/tools/platforms/AIRPlatform.hx @@ -1,17 +1,21 @@ package lime.tools.platforms; +import haxe.io.Path; +import lime.project.AssetType; +import lime.project.HXProject; +import lime.project.Icon; import lime.project.Platform; import lime.project.PlatformType; import lime.tools.helpers.AIRHelper; import lime.tools.helpers.DeploymentHelper; import lime.tools.helpers.FileHelper; +import lime.tools.helpers.FlashHelper; import lime.tools.helpers.IconHelper; import lime.tools.helpers.PathHelper; import lime.tools.helpers.PlatformHelper; import lime.tools.helpers.LogHelper; -import lime.project.HXProject; -import lime.project.Icon; +import sys.io.File; import sys.FileSystem; @@ -90,13 +94,67 @@ class AIRPlatform extends FlashPlatform { public override function update ():Void { - super.update (); + var destination = targetDirectory + "/bin/"; + PathHelper.mkdir (destination); - var context = project.templateContext; + project = project.clone (); - FileHelper.recursiveCopyTemplate (project.templatePaths, "air/hxml", targetDirectory + "/haxe", context, true, false); + embedded = FlashHelper.embedAssets (project, targetDirectory); + + var context = generateContext (); + context.OUTPUT_DIR = targetDirectory; + + FileHelper.recursiveCopyTemplate (project.templatePaths, "haxe", targetDirectory + "/haxe", context); + FileHelper.recursiveCopyTemplate (project.templatePaths, "air/hxml", targetDirectory + "/haxe", context); FileHelper.recursiveCopyTemplate (project.templatePaths, "air/template", targetDirectory + "/bin", context); + if (embedded) { + + var files = [ "debug.hxml", "release.hxml", "final.hxml" ]; + var path, hxml, lines, output; + + for (file in files) { + + path = targetDirectory + "/haxe/" + file; + hxml = File.getContent (path); + + if (hxml.indexOf ("-swf-header") > -1) { + + lines = ~/[\r\n]+/g.split (hxml); + output = []; + + for (line in lines) { + + if (line.indexOf ("-swf-header") > -1) continue; + output.push (line); + + } + + if (output.length < lines.length) { + + File.saveContent (path, output.join ("\n")); + + } + + } + + } + + } + + for (asset in project.assets) { + + if (asset.type == AssetType.TEMPLATE || asset.embed == false /*|| !usesLime*/) { + + var path = PathHelper.combine (destination, asset.targetPath); + + PathHelper.mkdir (Path.directory (path)); + FileHelper.copyAsset (asset, path, context); + + } + + } + //var sizes = [ 32, 48, 60, 64, 128, 512 ]; //var icons = project.icons; // diff --git a/templates/air/hxml/debug.hxml b/templates/air/hxml/debug.hxml new file mode 100644 index 000000000..6a80c4129 --- /dev/null +++ b/templates/air/hxml/debug.hxml @@ -0,0 +1,7 @@ +-main ApplicationMain ::HAXE_FLAGS:: +-swf-version ::SWF_VERSION:: +-swf ::OUTPUT_DIR::/bin/::APP_FILE::.swf +-swf-header ::if (WIN_WIDTH == "0")::800::else::::WIN_WIDTH::::end:::::if (WIN_HEIGHT == "0")::500::else::::WIN_HEIGHT::::end:::::WIN_FPS:::::WIN_FLASHBACKGROUND:: +-cp ::OUTPUT_DIR::/haxe +-debug +-D air \ No newline at end of file diff --git a/templates/air/hxml/final.hxml b/templates/air/hxml/final.hxml new file mode 100644 index 000000000..21b073751 --- /dev/null +++ b/templates/air/hxml/final.hxml @@ -0,0 +1,7 @@ +-main ApplicationMain ::HAXE_FLAGS:: +-swf-version ::SWF_VERSION:: +-swf ::OUTPUT_DIR::/bin/::APP_FILE::.swf +-swf-header ::if (WIN_WIDTH == "0")::800::else::::WIN_WIDTH::::end:::::if (WIN_HEIGHT == "0")::500::else::::WIN_HEIGHT::::end:::::WIN_FPS:::::WIN_FLASHBACKGROUND:: +-cp ::OUTPUT_DIR::/haxe +-D final +-D air \ No newline at end of file diff --git a/templates/air/hxml/release.hxml b/templates/air/hxml/release.hxml new file mode 100644 index 000000000..da37165fa --- /dev/null +++ b/templates/air/hxml/release.hxml @@ -0,0 +1,6 @@ +-main ApplicationMain ::HAXE_FLAGS:: +-swf-version ::SWF_VERSION:: +-swf ::OUTPUT_DIR::/bin/::APP_FILE::.swf +-swf-header ::if (WIN_WIDTH == "0")::800::else::::WIN_WIDTH::::end:::::if (WIN_HEIGHT == "0")::500::else::::WIN_HEIGHT::::end:::::WIN_FPS:::::WIN_FLASHBACKGROUND:: +-cp ::OUTPUT_DIR::/haxe +-D air \ No newline at end of file