Skip to content

Commit

Permalink
Allow bootType to be specified to avoid macro in build system and err…
Browse files Browse the repository at this point in the history
…or log
  • Loading branch information
hughsando committed Mar 25, 2024
1 parent b94fbf8 commit 98ef41d
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 10 deletions.
5 changes: 5 additions & 0 deletions templates/haxe/ApplicationBoot.hx
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
::if (APP_BOOT_TYPE!="BootTypeAuto")::
#error "ApplicationBoot should not be called unless ApplicationBoot==BootTypeAuto"
::else::

import haxe.macro.Expr;
import haxe.macro.Context;

Expand Down Expand Up @@ -50,3 +54,4 @@ class ApplicationBoot
return Context.parse("{}", p);
}
}
::end::
4 changes: 4 additions & 0 deletions templates/haxe/ApplicationDocument.hx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ class ApplicationDocument extends ::APP_MAIN::
}
#end

::if (APP_BOOT_TYPE=="BootTypeAuto")::
ApplicationBoot.callSuper();
::else::
super();
::end::

#if nme
if (added!=null && added.stage!=null)
Expand Down
42 changes: 33 additions & 9 deletions templates/haxe/ApplicationMain.hx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,20 @@ class ApplicationMain
public static var winBackground:Int = ::WIN_BACKGROUND::;
public static var onLoaded:Void->Void;


static function createInstance()
{
::if (APP_BOOT_TYPE=="BootTypeMain")::
::APP_MAIN::.main();
::elseif (APP_BOOT_TYPE=="BootTypeNew")::
new ::APP_MAIN::();
::elseif (APP_BOOT_TYPE=="BootTypeAddStage")::
new ApplicationDocument();
::else::
ApplicationBoot.createInstance();
::end::
}

public static function main()
{
#if cpp
Expand Down Expand Up @@ -111,7 +125,13 @@ class ApplicationMain
flash.Lib.current.stage.align = flash.display.StageAlign.TOP_LEFT;
flash.Lib.current.stage.scaleMode = flash.display.StageScaleMode.NO_SCALE;

var load = function() ApplicationBoot.createInstance();
function load() {
::if (APP_BOOT_TYPE=="BootTypeAuto")::
ApplicationBoot.createInstance();
::else::
new ApplicationDocument();
::end::
}

::if (PRELOADER_NAME!=null)::
onLoaded = load;
Expand All @@ -129,9 +149,15 @@ class ApplicationMain
nme.display.ManagedStage.initSdlAudio();
#end

::if (APP_BOOT_TYPE=="BootTypeMain")::
::APP_MAIN::.main();
::else::

::if (APP_BOOT_TYPE=="BootTypeAuto")::
if (ApplicationBoot.canCallMain())
ApplicationBoot.createInstance();
else
::end::
{
wx.App.boot(function()
{
Expand Down Expand Up @@ -163,11 +189,11 @@ class ApplicationMain

// Show frame before creating instance so context is good.
frame.shown = true;
ApplicationBoot.createInstance();
createInstance();
wx.App.setTopWindow(frame);

#else
ApplicationBoot.createInstance();
createInstance();
if (autoShowFrame)
{
wx.App.setTopWindow(frame);
Expand All @@ -177,9 +203,10 @@ class ApplicationMain

});
}
::end::
#elseif cppia
// Cppia
ApplicationBoot.createInstance();
createInstance();
#elseif nme
var flags:Int =
(::WIN_HARDWARE:: ? nme.app.Application.HARDWARE : 0) |
Expand Down Expand Up @@ -222,7 +249,7 @@ class ApplicationMain
nme.Lib.current.stage.align = nme.display.StageAlign.::STAGE_ALIGN::;
nme.Lib.current.stage.scaleMode = nme.display.StageScaleMode.::STAGE_SCALE::;
nme.Lib.current.loaderInfo = nme.display.LoaderInfo.create (null);
ApplicationBoot.createInstance();
createInstance();
},
::WIN_WIDTH::, ::WIN_HEIGHT::,
::WIN_FPS::,
Expand All @@ -237,10 +264,7 @@ class ApplicationMain
#end
#else
// Unknown framework
if (ApplicationBoot.canCallMain())
ApplicationBoot.createInstance();
else
ApplicationBoot.createInstance();
createInstance();
#end
}

Expand Down
4 changes: 4 additions & 0 deletions tools/nme/src/project/ApplicationData.hx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import BootType;


class ApplicationData
{
Expand All @@ -7,6 +9,7 @@ class ApplicationData
// Haxe main class
public var main:String;
public var preloader:String;
public var bootType = BootTypeAuto;

// Build directory base
public var binDir:String;
Expand All @@ -29,6 +32,7 @@ class ApplicationData
public var swfVersion:Float;



public function new()
{
file = "MyApplication";
Expand Down
7 changes: 7 additions & 0 deletions tools/nme/src/project/BootType.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
enum BootType
{
BootTypeAuto;
BootTypeMain;
BootTypeNew;
BootTypeAddStage;
}
8 changes: 7 additions & 1 deletion tools/nme/src/project/NMEProject.hx
Original file line number Diff line number Diff line change
Expand Up @@ -877,7 +877,13 @@ class NMEProject


for(field in Reflect.fields(app))
Reflect.setField(context, "APP_" + StringHelper.formatUppercaseVariable(field), Reflect.field(app, field));
{
var val:Dynamic = Reflect.field(app, field);
if (!Std.isOfType(val,Float))
val = "" + val;
Log.verbose(" APP_" + StringHelper.formatUppercaseVariable(field) + "=" + val);
Reflect.setField(context, "APP_" + StringHelper.formatUppercaseVariable(field), val);
}


context.APP_PACKAGE = app.packageName;
Expand Down
10 changes: 10 additions & 0 deletions tools/nme/src/project/NMMLParser.hx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import NMEProject;
import IconType;
import platforms.Platform;
import nme.AlphaMode;
import BootType;

using StringTools;

Expand Down Expand Up @@ -228,6 +229,15 @@ class NMMLParser
case "preloader":
project.app.preloader = substitute(element.att.preloader);

case "bootType":
var types = ["auto", "main", "new", "addStage" ];
var type = substitute(element.att.bootType);
var typeId = types.indexOf(type);
if (typeId<0)
Log.error('Invalid bootType "$type". Should be one of $types.');
project.app.bootType = Type.createEnumIndex( BootType, typeId );


case "package", "packageName", "package-name":
project.app.packageName = substitute(element.att.resolve(attribute));

Expand Down

0 comments on commit 98ef41d

Please sign in to comment.