Migrating components of the Lime tools into the public Lime namespace
This commit is contained in:
@@ -1,303 +0,0 @@
|
||||
package platforms;
|
||||
|
||||
|
||||
import haxe.io.Path;
|
||||
import haxe.Json;
|
||||
import haxe.Template;
|
||||
import helpers.CompatibilityHelper;
|
||||
import helpers.FileHelper;
|
||||
import helpers.FlashHelper;
|
||||
import helpers.PathHelper;
|
||||
import helpers.PlatformHelper;
|
||||
import helpers.ProcessHelper;
|
||||
import project.AssetType;
|
||||
import project.Haxelib;
|
||||
import project.HXProject;
|
||||
import project.Platform;
|
||||
import project.PlatformTarget;
|
||||
import sys.io.File;
|
||||
import sys.FileSystem;
|
||||
|
||||
|
||||
class FlashPlatform extends PlatformTarget {
|
||||
|
||||
|
||||
private var embedded:Bool;
|
||||
|
||||
|
||||
public function new (command:String, _project:HXProject, targetFlags:Map <String, String>) {
|
||||
|
||||
super (command, _project, targetFlags);
|
||||
|
||||
targetDirectory = project.app.path + "/flash";
|
||||
|
||||
}
|
||||
|
||||
|
||||
public override function build ():Void {
|
||||
|
||||
var destination = targetDirectory + "/bin";
|
||||
|
||||
var type = "release";
|
||||
|
||||
if (project.debug) {
|
||||
|
||||
type = "debug";
|
||||
|
||||
} else if (project.targetFlags.exists ("final")) {
|
||||
|
||||
type = "final";
|
||||
|
||||
}
|
||||
|
||||
if (embedded) {
|
||||
|
||||
var hxml = File.getContent (targetDirectory + "/haxe/" + type + ".hxml");
|
||||
var args = new Array<String> ();
|
||||
|
||||
for (line in ~/[\r\n]+/g.split (hxml)) {
|
||||
|
||||
line = StringTools.ltrim (line);
|
||||
|
||||
if (StringTools.startsWith (line, "#") || line.indexOf ("-swf-header") > -1) {
|
||||
|
||||
continue;
|
||||
|
||||
}
|
||||
|
||||
var space = line.indexOf (" ");
|
||||
|
||||
if (space == -1) {
|
||||
|
||||
args.push (StringTools.rtrim (line));
|
||||
|
||||
} else {
|
||||
|
||||
args.push (line.substr (0, space));
|
||||
|
||||
args.push (StringTools.trim (line.substr (space + 1)));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (PlatformHelper.hostPlatform != Platform.WINDOWS) {
|
||||
|
||||
for (i in 0...args.length) {
|
||||
|
||||
if (args[i].indexOf ("(") > -1) {
|
||||
|
||||
args[i] = "'" + args[i] + "'";
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
ProcessHelper.runCommand ("", "haxe", args);
|
||||
|
||||
} else {
|
||||
|
||||
var hxml = targetDirectory + "/haxe/" + type + ".hxml";
|
||||
ProcessHelper.runCommand ("", "haxe", [ hxml ] );
|
||||
|
||||
}
|
||||
|
||||
/*var usesOpenFL = false;
|
||||
|
||||
for (haxelib in project.haxelibs) {
|
||||
|
||||
if (haxelib.name == "nme" || haxelib.name == "openfl") {
|
||||
|
||||
usesOpenFL = true;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (usesOpenFL) {
|
||||
|
||||
FlashHelper.embedAssets (destination + "/" + project.app.file + ".swf", project.assets);
|
||||
|
||||
}*/
|
||||
|
||||
}
|
||||
|
||||
|
||||
public override function clean ():Void {
|
||||
|
||||
var targetPath = targetDirectory + "";
|
||||
|
||||
if (FileSystem.exists (targetPath)) {
|
||||
|
||||
PathHelper.removeDirectory (targetPath);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public override function display ():Void {
|
||||
|
||||
var type = "release";
|
||||
|
||||
if (project.debug) {
|
||||
|
||||
type = "debug";
|
||||
|
||||
} else if (project.targetFlags.exists ("final")) {
|
||||
|
||||
type = "final";
|
||||
|
||||
}
|
||||
|
||||
var hxml = PathHelper.findTemplate (project.templatePaths, "flash/hxml/" + type + ".hxml");
|
||||
|
||||
var context = project.templateContext;
|
||||
context.WIN_FLASHBACKGROUND = StringTools.hex (project.window.background, 6);
|
||||
|
||||
var template = new Template (File.getContent (hxml));
|
||||
Sys.println (template.execute (context));
|
||||
|
||||
}
|
||||
|
||||
|
||||
private function generateContext ():Dynamic {
|
||||
|
||||
project = project.clone ();
|
||||
|
||||
if (project.targetFlags.exists ("xml")) {
|
||||
|
||||
project.haxeflags.push ("-xml " + targetDirectory + "/types.xml");
|
||||
|
||||
}
|
||||
|
||||
var context = project.templateContext;
|
||||
context.WIN_FLASHBACKGROUND = StringTools.hex (project.window.background, 6);
|
||||
var assets:Array <Dynamic> = cast context.assets;
|
||||
|
||||
for (asset in assets) {
|
||||
|
||||
var assetType:AssetType = Reflect.field (AssetType, asset.type.toUpperCase ());
|
||||
|
||||
switch (assetType) {
|
||||
|
||||
case MUSIC : asset.flashClass = "flash.media.Sound";
|
||||
case SOUND : asset.flashClass = "flash.media.Sound";
|
||||
case IMAGE : asset.flashClass = "flash.display.BitmapData";
|
||||
case FONT : asset.flashClass = "flash.text.Font";
|
||||
default: asset.flashClass = "flash.utils.ByteArray";
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return context;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public override function run ():Void {
|
||||
|
||||
if (project.app.url != null && project.app.url != "") {
|
||||
|
||||
ProcessHelper.openURL (project.app.url);
|
||||
|
||||
} else {
|
||||
|
||||
var destination = targetDirectory + "/bin";
|
||||
var targetPath = project.app.file + ".swf";
|
||||
|
||||
if (project.targetFlags.exists ("web")) {
|
||||
|
||||
targetPath = "index.html";
|
||||
|
||||
}
|
||||
|
||||
FlashHelper.run (project, destination, targetPath);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public override function update ():Void {
|
||||
|
||||
var destination = targetDirectory + "/bin/";
|
||||
PathHelper.mkdir (destination);
|
||||
|
||||
embedded = FlashHelper.embedAssets (project);
|
||||
|
||||
var context = generateContext ();
|
||||
|
||||
FileHelper.recursiveCopyTemplate (project.templatePaths, "haxe", targetDirectory + "/haxe", context);
|
||||
FileHelper.recursiveCopyTemplate (project.templatePaths, "flash/hxml", targetDirectory + "/haxe", context);
|
||||
FileHelper.recursiveCopyTemplate (project.templatePaths, "flash/haxe", targetDirectory + "/haxe", context, true, false);
|
||||
|
||||
//SWFHelper.generateSWFClasses (project, targetDirectory + "/haxe");
|
||||
|
||||
var usesNME = false;
|
||||
|
||||
for (haxelib in project.haxelibs) {
|
||||
|
||||
if (haxelib.name == "nme" || haxelib.name == "openfl") {
|
||||
|
||||
usesNME = true;
|
||||
|
||||
}
|
||||
|
||||
if (haxelib.name == "openfl") {
|
||||
|
||||
CompatibilityHelper.patchAssetLibrary (project, haxelib, targetDirectory + "/haxe/DefaultAssetLibrary.hx", context);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (project.targetFlags.exists ("web") || project.app.url != "") {
|
||||
|
||||
PathHelper.mkdir (destination);
|
||||
FileHelper.recursiveCopyTemplate (project.templatePaths, "flash/templates/web", destination, generateContext ());
|
||||
|
||||
}
|
||||
|
||||
for (asset in project.assets) {
|
||||
|
||||
if (asset.type == AssetType.TEMPLATE || asset.embed == false || !usesNME) {
|
||||
|
||||
var path = PathHelper.combine (destination, asset.targetPath);
|
||||
|
||||
PathHelper.mkdir (Path.directory (path));
|
||||
FileHelper.copyAsset (asset, path, context);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*private function getIcon (size:Int, targetPath:String):Void {
|
||||
|
||||
var icon = icons.findIcon (size, size);
|
||||
|
||||
if (icon != "") {
|
||||
|
||||
FileHelper.copyIfNewer (icon, targetPath);
|
||||
|
||||
} else {
|
||||
|
||||
icons.updateIcon (size, size, targetPath);
|
||||
|
||||
}
|
||||
|
||||
}*/
|
||||
|
||||
|
||||
@ignore public override function install ():Void {}
|
||||
@ignore public override function rebuild ():Void {}
|
||||
@ignore public override function trace ():Void {}
|
||||
@ignore public override function uninstall ():Void {}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user