Unify preloading code
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -15,3 +15,4 @@ project/winrt/shaders/
|
|||||||
*.swp
|
*.swp
|
||||||
.idea/
|
.idea/
|
||||||
*.iml
|
*.iml
|
||||||
|
tools/run.n
|
||||||
|
|||||||
@@ -29,13 +29,21 @@ class Preloader #if flash extends Sprite #end {
|
|||||||
public function init (config:Config):Void {
|
public function init (config:Config):Void {
|
||||||
|
|
||||||
#if flash
|
#if flash
|
||||||
|
Lib.current.stage.align = flash.display.StageAlign.TOP_LEFT;
|
||||||
|
Lib.current.stage.scaleMode = flash.display.StageScaleMode.NO_SCALE;
|
||||||
|
|
||||||
Lib.current.addChild (this);
|
Lib.current.addChild (this);
|
||||||
|
|
||||||
Lib.current.loaderInfo.addEventListener (Event.COMPLETE, loaderInfo_onComplete);
|
Lib.current.loaderInfo.addEventListener (Event.COMPLETE, loaderInfo_onComplete);
|
||||||
Lib.current.loaderInfo.addEventListener (Event.INIT, loaderInfo_onInit);
|
Lib.current.loaderInfo.addEventListener (Event.INIT, loaderInfo_onInit);
|
||||||
Lib.current.loaderInfo.addEventListener (ProgressEvent.PROGRESS, loaderInfo_onProgress);
|
Lib.current.loaderInfo.addEventListener (ProgressEvent.PROGRESS, loaderInfo_onProgress);
|
||||||
Lib.current.addEventListener (Event.ENTER_FRAME, current_onEnter);
|
Lib.current.addEventListener (Event.ENTER_FRAME, current_onEnter);
|
||||||
#end
|
#end
|
||||||
|
|
||||||
|
#if !flash
|
||||||
|
start ();
|
||||||
|
#end
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,11 @@
|
|||||||
package lime.system;
|
package lime.system;
|
||||||
|
|
||||||
|
|
||||||
|
#if js
|
||||||
|
import js.html.HtmlElement;
|
||||||
|
import js.Browser;
|
||||||
|
#end
|
||||||
|
|
||||||
#if sys
|
#if sys
|
||||||
import sys.io.Process;
|
import sys.io.Process;
|
||||||
#end
|
#end
|
||||||
@@ -16,6 +21,56 @@ class System {
|
|||||||
#end
|
#end
|
||||||
|
|
||||||
|
|
||||||
|
#if js
|
||||||
|
@:keep @:expose("lime.embed")
|
||||||
|
public static function embed (elementName:String, width:Null<Int> = null, height:Null<Int> = null, background:String = null) {
|
||||||
|
|
||||||
|
var element:HtmlElement = null;
|
||||||
|
|
||||||
|
if (elementName != null) {
|
||||||
|
|
||||||
|
element = cast Browser.document.getElementById (elementName);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
var color = null;
|
||||||
|
|
||||||
|
if (background != null) {
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
ApplicationMain.config.background = color;
|
||||||
|
ApplicationMain.config.element = element;
|
||||||
|
ApplicationMain.init ();
|
||||||
|
|
||||||
|
}
|
||||||
|
#end
|
||||||
|
|
||||||
|
|
||||||
static private function findHaxeLib (library:String):String {
|
static private function findHaxeLib (library:String):String {
|
||||||
|
|
||||||
#if sys
|
#if sys
|
||||||
|
|||||||
@@ -1,56 +0,0 @@
|
|||||||
import ::APP_MAIN::;
|
|
||||||
|
|
||||||
|
|
||||||
class ApplicationMain {
|
|
||||||
|
|
||||||
|
|
||||||
private static var app:lime.app.Application;
|
|
||||||
private static var config:lime.app.Config;
|
|
||||||
private static var preloader:lime.app.Preloader;
|
|
||||||
|
|
||||||
|
|
||||||
public static function main () {
|
|
||||||
|
|
||||||
flash.Lib.current.stage.align = flash.display.StageAlign.TOP_LEFT;
|
|
||||||
flash.Lib.current.stage.scaleMode = flash.display.StageScaleMode.NO_SCALE;
|
|
||||||
|
|
||||||
preloader = new ::if (PRELOADER_NAME != "")::::PRELOADER_NAME::::else::lime.app.Preloader::end:: ();
|
|
||||||
preloader.onComplete = start;
|
|
||||||
|
|
||||||
config = {
|
|
||||||
|
|
||||||
antialiasing: Std.int (::WIN_ANTIALIASING::),
|
|
||||||
borderless: ::WIN_BORDERLESS::,
|
|
||||||
depthBuffer: ::WIN_DEPTH_BUFFER::,
|
|
||||||
fps: Std.int (::WIN_FPS::),
|
|
||||||
fullscreen: ::WIN_FULLSCREEN::,
|
|
||||||
height: Std.int (::WIN_HEIGHT::),
|
|
||||||
orientation: "::WIN_ORIENTATION::",
|
|
||||||
resizable: ::WIN_RESIZABLE::,
|
|
||||||
stencilBuffer: ::WIN_STENCIL_BUFFER::,
|
|
||||||
title: "::APP_TITLE::",
|
|
||||||
vsync: ::WIN_VSYNC::,
|
|
||||||
width: Std.int (::WIN_WIDTH::),
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
preloader.init (config);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private static function start ():Void {
|
|
||||||
|
|
||||||
app = new ::APP_MAIN:: ();
|
|
||||||
app.create (config);
|
|
||||||
|
|
||||||
var result = app.exec ();
|
|
||||||
|
|
||||||
//#if sys
|
|
||||||
//Sys.exit (result);
|
|
||||||
//#end
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -4,14 +4,24 @@ import ::APP_MAIN::;
|
|||||||
class ApplicationMain {
|
class ApplicationMain {
|
||||||
|
|
||||||
|
|
||||||
private var app:lime.app.Application;
|
public static var config:lime.app.Config;
|
||||||
|
public static var preloader:lime.app.Preloader;
|
||||||
|
|
||||||
|
private static var app:lime.app.Application;
|
||||||
|
|
||||||
|
|
||||||
|
public static function init ():Void {
|
||||||
|
|
||||||
|
preloader = new ::if (PRELOADER_NAME != "")::::PRELOADER_NAME::::else::lime.app.Preloader::end:: ();
|
||||||
|
preloader.onComplete = start;
|
||||||
|
preloader.init (config);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static function main () {
|
public static function main () {
|
||||||
|
|
||||||
var app = new ::APP_MAIN:: ();
|
config = {
|
||||||
|
|
||||||
var config:lime.app.Config = {
|
|
||||||
|
|
||||||
antialiasing: Std.int (::WIN_ANTIALIASING::),
|
antialiasing: Std.int (::WIN_ANTIALIASING::),
|
||||||
borderless: ::WIN_BORDERLESS::,
|
borderless: ::WIN_BORDERLESS::,
|
||||||
@@ -28,6 +38,18 @@ class ApplicationMain {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if (js && munit)
|
||||||
|
embed (null, ::WIN_WIDTH::, ::WIN_HEIGHT::, "::WIN_FLASHBACKGROUND::");
|
||||||
|
#else
|
||||||
|
init ();
|
||||||
|
#end
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static function start ():Void {
|
||||||
|
|
||||||
|
app = new ::APP_MAIN:: ();
|
||||||
app.create (config);
|
app.create (config);
|
||||||
|
|
||||||
var result = app.exec ();
|
var result = app.exec ();
|
||||||
|
|||||||
@@ -1,92 +0,0 @@
|
|||||||
import ::APP_MAIN::;
|
|
||||||
|
|
||||||
|
|
||||||
class ApplicationMain {
|
|
||||||
|
|
||||||
|
|
||||||
private var app:lime.app.Application;
|
|
||||||
|
|
||||||
|
|
||||||
@:keep @:expose("lime.embed")
|
|
||||||
public static function embed (elementName:String, width:Null<Int> = null, height:Null<Int> = null, background:String = null) {
|
|
||||||
|
|
||||||
var element:js.html.HtmlElement = null;
|
|
||||||
|
|
||||||
if (elementName != null) {
|
|
||||||
|
|
||||||
element = cast js.Browser.document.getElementById (elementName);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
var color = null;
|
|
||||||
|
|
||||||
if (background != null) {
|
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
var app = new ::APP_MAIN:: ();
|
|
||||||
|
|
||||||
var config:lime.app.Config = {
|
|
||||||
|
|
||||||
antialiasing: Std.int (::WIN_ANTIALIASING::),
|
|
||||||
background: color,
|
|
||||||
borderless: ::WIN_BORDERLESS::,
|
|
||||||
depthBuffer: ::WIN_DEPTH_BUFFER::,
|
|
||||||
element: element,
|
|
||||||
fps: Std.int (::WIN_FPS::),
|
|
||||||
fullscreen: ::WIN_FULLSCREEN::,
|
|
||||||
height: height,
|
|
||||||
orientation: "::WIN_ORIENTATION::",
|
|
||||||
resizable: ::WIN_RESIZABLE::,
|
|
||||||
stencilBuffer: ::WIN_STENCIL_BUFFER::,
|
|
||||||
title: "::APP_TITLE::",
|
|
||||||
vsync: ::WIN_VSYNC::,
|
|
||||||
width: width,
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
app.create (config);
|
|
||||||
|
|
||||||
var result = app.exec ();
|
|
||||||
|
|
||||||
//#if sys
|
|
||||||
//Sys.exit (result);
|
|
||||||
//#end
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static function main () {
|
|
||||||
|
|
||||||
#if munit
|
|
||||||
embed (null, ::WIN_WIDTH::, ::WIN_HEIGHT::, "::WIN_FLASHBACKGROUND::");
|
|
||||||
#end
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user