Skip to content

Commit

Permalink
Add a little home page for acadnme-wasm
Browse files Browse the repository at this point in the history
  • Loading branch information
hughsando committed Oct 17, 2024
1 parent 37709a6 commit 9d89493
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 21 deletions.
1 change: 1 addition & 0 deletions acadnme/build.nmml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
<unset name="no_haxe_http" if="wasm" />
<engine name="Acadnme" version="6.0" />
<haxedef name="HXCPP_LINK_TOTAL_MEMORY" value="32000000"/>

<haxeflag name="-dce no" />

<certificate path="${KEYSTORE_PATH}/android.keystore" alias="nme" password="${KEYSTORE_PASSWD}" if="KEYSTORE_PASSWD KEYSTORE_PATH" />
Expand Down
10 changes: 6 additions & 4 deletions acadnme/src/Acadnme.hx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Acadnme extends Sprite implements IScriptHandler


instance = this;
var startServer = #if emscripten false #else true #end;
var startServer = #if web false #else true #end;

// For attaching a debugger
var delay = Sys.getEnv("ACADNME_DELAY")!=null;
Expand Down Expand Up @@ -83,18 +83,20 @@ class Acadnme extends Sprite implements IScriptHandler
}
nme.system.System.setArgs(unusedArgs);

Server.functions["log"] = function(x) { scriptLog(x); return "ok"; }

server = new Server("Acadnme", Sys.getEnv("ACADNME_DIR"), this );
directory = server.directory;

if (startServer)
{
Server.functions["log"] = function(x) { scriptLog(x); return "ok"; }
server = new Server("Acadnme", Sys.getEnv("ACADNME_DIR"), this );
directory = server.directory;
server.start();
connectionStatus = server.connectedHost;
}
else
{
connectionStatus = "Not started";
}

if (script!=null)
{
Expand Down
2 changes: 2 additions & 0 deletions project/src/sdl2/SDL2Stage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2634,7 +2634,9 @@ void CreateMainFrame(FrameCreationCallback inOnFrame, int inWidth, int inHeight,
#else
int renderFlags = 0;
if (hardware) renderFlags |= SDL_RENDERER_ACCELERATED;
#ifndef EMSCRIPTEN
if (hardware && vsync) renderFlags |= SDL_RENDERER_PRESENTVSYNC;
#endif
renderer = SDL_CreateRenderer(window, -1, renderFlags);
#endif

Expand Down
124 changes: 107 additions & 17 deletions samples/AcadnmeBoot/src/AcadnmeBoot.hx
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import cpp.cppia.HostClasses;

import nme.display.Sprite;
import nme.display.Bitmap;
import nme.display.BitmapData;
import nme.display.*;
import nme.script.Server;
import nme.geom.Point;
import nme.Assets;
Expand Down Expand Up @@ -37,6 +35,7 @@ class AcadnmeBoot extends Screen implements IBoot
var button:Button;
var nmeVersion:String;
var isWeb:Bool;
var listenStage:Stage;

public function new()
{
Expand Down Expand Up @@ -98,33 +97,103 @@ class AcadnmeBoot extends Screen implements IBoot
var hostBar = new Widget({ align:Layout.AlignCenterY });
hostBar.setItemLayout( new HorizontalLayout([1,0]).stretch() );

if (url==null)
if (!isWeb)
{
hostBar.addWidget(new TextLabel("Host:" + getConnectionStatus(),{ textColor:accent, align:Layout.AlignCenterY|Layout.AlignStretch }) );
hostBar.addWidget( button = Button.BMPButton( createMenuIcon(), onMenu, { shape:ShapeNone } ) );
}
else
{
hostBar.addWidget(new TextLabel("",{ textColor:accent, align:Layout.AlignCenterY|Layout.AlignStretch }) );
hostBar.addWidget( button = Button.TextButton( "Load .nme file", onMenu, {
textColor:0xffffff,
//line:LineSolid(1,0xff0000,1),
line:LineNone,
//fill:FillSolid(0xffffff,0.25),
fill:FillSolid(0xffa080,1),
shape:ShapeRoundRect,
margin:pad,
} ) );
}

hostBar.addWidget( button = Button.BMPButton( createMenuIcon(), onMenu, { shape:ShapeNone } ) );
hostBar.build();

titleBar.addWidget(hostBar);
titleBar.build();


tileCtrl = new TileControl(["Stretch"], { padding:new Rectangle(10,0,20,10), columnWidth:400});
fillList();
addWidget(tileCtrl);
if (isWeb)
{
var tl = new TextLabel("Welcome To NME!", {
multiline:true,
wordwrap:true,
itemAlign:Layout.AlignTop,
}
);
var tf = tl.getLabel();
tf.htmlText = [
"<br>",
"<font size='32'><b>Welcome To NME!</b></font>",
"<br>",
"1. Compile your programs with <u>NME</u>.",
"<br>",
" <i>nme cppia installer</i>",
"<br>",
"2. Run your .nme files using the button in the title bar!",
"<br>",
].join("\n");
addChild(tf);
var b = skin.scale(10);
var layout = new TextLayout(tf).setBorders(b,b,b,b).stretch();
getItemLayout().add(layout);
}
else
{
tileCtrl = new TileControl(["Stretch"], { padding:new Rectangle(10,0,20,10), columnWidth:400});
fillList();
addWidget(tileCtrl);
addListeners();
}

build();
makeCurrent();

/*
CORS issues here
if (isWeb)
{
var q = nme.Lib.getWebpageParam("prog");
if (q!=null && q!="")
downloadAndRun(q);
}
*/
}

function onDropFiles(e:DropEvent)
{
var items = e.items;
if (items!=null && items.length==1)
{
launch(items[0]);
}
}

function addListeners()
{
listenStage = stage;
listenStage.addEventListener(DropEvent.DROP_FILES, onDropFiles);
}

function removeListeners()
{
if (listenStage!=null)
{
listenStage.removeEventListener(DropEvent.DROP_FILES, onDropFiles);
listenStage = null;
}
}


function downloadAndRun(url:String)
{
var loader = new URLLoader();
Expand All @@ -146,7 +215,7 @@ class AcadnmeBoot extends Screen implements IBoot
if (bytes==null)
warn("Error Loading Data","No data.");
else
Acadnme.runScriptBytes(bytes);
runBytes(bytes);
}
});
var lastPct = 0;
Expand Down Expand Up @@ -273,25 +342,43 @@ class AcadnmeBoot extends Screen implements IBoot
if (name=="" || name==null)
return "usage : launch appName";

var path = launchScript.get(name);
if (path==null)
var path = null;
if (launchScript!=null)
{
for(k in launchScript.keys())
path = launchScript.get(name);
if (path==null)
{
var parts = k.split(".");
if (parts[ parts.length-1 ]==name)
path = launchScript[k];
for(k in launchScript.keys())
{
var parts = k.split(".");
if (parts[ parts.length-1 ]==name)
path = launchScript[k];
}
}
}
if (path==null && FileSystem.exists(name) )
path = name;
if (path==null)
return 'Unknown application $name';
haxe.Timer.delay( function() Acadnme.runScript(path), 0 );
haxe.Timer.delay( () -> run(path), 0 );
return "launched...";
};


function runBytes(bytes:ByteArray)
{
removeListeners();
Acadnme.runScriptBytes(bytes);
}

function run(path:String)
{
removeListeners();
Acadnme.runScript(path);
}



function apps() : String
{
var result = new Array<String>();
Expand Down Expand Up @@ -380,7 +467,7 @@ class AcadnmeBoot extends Screen implements IBoot
public function onSelect(path:String):Void
{
if (path!=null)
Acadnme.runScript(path);
run(path);
}

function addNmeApp(appName:String, details:Dynamic,path:String)
Expand Down Expand Up @@ -450,6 +537,9 @@ class AcadnmeBoot extends Screen implements IBoot

public function fillList()
{
if (isWeb)
return;

launchScript = new Map<String, String>();
tileCtrl.clear();

Expand Down
1 change: 1 addition & 0 deletions src/nme/app/Window.hx
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ class Window
appEventHandler.onDpiChanged(event);

case EventId.DropBegin, EventId.DropFile, EventId.DropEnd:
appEventHandler.onDrop(event);

case EventId.WindowClose:
appEventHandler.onWindowClose();
Expand Down

0 comments on commit 9d89493

Please sign in to comment.