From bb41c08293543aa795ad47481dee2166801aa65b Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Fri, 12 Apr 2013 12:54:30 -0700 Subject: [PATCH] Handle as a platform instead of target flag --- project/NMEProject.hx | 1 + project/NMMLParser.hx | 6 + project/Platform.hx | 1 + src/CommandLineTools.hx | 10 +- src/platforms/EmscriptenPlatform.hx | 200 ++++++++++++++++++++++++++++ 5 files changed, 215 insertions(+), 3 deletions(-) create mode 100644 src/platforms/EmscriptenPlatform.hx diff --git a/project/NMEProject.hx b/project/NMEProject.hx index 7902ea5..3d3122b 100644 --- a/project/NMEProject.hx +++ b/project/NMEProject.hx @@ -104,6 +104,7 @@ class NMEProject { architectures = []; case HTML5: + case EMSCRIPTEN: platformType = PlatformType.WEB; architectures = []; diff --git a/project/NMMLParser.hx b/project/NMMLParser.hx index 3954508..f9a58d3 100644 --- a/project/NMMLParser.hx +++ b/project/NMMLParser.hx @@ -91,6 +91,12 @@ class NMMLParser extends NMEProject { } + if (target == Platform.EMSCRIPTEN) { + + localDefines.set ("native", "1"); + + } + localDefines.set ("haxe3", "1"); if (command != null) { diff --git a/project/Platform.hx b/project/Platform.hx index f85b1b1..7f9d509 100644 --- a/project/Platform.hx +++ b/project/Platform.hx @@ -12,5 +12,6 @@ enum Platform { MAC; WINDOWS; WEBOS; + EMSCRIPTEN; } \ No newline at end of file diff --git a/src/CommandLineTools.hx b/src/CommandLineTools.hx index 54b2630..91826f4 100644 --- a/src/CommandLineTools.hx +++ b/src/CommandLineTools.hx @@ -68,19 +68,23 @@ class CommandLineTools { case MAC: platform = new MacPlatform (); - + case LINUX: platform = new LinuxPlatform (); - + case FLASH: platform = new FlashPlatform (); - + case HTML5: platform = new HTML5Platform (); + case EMSCRIPTEN: + + platform = new EmscriptenPlatform (); + } var metaFields = Meta.getFields (Type.getClass (platform)); diff --git a/src/platforms/EmscriptenPlatform.hx b/src/platforms/EmscriptenPlatform.hx new file mode 100644 index 0000000..4217a7a --- /dev/null +++ b/src/platforms/EmscriptenPlatform.hx @@ -0,0 +1,200 @@ +package platforms; + + +import haxe.io.Path; +import haxe.Template; +import helpers.FileHelper; +import helpers.HTML5Helper; +import helpers.PathHelper; +import helpers.ProcessHelper; +import project.AssetType; +import project.NMEProject; +import sys.io.File; +import sys.FileSystem; + + +class EmscriptenPlatform implements IPlatformTool { + + + private var outputDirectory:String; + private var outputFile:String; + + + public function build (project:NMEProject):Void { + + initialize (project); + + if (project.app.main != null) { + + var hxml = outputDirectory + "/haxe/" + (project.debug ? "debug" : "release") + ".hxml"; + ProcessHelper.runCommand ("", "haxe", [ hxml ] ); + + } + + //if (project.targetFlags.exists ("webgl")) { + + FileHelper.copyFile (outputDirectory + "/obj/ApplicationMain.js", outputFile); + + //} + + if (project.targetFlags.exists ("minify")) { + + HTML5Helper.minify (project, outputDirectory + "/bin/" + project.app.file + ".js"); + + } + + } + + + public function clean (project:NMEProject):Void { + + var targetPath = project.app.path + "/emscripten"; + + if (FileSystem.exists (targetPath)) { + + PathHelper.removeDirectory (targetPath); + + } + + } + + + public function display (project:NMEProject):Void { + + initialize (project); + + var hxml = PathHelper.findTemplate (project.templatePaths, "emscripten/hxml/" + (project.debug ? "debug" : "release") + ".hxml"); + + var context = project.templateContext; + context.OUTPUT_DIR = outputDirectory; + context.OUTPUT_FILE = outputFile; + + var template = new Template (File.getContent (hxml)); + Sys.println (template.execute (context)); + + } + + + private function initialize (project:NMEProject):Void { + + outputDirectory = project.app.path + "/emscripten"; + outputFile = outputDirectory + "/bin/" + project.app.file + ".js"; + + } + + + public function run (project:NMEProject, arguments:Array < String > ):Void { + + initialize (project); + + if (project.app.url != "") { + + ProcessHelper.openURL (project.app.url); + + } else { + + ProcessHelper.openFile (project.app.path + "/emscripten/bin", "index.html"); + + } + + } + + + public function update (project:NMEProject):Void { + + initialize (project); + + project = project.clone (); + + var destination = outputDirectory + "/bin/"; + PathHelper.mkdir (destination); + + for (asset in project.assets) { + + if (asset.type == AssetType.FONT) { + + project.haxeflags.push (HTML5Helper.generateFontData (project, asset)); + + } + + } + + if (project.targetFlags.exists ("xml")) { + + project.haxeflags.push ("-xml " + project.app.path + "/emscripten/types.xml"); + + } + + var context = project.templateContext; + + context.WIN_FLASHBACKGROUND = StringTools.hex (project.window.background, 6); + context.OUTPUT_DIR = outputDirectory; + context.OUTPUT_FILE = outputFile; + + //if (project.targetFlags.exists ("webgl")) { + + context.CPP_DIR = project.app.path + "/emscripten/obj"; + + //} + + for (asset in project.assets) { + + var path = PathHelper.combine (destination, asset.targetPath); + + if (asset.type != AssetType.TEMPLATE) { + + if (asset.type != AssetType.FONT) { + + PathHelper.mkdir (Path.directory (path)); + FileHelper.copyAssetIfNewer (asset, path); + + } + + } + + } + + FileHelper.recursiveCopyTemplate (project.templatePaths, "emscripten/template", destination, context); + + if (project.app.main != null) { + + FileHelper.recursiveCopyTemplate (project.templatePaths, "haxe", outputDirectory + "/haxe", context); + + //if (!project.targetFlags.exists ("webgl")) { + // + //FileHelper.recursiveCopyTemplate (project.templatePaths, "html5/haxe", outputDirectory + "/haxe", context); + //FileHelper.recursiveCopyTemplate (project.templatePaths, "html5/hxml", outputDirectory + "/haxe", context); + // + //} else { + + FileHelper.recursiveCopyTemplate (project.templatePaths, "haxe", outputDirectory + "/haxe", context); + FileHelper.recursiveCopyTemplate (project.templatePaths, "emscripten/hxml", outputDirectory + "/haxe", context); + //FileHelper.recursiveCopyTemplate (project.templatePaths, "webgl/hxml", outputDirectory + "/haxe", context); + + //} + + } + + for (asset in project.assets) { + + var path = PathHelper.combine (destination, asset.targetPath); + + if (asset.type == AssetType.TEMPLATE) { + + PathHelper.mkdir (Path.directory (path)); + FileHelper.copyAsset (asset, path, context); + + } + + } + + } + + + public function new () {} + @ignore public function install (project:NMEProject):Void {} + @ignore public function trace (project:NMEProject):Void {} + @ignore public function uninstall (project:NMEProject):Void {} + + +} \ No newline at end of file