Adding provisional html5 support, normal GL access appears to be working fine, but no Assets support and lacking ByteArray implementations to be fixed later.
This commit is contained in:
204
buildfiles/html5/haxe/ApplicationMain.hx
Executable file
204
buildfiles/html5/haxe/ApplicationMain.hx
Executable file
@@ -0,0 +1,204 @@
|
||||
#if (!lime && !flambe)
|
||||
|
||||
|
||||
import ::APP_MAIN_PACKAGE::::APP_MAIN_CLASS::;
|
||||
import nme.display.Bitmap;
|
||||
import nme.display.Loader;
|
||||
import nme.events.Event;
|
||||
import nme.media.Sound;
|
||||
import nme.net.URLLoader;
|
||||
import nme.net.URLRequest;
|
||||
import nme.net.URLLoaderDataFormat;
|
||||
import nme.Assets;
|
||||
import nme.Lib;
|
||||
|
||||
|
||||
class ApplicationMain {
|
||||
|
||||
|
||||
private static var completed:Int;
|
||||
private static var preloader:NMEPreloader;
|
||||
private static var total:Int;
|
||||
|
||||
public static var loaders:Hash <Loader>;
|
||||
public static var urlLoaders:Hash <URLLoader>;
|
||||
|
||||
|
||||
public static function main () {
|
||||
|
||||
completed = 0;
|
||||
loaders = new Hash <Loader> ();
|
||||
urlLoaders = new Hash <URLLoader> ();
|
||||
total = 0;
|
||||
|
||||
::if (WIN_WIDTH == "0")::::if (WIN_HEIGHT == "0")::
|
||||
browser.Lib.preventDefaultTouchMove ();
|
||||
::end::::end::
|
||||
|
||||
::if (PRELOADER_NAME!="")::
|
||||
preloader = new ::PRELOADER_NAME:: ();
|
||||
::else::
|
||||
preloader = new NMEPreloader ();
|
||||
::end::
|
||||
Lib.current.addChild (preloader);
|
||||
preloader.onInit ();
|
||||
|
||||
::foreach assets::
|
||||
::if (type=="image")::
|
||||
var loader:Loader = new Loader ();
|
||||
loaders.set ("::resourceName::", loader);
|
||||
total ++;
|
||||
::elseif (type == "binary")::
|
||||
var urlLoader:URLLoader = new URLLoader ();
|
||||
urlLoader.dataFormat = BINARY;
|
||||
urlLoaders.set ("::resourceName::", urlLoader);
|
||||
total ++;
|
||||
::elseif (type == "text")::
|
||||
var urlLoader:URLLoader = new URLLoader ();
|
||||
urlLoader.dataFormat = TEXT;
|
||||
urlLoaders.set ("::resourceName::", urlLoader);
|
||||
total ++;
|
||||
::end::::end::
|
||||
|
||||
if (total == 0) {
|
||||
|
||||
begin ();
|
||||
|
||||
} else {
|
||||
|
||||
for (path in loaders.keys ()) {
|
||||
|
||||
var loader:Loader = loaders.get (path);
|
||||
loader.contentLoaderInfo.addEventListener ("complete", loader_onComplete);
|
||||
loader.load (new URLRequest (path));
|
||||
|
||||
}
|
||||
|
||||
for (path in urlLoaders.keys ()) {
|
||||
|
||||
var urlLoader:URLLoader = urlLoaders.get (path);
|
||||
urlLoader.addEventListener ("complete", loader_onComplete);
|
||||
urlLoader.load (new URLRequest (path));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
private static function begin ():Void {
|
||||
|
||||
preloader.addEventListener (Event.COMPLETE, preloader_onComplete);
|
||||
preloader.onLoaded ();
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static function getAsset(inName:String):Dynamic {
|
||||
|
||||
::foreach assets::
|
||||
if (inName=="::id::") {
|
||||
::if (type == "image")::
|
||||
return Assets.getBitmapData ("::id::");
|
||||
::elseif (type=="sound")::
|
||||
return Assets.getSound ("::id::");
|
||||
::elseif (type=="music")::
|
||||
return Assets.getSound ("::id::");
|
||||
::elseif (type== "font")::
|
||||
return Assets.getFont ("::id::");
|
||||
::elseif (type== "text")::
|
||||
return Assets.getText ("::id::");
|
||||
::else::
|
||||
return Assets.getBytes ("::id::");
|
||||
::end::
|
||||
}
|
||||
::end::
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// Event Handlers
|
||||
|
||||
|
||||
|
||||
|
||||
private static function loader_onComplete (event:Event):Void {
|
||||
|
||||
completed ++;
|
||||
|
||||
preloader.onUpdate (completed, total);
|
||||
|
||||
if (completed == total) {
|
||||
|
||||
begin ();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
private static function preloader_onComplete (event:Event):Void {
|
||||
|
||||
preloader.removeEventListener (Event.COMPLETE, preloader_onComplete);
|
||||
|
||||
Lib.current.removeChild(preloader);
|
||||
preloader = null;
|
||||
|
||||
if (Reflect.field(::APP_MAIN::, "main") == null)
|
||||
{
|
||||
var mainDisplayObj = new ::APP_MAIN::();
|
||||
if (Std.is(mainDisplayObj, browser.display.DisplayObject))
|
||||
nme.Lib.current.addChild(cast mainDisplayObj);
|
||||
}
|
||||
else
|
||||
{
|
||||
Reflect.callMethod (::APP_MAIN::, Reflect.field (::APP_MAIN::, "main"), []);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
::foreach assets::
|
||||
::if (type=="font")::
|
||||
class NME_::flatName:: extends nme.text.Font { }
|
||||
::end::
|
||||
::end::
|
||||
|
||||
|
||||
#else
|
||||
|
||||
|
||||
import ::APP_MAIN_PACKAGE::::APP_MAIN_CLASS::;
|
||||
import lime.LiME;
|
||||
|
||||
class ApplicationMain {
|
||||
|
||||
public static function main () {
|
||||
|
||||
//Create the game class, give it the runtime
|
||||
var _main_ = Type.createInstance (::APP_MAIN::, []);
|
||||
//Create an instance of lime
|
||||
var _lime = new LiME();
|
||||
|
||||
//Create the config from the project.nmml info
|
||||
var config = {
|
||||
width : ::WIN_WIDTH::,
|
||||
height : ::WIN_HEIGHT::,
|
||||
title : "::APP_TITLE::"
|
||||
};
|
||||
|
||||
//Start up
|
||||
_lime.init( _main_, config );
|
||||
|
||||
} //main
|
||||
} //ApplicationMain
|
||||
|
||||
|
||||
#end
|
||||
38
buildfiles/html5/haxe/nme/AssetData.hx
Normal file
38
buildfiles/html5/haxe/nme/AssetData.hx
Normal file
@@ -0,0 +1,38 @@
|
||||
package nme;
|
||||
|
||||
|
||||
import lime.utils.Assets;
|
||||
|
||||
|
||||
class AssetData {
|
||||
|
||||
|
||||
public static var className = new Map <String, Dynamic> ();
|
||||
public static var library = new Map <String, LibraryType> ();
|
||||
public static var path = new Map <String, String> ();
|
||||
public static var type = new Map <String, AssetType> ();
|
||||
|
||||
private static var initialized:Bool = false;
|
||||
|
||||
|
||||
public static function initialize ():Void {
|
||||
|
||||
if (!initialized) {
|
||||
|
||||
::if (assets != null)::::foreach assets::::if (type == "font")::className.set ("::id::", nme.NME_::flatName::);::else::path.set ("::id::", "::resourceName::");::end::
|
||||
type.set ("::id::", Reflect.field (AssetType, "::type::".toUpperCase ()));
|
||||
::end::::end::
|
||||
::if (libraries != null)::::foreach libraries::library.set ("::name::", Reflect.field (LibraryType, "::type::".toUpperCase ()));
|
||||
::end::::end::
|
||||
initialized = true;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
::foreach assets::::if (type == "font")::class NME_::flatName:: extends flash.text.Font { }::end::
|
||||
::end::
|
||||
324
buildfiles/html5/haxe/nme/installer/Assets.hx
Executable file
324
buildfiles/html5/haxe/nme/installer/Assets.hx
Executable file
@@ -0,0 +1,324 @@
|
||||
package nme.installer;
|
||||
|
||||
|
||||
import format.display.MovieClip;
|
||||
import haxe.Unserializer;
|
||||
import nme.display.Bitmap;
|
||||
import nme.display.BitmapData;
|
||||
import nme.media.Sound;
|
||||
import nme.net.URLRequest;
|
||||
import nme.text.Font;
|
||||
import nme.utils.ByteArray;
|
||||
import ApplicationMain;
|
||||
|
||||
#if swfdev
|
||||
import format.swf.lite.SWFLite;
|
||||
#end
|
||||
|
||||
#if xfl
|
||||
import format.XFL;
|
||||
#end
|
||||
|
||||
|
||||
/**
|
||||
* ...
|
||||
* @author Joshua Granick
|
||||
*/
|
||||
|
||||
class Assets {
|
||||
|
||||
|
||||
public static var cachedBitmapData:Hash<BitmapData> = new Hash<BitmapData>();
|
||||
#if swfdev private static var cachedSWFLibraries:Hash <SWFLite> = new Hash <SWFLite> (); #end
|
||||
#if xfl private static var cachedXFLLibraries:Hash <XFL> = new Hash <XFL> (); #end
|
||||
|
||||
private static var initialized:Bool = false;
|
||||
private static var libraryTypes:Hash <String> = new Hash <String> ();
|
||||
private static var resourceClasses:Hash <Dynamic> = new Hash <Dynamic> ();
|
||||
private static var resourceNames:Hash <String> = new Hash <String> ();
|
||||
private static var resourceTypes:Hash <String> = new Hash <String> ();
|
||||
|
||||
|
||||
private static function initialize ():Void {
|
||||
|
||||
if (!initialized) {
|
||||
|
||||
::foreach assets::
|
||||
::if (type == "font")::resourceClasses.set ("::id::", NME_::flatName::);::end::
|
||||
resourceNames.set ("::id::", "::resourceName::");
|
||||
resourceTypes.set ("::id::", "::type::");
|
||||
::end::
|
||||
::foreach libraries::libraryTypes.set ("::name::", "::type::");::end::
|
||||
initialized = true;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static function getBitmapData (id:String, useCache:Bool = true):BitmapData {
|
||||
|
||||
initialize ();
|
||||
|
||||
if (resourceNames.exists(id) && resourceTypes.exists (id) && resourceTypes.get (id).toLowerCase () == "image") {
|
||||
|
||||
if (useCache && cachedBitmapData.exists (id)) {
|
||||
|
||||
return cachedBitmapData.get (id);
|
||||
|
||||
} else {
|
||||
|
||||
// Should be bitmapData.clone (), but stopped working in recent Jeash builds
|
||||
// Without clone, BitmapData is already cached, so ignoring the hash table for now
|
||||
|
||||
var data = cast (ApplicationMain.loaders.get (resourceNames.get(id)).contentLoaderInfo.content, Bitmap).bitmapData;
|
||||
|
||||
if (useCache) {
|
||||
|
||||
cachedBitmapData.set (id, data);
|
||||
|
||||
}
|
||||
|
||||
return data;
|
||||
|
||||
}
|
||||
|
||||
} else if (id.indexOf (":") > -1) {
|
||||
|
||||
var libraryName = id.substr (0, id.indexOf (":"));
|
||||
var symbolName = id.substr (id.indexOf (":") + 1);
|
||||
|
||||
if (libraryTypes.exists (libraryName)) {
|
||||
|
||||
#if swfdev
|
||||
|
||||
if (libraryTypes.get (libraryName) == "swf") {
|
||||
|
||||
if (!cachedSWFLibraries.exists (libraryName)) {
|
||||
|
||||
var unserializer = new Unserializer (getText ("libraries/" + libraryName + ".dat"));
|
||||
unserializer.setResolver (cast { resolveEnum: resolveEnum, resolveClass: resolveClass });
|
||||
cachedSWFLibraries.set (libraryName, unserializer.unserialize());
|
||||
|
||||
}
|
||||
|
||||
return cachedSWFLibraries.get (libraryName).getBitmapData (symbolName);
|
||||
|
||||
}
|
||||
|
||||
#end
|
||||
|
||||
#if xfl
|
||||
|
||||
if (libraryTypes.get (libraryName) == "xfl") {
|
||||
|
||||
if (!cachedXFLLibraries.exists (libraryName)) {
|
||||
|
||||
cachedXFLLibraries.set (libraryName, Unserializer.run (getText ("libraries/" + libraryName + "/" + libraryName + ".dat")));
|
||||
|
||||
}
|
||||
|
||||
return cachedXFLLibraries.get (libraryName).getBitmapData (symbolName);
|
||||
|
||||
}
|
||||
|
||||
#end
|
||||
|
||||
} else {
|
||||
|
||||
trace ("[nme.Assets] There is no asset library named \"" + libraryName + "\"");
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
trace ("[nme.Assets] There is no BitmapData asset with an ID of \"" + id + "\"");
|
||||
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static function getBytes (id:String):ByteArray {
|
||||
|
||||
initialize ();
|
||||
|
||||
if (resourceNames.exists (id)) {
|
||||
|
||||
return cast ApplicationMain.urlLoaders.get (getResourceName(id)).data;
|
||||
|
||||
}
|
||||
|
||||
trace ("[nme.Assets] There is no String or ByteArray asset with an ID of \"" + id + "\"");
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static function getFont (id:String):Font {
|
||||
|
||||
initialize ();
|
||||
|
||||
if (resourceNames.exists(id) && resourceTypes.exists (id)) {
|
||||
|
||||
if (resourceTypes.get (id).toLowerCase () == "font") {
|
||||
|
||||
return cast (Type.createInstance (resourceClasses.get (id), []), Font);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
trace ("[nme.Assets] There is no Font asset with an ID of \"" + id + "\"");
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static function getMovieClip (id:String):MovieClip {
|
||||
|
||||
initialize ();
|
||||
|
||||
var libraryName = id.substr (0, id.indexOf (":"));
|
||||
var symbolName = id.substr (id.indexOf (":") + 1);
|
||||
|
||||
if (libraryTypes.exists (libraryName)) {
|
||||
|
||||
#if swfdev
|
||||
|
||||
if (libraryTypes.get (libraryName) == "swf") {
|
||||
|
||||
if (!cachedSWFLibraries.exists (libraryName)) {
|
||||
|
||||
var unserializer = new Unserializer (getText ("libraries/" + libraryName + ".dat"));
|
||||
unserializer.setResolver (cast { resolveEnum: resolveEnum, resolveClass: resolveClass });
|
||||
cachedSWFLibraries.set (libraryName, unserializer.unserialize());
|
||||
|
||||
}
|
||||
|
||||
return cachedSWFLibraries.get (libraryName).createMovieClip (symbolName);
|
||||
|
||||
}
|
||||
|
||||
#end
|
||||
|
||||
#if xfl
|
||||
|
||||
if (libraryTypes.get (libraryName) == "xfl") {
|
||||
|
||||
if (!cachedXFLLibraries.exists (libraryName)) {
|
||||
|
||||
cachedXFLLibraries.set (libraryName, Unserializer.run (getText ("libraries/" + libraryName + "/" + libraryName + ".dat")));
|
||||
|
||||
}
|
||||
|
||||
return cachedXFLLibraries.get (libraryName).createMovieClip (symbolName);
|
||||
|
||||
}
|
||||
|
||||
#end
|
||||
|
||||
} else {
|
||||
|
||||
trace ("[nme.Assets] There is no asset library named \"" + libraryName + "\"");
|
||||
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static function getResourceName (id:String):String {
|
||||
|
||||
initialize ();
|
||||
|
||||
return resourceNames.get (id);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static function getSound (id:String):Sound {
|
||||
|
||||
initialize ();
|
||||
|
||||
if (resourceNames.exists(id) && resourceTypes.exists (id)) {
|
||||
|
||||
if (resourceTypes.get (id).toLowerCase () == "sound") {
|
||||
|
||||
return new Sound (new URLRequest (resourceNames.get(id)));
|
||||
|
||||
} else if (resourceTypes.get (id).toLowerCase () == "music") {
|
||||
|
||||
return new Sound (new URLRequest (resourceNames.get(id)));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
trace ("[nme.Assets] There is no Sound asset with an ID of \"" + id + "\"");
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static function getText (id:String):String {
|
||||
|
||||
initialize ();
|
||||
|
||||
if (resourceNames.exists(id) && resourceTypes.exists (id)) {
|
||||
|
||||
if (resourceTypes.get (id).toLowerCase () == "text") {
|
||||
|
||||
return ApplicationMain.urlLoaders.get (resourceNames.get(id)).data;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
var bytes = getBytes (id);
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
|
||||
//public static function loadBitmapData(id:String, handler:BitmapData -> Void, useCache:Bool = true):BitmapData
|
||||
//{
|
||||
//return null;
|
||||
//}
|
||||
//
|
||||
//
|
||||
//public static function loadBytes(id:String, handler:ByteArray -> Void):ByteArray
|
||||
//{
|
||||
//return null;
|
||||
//}
|
||||
//
|
||||
//
|
||||
//public static function loadText(id:String, handler:String -> Void):String
|
||||
//{
|
||||
//return null;
|
||||
//}
|
||||
|
||||
|
||||
private static function resolveClass (name:String):Class <Dynamic> {
|
||||
|
||||
name = StringTools.replace (name, "native.", "browser.");
|
||||
return Type.resolveClass (name);
|
||||
|
||||
}
|
||||
|
||||
|
||||
private static function resolveEnum (name:String):Enum <Dynamic> {
|
||||
|
||||
name = StringTools.replace (name, "native.", "browser.");
|
||||
return Type.resolveEnum (name);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user