Skip to content

Commit

Permalink
Add some placeholders for html5 platform
Browse files Browse the repository at this point in the history
  • Loading branch information
hughsando committed Jul 17, 2015
1 parent 56452c3 commit e1d7876
Show file tree
Hide file tree
Showing 8 changed files with 142 additions and 4 deletions.
2 changes: 2 additions & 0 deletions include.nmml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@
<asset name="Cousine-Regular.ttf" id="_monospace" embed="true"/>
</assets>

<classpath name="lyre" if="html5" />

</project>
2 changes: 1 addition & 1 deletion nme/Assets.hx
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ class Assets
data = Type.createInstance(Type.resolveClass(i.className), []);
#elseif js
var asset:Dynamic = ApplicationMain.urlLoaders.get(i.path).data;
data:ByteArray = null;
data = null;
if (Std.is(asset, String))
{
bytes = new ByteArray();
Expand Down
61 changes: 61 additions & 0 deletions tools/lyre/Lyre.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import sys.FileSystem;
using StringTools;

class Lyre
{

public static function runRecurse(srcDir:String, destDir:String, copyDir:String, srcPack:String, destPack:String)
{
try
{
if (!FileSystem.exists(destDir))
FileSystem.createDirectory(destDir);
if (!FileSystem.exists(copyDir))
FileSystem.createDirectory(copyDir);
for(file in FileSystem.readDirectory(srcDir))
{
if (file=="_legacy")
continue;

var srcPath = srcDir +"/" + file;
var destPath = destDir +"/" + file;
var copyPath = copyDir +"/" + file;

if (FileSystem.isDirectory(srcPath))
runRecurse(srcPath, destPath, copyPath, srcPack+"."+file, destPack+"."+file);
else if (file.endsWith(".hx"))
{
Sys.println("Writing " + destPath);
var clazz = file.substr(0, file.length-3);
var content = [
'package $destPack;',
'typedef $clazz=$srcPack.$clazz;',
].join("\n");
sys.io.File.saveContent(destPath,content);

Sys.println("Copy " + copyPath);
sys.io.File.copy(srcPath, copyPath);
}
}
}
catch(e:Dynamic)
{
trace("Error " + e);
}
}

public static function main()
{
var args = Sys.args();
var srcDir = args[0];
var destDir = args[1];
var packName = args[2];

if (packName==null || !FileSystem.isDirectory(srcDir) || !FileSystem.isDirectory(destDir))
{
Sys.println("Usage : lyre srcDir destDir packageName");
Sys.exit(0);
}
runRecurse(srcDir + "/" + packName, destDir + "/nme", destDir+"/"+packName, packName, "nme" );
}
}
3 changes: 3 additions & 0 deletions tools/lyre/compile.hxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-main Lyre
-neko lyre.n
-debug
5 changes: 4 additions & 1 deletion tools/nme/src/CommandLineTools.hx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class CommandLineTools
static var allTargets =
[ "cpp", "neko", "ios", "iphone", "iphoneos", "iosview", "ios-view",
"androidview", "android-view", "iphonesim", "android", "androidsim",
"windows", "mac", "linux", "flash", "cppia", "emscripten" ];
"windows", "mac", "linux", "flash", "cppia", "emscripten", "html5" ];
static var allCommands =
[ "help", "setup", "document", "generate", "create", "xcode", "clone", "demo",
"installer", "copy-if-newer", "tidy", "set", "unset", "nocompile",
Expand Down Expand Up @@ -98,6 +98,9 @@ class CommandLineTools

case Platform.EMSCRIPTEN:
platform = new platforms.EmscriptenPlatform(project);

case Platform.HTML5:
platform = new platforms.Html5Platform(project);
}

if (platform != null)
Expand Down
60 changes: 60 additions & 0 deletions tools/nme/src/platforms/Html5Platform.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package platforms;

import haxe.io.Path;
import haxe.Template;
import sys.io.File;
import sys.FileSystem;


class Html5Platform extends Platform
{
private var applicationDirectory:String;

public function new(inProject:NMEProject)
{
inProject.openflCompat = false;
super(inProject);

applicationDirectory = getOutputDir();

project.haxeflags.push('-js $haxeDir/ApplicationMain.js');
}

override public function getPlatformDir() : String { return "html5"; }
override public function getBinName() : String { return null; }
override public function getNativeDllExt() { return null; }
override public function getLibExt() { return null; }
override public function getHaxeTemplateDir() { return "haxe"; }
override public function getAssetDir() { return getOutputDir()+"/assets"; }


override public function copyBinary():Void
{
FileHelper.copyFile('$haxeDir/ApplicationMain.js',
'$applicationDirectory/ApplicationMain.js', addOutput);
}

override public function updateOutputDir():Void
{
super.updateOutputDir();

var destination = getOutputDir();
var icon = IconHelper.getSvgIcon(project.icons);
if (icon!=null)
{
FileHelper.copyFile(icon, destination + "/icon.svg", addOutput);
}
else
IconHelper.createIcon(project.icons, 128, 128, destination + "/icon.png", addOutput);
}


override public function run(arguments:Array<String>):Void
{
var fullPath = FileSystem.fullPath('$applicationDirectory/ApplicationMain.js');
trace("TODO " + fullPath);
}
}



1 change: 1 addition & 0 deletions tools/nme/src/platforms/Platform.hx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class Platform
public static inline var ANDROIDVIEW = "ANDROIDVIEW";
public static inline var CPPIA = "CPPIA";
public static inline var EMSCRIPTEN = "EMSCRIPTEN";
public static inline var HTML5 = "HTML5";


public static inline var TYPE_WEB = "WEB";
Expand Down
12 changes: 10 additions & 2 deletions tools/nme/src/project/NMEProject.hx
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ class NMEProject
public var debug:Bool;
public var megaTrace:Bool;
public var isFlash:Bool;
public var isHtml5:Bool;

// Exported into project for use in project files
public var platformType:String;
Expand Down Expand Up @@ -291,6 +292,9 @@ class NMEProject
case "flash":
target = inTargetName.toUpperCase();

case "html5":
target = inTargetName.toUpperCase();

case "windows", "mac", "linux":
targetFlags.set("cpp", "1");
target = inTargetName.toUpperCase();
Expand All @@ -313,7 +317,8 @@ class NMEProject
}

isFlash = target==Platform.FLASH;
if (!isFlash)
isHtml5 = target==Platform.HTML5;
if (!isFlash && !isHtml5)
{
haxeflags.push("--remap flash:nme");
haxeflags.push("--remap lime:nme");
Expand All @@ -324,14 +329,17 @@ class NMEProject
switch(target)
{
case Platform.FLASH:

platformType = Platform.TYPE_WEB;
embedAssets = true;

case Platform.CPPIA:
platformType = Platform.TYPE_SCRIPT;
embedAssets = false;

case Platform.HTML5:
platformType = Platform.TYPE_WEB;
embedAssets = false;

case Platform.EMSCRIPTEN:
platformType = Platform.TYPE_WEB;
embedAssets = true;
Expand Down

0 comments on commit e1d7876

Please sign in to comment.