SOURCE / PINNED RELEASE
Made of little things.
Powder Tool V600Billion
- Release
- 142767edcab8…
- Author-recorded commit
- 6d92971effd0…
- License
- LICENSE
- Author’s source reference
- nostr://npub1fllw8kw0thjj55wds0uugcnp5kej2nfxd36eruq39d56wwz8r44q5q78wj/wss%3A%2F%2Fgit.napplet.soy%2F/powder-toy
Archive hash verified: ed7d6a8ea7083197…. The source-to-build association is the author’s claim; it has not been independently rebuilt.
The Powder Toy v100.1.400 (d768aeb89acad986bd252d7e904bf44bb374545f) for the web:
two functions for the page around the game, for the Powder Toy napplet
(BIMbeamFLX/powder-toy-napplet, GPL-3.0 like upstream). Applies after
the-powder-toy-single-thread.patch.
The napplet draws its own controls around the game (element palette, tool bar,
scenes) and drives the game through its Lua API, the same one the console uses:
- Napplet_Lua(code) runs Lua as the console does and returns "ok:" or "error:"
followed by what the console would print. A line someone is still typing in
the console (its continuation buffer) is kept aside meanwhile.
- Napplet_GameViewActive() says whether the game's own view is on top, so the
page hides its controls while one of the game's dialogs, the save browser or
the console is open.
Both are exported with EMSCRIPTEN_KEEPALIVE and called through ccall once the
game has marked itself presentable. Nothing else changes.
Applied by scripts/build-wasm.sh with git apply.
diff --git a/src/PowderToySDLEmscripten.cpp b/src/PowderToySDLEmscripten.cpp
index 408ea99..6458e5d 100644
--- a/src/PowderToySDLEmscripten.cpp
+++ b/src/PowderToySDLEmscripten.cpp
@@ -1,5 +1,7 @@
#include "PowderToySDL.h"
#include "gui/interface/Engine.h"
+#include "gui/game/GameView.h"
+#include "lua/LuaScriptInterface.h"
#include <emscripten.h>
#include <iostream>
@@ -62,3 +64,29 @@ void MainLoop()
ApplyFpsLimit();
MainLoopBody();
}
+
+// For the page around the game (the napplet's own controls, not upstream's).
+// Both may only be called once the game has marked itself presentable: the
+// Lua state and the game view exist from then on.
+
+// Runs Lua as the console does ("ok:" or "error:", then what the console would
+// print), without taking over a line someone is still typing in the console.
+extern "C" EMSCRIPTEN_KEEPALIVE const char *Napplet_Lua(const char *code)
+{
+ static ByteString result;
+ auto *lsi = static_cast<LuaScriptInterface *>(&CommandInterface::Ref());
+ auto consoleCode = lsi->lastCode;
+ lsi->lastCode = "";
+ auto status = lsi->Command(ByteString(code).FromUtf8());
+ result = ByteString(status ? "error:" : "ok:") + lsi->GetLastError().ToUtf8();
+ lsi->lastCode = consoleCode;
+ return result.c_str();
+}
+
+// Whether the game's own view is the window on top (no dialog, browser or
+// console over it).
+extern "C" EMSCRIPTEN_KEEPALIVE int Napplet_GameViewActive()
+{
+ auto *lsi = static_cast<LuaScriptInterface *>(&CommandInterface::Ref());
+ return ui::Engine::Ref().GetWindow() == lsi->window;
+}
