-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle as a platform instead of target flag
- Loading branch information
Showing
5 changed files
with
215 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,5 +12,6 @@ enum Platform { | |
MAC; | ||
WINDOWS; | ||
WEBOS; | ||
EMSCRIPTEN; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 {} | ||
|
||
|
||
} |