Move lime.embed to ApplicationMain template

This commit is contained in:
Joshua Granick
2016-10-20 08:19:24 -07:00
parent 525a51d07f
commit 6dc05a26c9
2 changed files with 103 additions and 105 deletions

View File

@@ -10,7 +10,6 @@ import flash.Lib;
#end
#if (js && html5)
import js.html.Element;
import js.Browser;
#end
@@ -43,69 +42,6 @@ class System {
@:noCompletion private static var __directories = new Map<SystemDirectory, String> ();
#if (js && html5)
@:keep @:expose("lime.embed")
public static function embed (element:Dynamic, width:Null<Int> = null, height:Null<Int> = null, background:String = null, assetsPrefix:String = null) {
var htmlElement:Element = null;
if (Std.is (element, String)) {
htmlElement = cast Browser.document.getElementById (cast (element, String));
} else if (element == null) {
htmlElement = cast Browser.document.createElement ("div");
} else {
htmlElement = cast element;
}
var color = null;
if (background != null && background != "") {
background = StringTools.replace (background, "#", "");
if (background.indexOf ("0x") > -1) {
color = Std.parseInt (background);
} else {
color = Std.parseInt ("0x" + background);
}
}
if (width == null) {
width = 0;
}
if (height == null) {
height = 0;
}
#if tools
ApplicationMain.config.windows[0].background = color;
ApplicationMain.config.windows[0].element = htmlElement;
ApplicationMain.config.windows[0].width = width;
ApplicationMain.config.windows[0].height = height;
ApplicationMain.config.assetsPrefix = assetsPrefix;
ApplicationMain.create ();
#end
}
#end
public static function exit (code:Int):Void {
#if android

View File

@@ -14,6 +14,53 @@ class ApplicationMain {
private static var app:lime.app.Application;
public static function main () {
config = {
build: "::meta.buildNumber::",
company: "::meta.company::",
file: "::APP_FILE::",
fps: ::WIN_FPS::,
name: "::meta.title::",
orientation: "::WIN_ORIENTATION::",
packageName: "::meta.packageName::",
version: "::meta.version::",
windows: [
::foreach windows::
{
allowHighDPI: ::allowHighDPI::,
antialiasing: ::antialiasing::,
background: ::background::,
borderless: ::borderless::,
depthBuffer: ::depthBuffer::,
display: ::display::,
fullscreen: ::fullscreen::,
hardware: ::hardware::,
height: ::height::,
hidden: #if munit true #else ::hidden:: #end,
maximized: ::maximized::,
minimized: ::minimized::,
parameters: "::parameters::",
resizable: ::resizable::,
stencilBuffer: ::stencilBuffer::,
title: "::title::",
vsync: ::vsync::,
width: ::width::,
x: ::x::,
y: ::y::
},::end::
]
};
#if (!html5 || munit)
create ();
#end
}
public static function create ():Void {
preloader = new ::if (PRELOADER_NAME != "")::::PRELOADER_NAME::::else::lime.app.Preloader::end:: ();
@@ -62,51 +109,66 @@ class ApplicationMain {
}
public static function main () {
#if (js && html5)
@:keep @:expose("lime.embed")
public static function embed (element:Dynamic, width:Null<Int> = null, height:Null<Int> = null, background:String = null, assetsPrefix:String = null) {
config = {
build: "::meta.buildNumber::",
company: "::meta.company::",
file: "::APP_FILE::",
fps: ::WIN_FPS::,
name: "::meta.title::",
orientation: "::WIN_ORIENTATION::",
packageName: "::meta.packageName::",
version: "::meta.version::",
windows: [
::foreach windows::
{
allowHighDPI: ::allowHighDPI::,
antialiasing: ::antialiasing::,
background: ::background::,
borderless: ::borderless::,
depthBuffer: ::depthBuffer::,
display: ::display::,
fullscreen: ::fullscreen::,
hardware: ::hardware::,
height: ::height::,
hidden: #if munit true #else ::hidden:: #end,
maximized: ::maximized::,
minimized: ::minimized::,
parameters: "::parameters::",
resizable: ::resizable::,
stencilBuffer: ::stencilBuffer::,
title: "::title::",
vsync: ::vsync::,
width: ::width::,
x: ::x::,
y: ::y::
},::end::
]
};
var htmlElement:js.html.Element = null;
if (Std.is (element, String)) {
htmlElement = cast js.Browser.document.getElementById (cast (element, String));
} else if (element == null) {
htmlElement = cast js.Browser.document.createElement ("div");
} else {
htmlElement = cast element;
}
var color = null;
if (background != null && background != "") {
background = StringTools.replace (background, "#", "");
if (background.indexOf ("0x") > -1) {
color = Std.parseInt (background);
} else {
color = Std.parseInt ("0x" + background);
}
}
if (width == null) {
width = 0;
}
if (height == null) {
height = 0;
}
config.windows[0].background = color;
config.windows[0].element = htmlElement;
config.windows[0].width = width;
config.windows[0].height = height;
config.assetsPrefix = assetsPrefix;
#if (!html5 || munit)
create ();
#end
}
#end
public static function start ():Void {
@@ -160,4 +222,4 @@ class ApplicationMain {
#end
}
}