|
1 | | -<html lang="en-us"><script src="{{cookiecutter.cdn}}pythons.js" type=module id="site" data-python="python{{cookiecutter.PYBUILD}}" data-LINES=42 data-COLUMNS=132 data-os="vtx,snd,gui" async defer>#<!-- |
| 1 | +<html lang="en-us"><script src="{{cookiecutter.cdn}}pythons.js" type=module id="site" data-python="python{{cookiecutter.PYBUILD}}" data-LINES=42 data-COLUMNS=132 data-os="vtx,gui" async defer>#<!-- |
| 2 | + |
| 3 | +# The template is based on https://github.com/pygame-web/pygbag/blob/main/static/default.tmpl |
2 | 4 |
|
3 | 5 | print(""" |
4 | 6 | Loading {{cookiecutter.title}} from {{cookiecutter.archive}}.apk |
@@ -59,25 +61,6 @@ async def custom_site(): |
59 | 61 |
|
60 | 62 | main = appdir / "assets" / "main.py" |
61 | 63 |
|
62 | | - # TODO: test for window.webkitAudioContext and block aio loop until gesture if accessing media manager play |
63 | | - # before a gesture is recorded ( touch or click ) |
64 | | - |
65 | | - # test/wait user media interaction |
66 | | - if not platform.window.MM.UME: |
67 | | - |
68 | | - # now that apk is mounted we have access to font cache |
69 | | - # but we need to fill __file__ that is not yet set |
70 | | - __import__(__name__).__file__ = main |
71 | | - |
72 | | - # now make a prompt |
73 | | - print("Ready to start !") |
74 | | - |
75 | | - print(""" |
76 | | - * Waiting for media user engagement : please click/touch page * |
77 | | - """) |
78 | | - while not platform.window.MM.UME: |
79 | | - await asyncio.sleep(.1) |
80 | | - |
81 | 64 | # start async top level machinery if not started and add a console in any case if requested. |
82 | 65 | await TopLevel_async_handler.start_toplevel(platform.shell, console=window.python.config.debug) |
83 | 66 |
|
@@ -143,7 +126,7 @@ asyncio.run( custom_site() ) |
143 | 126 | config = { |
144 | 127 | xtermjs : "{{cookiecutter.xtermjs}}" , |
145 | 128 | _sdl2 : "canvas", |
146 | | - user_canvas : 0, |
| 129 | + user_canvas : 1, |
147 | 130 | user_canvas_managed : 0, |
148 | 131 | gui_divider : 2, |
149 | 132 | ume_block : {{cookiecutter.ume_block}}, |
@@ -353,6 +336,8 @@ frameborder="1" |
353 | 336 | // make your js customization here |
354 | 337 | console.log(__FILE__, "custom_onload") |
355 | 338 |
|
| 339 | + //debug_hidden = false //!!! use this for debug |
| 340 | + |
356 | 341 | pyconsole.hidden = debug_hidden |
357 | 342 | system.hidden = debug_hidden |
358 | 343 | transfer.hidden = debug_hidden |
@@ -401,6 +386,72 @@ frameborder="1" |
401 | 386 | window.frames["iframe"].location = url; |
402 | 387 | } |
403 | 388 |
|
| 389 | + |
| 390 | + |
| 391 | + |
| 392 | + // Visual Lambda stuff |
| 393 | + // localStorage exchange |
| 394 | + function setStorageValue(name, newValue, separator = undefined) { |
| 395 | + let key = "storage_" + name; |
| 396 | + let value = undefined; |
| 397 | + if (separator) { |
| 398 | + value = window.localStorage.getItem(key); |
| 399 | + if (value) { |
| 400 | + value += separator + newValue; |
| 401 | + } else { |
| 402 | + value = newValue; |
| 403 | + } |
| 404 | + } else { |
| 405 | + value = newValue; |
| 406 | + } |
| 407 | + window.localStorage.setItem(key, value); |
| 408 | + } |
| 409 | + |
| 410 | + function addItem(expression) { |
| 411 | + setStorageValue("addItem", expression, "|"); |
| 412 | + } |
| 413 | + function clearWorkspace() { |
| 414 | + setStorageValue("clearWorkspace", "1"); |
| 415 | + } |
| 416 | + function saveWorkspace(workspaceName) { |
| 417 | + setStorageValue("saveWorkspace", workspaceName); |
| 418 | + } |
| 419 | + function loadWorkspace(workspaceName) { |
| 420 | + setStorageValue("loadWorkspace", workspaceName); |
| 421 | + } |
| 422 | + function help() { |
| 423 | + console.log("addItem(expression) - add an item by expression, e.g. addItem('\\x. x x')"); |
| 424 | + console.log("clearWorkspace() - clear the workspace"); |
| 425 | + console.log("saveWorkspace(workspaceName) - save current workspace to localStorage, e.g. saveWorkspace('combinators3')"); |
| 426 | + console.log("loadWorkspace(workspaceName) - load a workspace from localStorage, e.g. loadWorkspace('combinators3')"); |
| 427 | + } |
| 428 | + |
| 429 | + // Allow using browser console through an iframe on itch.io |
| 430 | + window.addEventListener('message', event => { |
| 431 | + //console.log(event); |
| 432 | + if (event.origin !== "https://bntr.itch.io") return; |
| 433 | + const method = event.data[0]; |
| 434 | + if (method === "addItem") { |
| 435 | + addItem(event.data[1]); |
| 436 | + } else if (method === "clearWorkspace") { |
| 437 | + clearWorkspace(); |
| 438 | + } else if (method === "saveWorkspace") { |
| 439 | + saveWorkspace(event.data[1]) |
| 440 | + } else if (method === "loadWorkspace") { |
| 441 | + loadWorkspace(event.data[1]); |
| 442 | + } |
| 443 | + }); |
| 444 | + |
| 445 | + // Then in browser console: |
| 446 | + //> function vl(...args) { document.getElementById("game_drop").contentWindow.postMessage(args, "*") } |
| 447 | + //> vl('addItem','MULT 2 (\\f x. f (f x))') |
| 448 | + //> vl('clearWorkspace') |
| 449 | + //> vl('saveWorkspace', 'combinators3') |
| 450 | + //> vl('loadWorkspace', 'combinators3') |
| 451 | + |
| 452 | + |
| 453 | + |
| 454 | + |
404 | 455 | </script> |
405 | 456 |
|
406 | 457 | </body> |
|
0 commit comments