Skip to content

Commit

Permalink
Handle as a platform instead of target flag
Browse files Browse the repository at this point in the history
  • Loading branch information
jgranick committed Apr 12, 2013
1 parent 3c05522 commit bb41c08
Show file tree
Hide file tree
Showing 5 changed files with 215 additions and 3 deletions.
1 change: 1 addition & 0 deletions project/NMEProject.hx
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ class NMEProject {
architectures = [];

case HTML5:
case EMSCRIPTEN:

platformType = PlatformType.WEB;
architectures = [];
Expand Down
6 changes: 6 additions & 0 deletions project/NMMLParser.hx
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ class NMMLParser extends NMEProject {

}

if (target == Platform.EMSCRIPTEN) {

localDefines.set ("native", "1");

}

localDefines.set ("haxe3", "1");

if (command != null) {
Expand Down
1 change: 1 addition & 0 deletions project/Platform.hx
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ enum Platform {
MAC;
WINDOWS;
WEBOS;
EMSCRIPTEN;

}
10 changes: 7 additions & 3 deletions src/CommandLineTools.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
200 changes: 200 additions & 0 deletions src/platforms/EmscriptenPlatform.hx
Original file line number Diff line number Diff line change
@@ -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 {}


}

0 comments on commit bb41c08

Please sign in to comment.