mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2025-12-02 15:39:57 +00:00
Implemented LittleJS run logic https://chatgpt.com/share/692894bc-5a58-800f-b803-eb906c3cec65
This commit is contained in:
@@ -19,9 +19,8 @@ def littlejs_href(example, protocol, domain):
|
|||||||
if is_project:
|
if is_project:
|
||||||
return f"{protocol}://{domain}/examples/{file}/"
|
return f"{protocol}://{domain}/examples/{file}/"
|
||||||
|
|
||||||
# Short examples: internal wrapper
|
# Non-full shorts: use custom runner without example browser overhead
|
||||||
return f"{protocol}://{domain}/examples/shorts/base.html?file={file}"
|
return f"{protocol}://{domain}/examples/shorts/run.html?file={file}"
|
||||||
|
|
||||||
|
|
||||||
class FilterModule(object):
|
class FilterModule(object):
|
||||||
def filters(self):
|
def filters(self):
|
||||||
|
|||||||
@@ -17,6 +17,15 @@
|
|||||||
- docker compose build
|
- docker compose build
|
||||||
- docker compose up
|
- docker compose up
|
||||||
|
|
||||||
|
- name: "Render LittleJS run.html for shorts"
|
||||||
|
template:
|
||||||
|
src: "html/run.html.j2"
|
||||||
|
dest: "{{ LITTLEJS_RUN_HOST_ABS }}"
|
||||||
|
mode: "0644"
|
||||||
|
notify:
|
||||||
|
- docker compose build
|
||||||
|
- docker compose up
|
||||||
|
|
||||||
- name: "flush docker compose for '{{ application_id }}'"
|
- name: "flush docker compose for '{{ application_id }}'"
|
||||||
meta: flush_handlers
|
meta: flush_handlers
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
# roles/web-app-littlejs/templates/Dockerfile.j2
|
|
||||||
FROM nginx:alpine
|
FROM nginx:alpine
|
||||||
|
|
||||||
# Static LittleJS assets – engine builds + examples
|
# Static LittleJS assets – engine builds + examples
|
||||||
@@ -7,3 +6,6 @@ COPY ./{{ LITTLEJS_APP_REL }}/dist /usr/share/nginx/html/dist
|
|||||||
|
|
||||||
# Custom Infinito.Nexus landing page with Bootstrap menu and tiles
|
# Custom Infinito.Nexus landing page with Bootstrap menu and tiles
|
||||||
COPY ./{{ LITTLEJS_INDEX_HOST_REL }} /usr/share/nginx/html/index.html
|
COPY ./{{ LITTLEJS_INDEX_HOST_REL }} /usr/share/nginx/html/index.html
|
||||||
|
|
||||||
|
# Custom runner for non-full LittleJS shorts examples
|
||||||
|
COPY ./{{ LITTLEJS_RUN_HOST_REL }} /usr/share/nginx/html/examples/shorts/run.html
|
||||||
|
|||||||
69
roles/web-app-littlejs/templates/html/run.html.j2
Normal file
69
roles/web-app-littlejs/templates/html/run.html.j2
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<title>LittleJS Example</title>
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<!-- LittleJS engine bundle -->
|
||||||
|
<script src="../../dist/littlejs.js"></script>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
(function () {
|
||||||
|
// Read ?file=... from query string
|
||||||
|
const params = new URLSearchParams(window.location.search);
|
||||||
|
let file = params.get("file") || "helloWorld.js";
|
||||||
|
|
||||||
|
// Basic safety: keep file in current directory and avoid traversal
|
||||||
|
if (file.includes("/") || file.includes("\\")) {
|
||||||
|
console.warn("Invalid file parameter, falling back to default");
|
||||||
|
file = "helloWorld.js";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!file.endsWith(".js")) {
|
||||||
|
file = file + ".js";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Dynamically load the selected example script from /examples/shorts/
|
||||||
|
const script = document.createElement("script");
|
||||||
|
script.src = file;
|
||||||
|
|
||||||
|
script.onload = () => {
|
||||||
|
console.log("Loaded LittleJS example:", file);
|
||||||
|
|
||||||
|
if (typeof window.engineInit !== "function") {
|
||||||
|
console.error("LittleJS engineInit not found");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fallbacks if some callbacks are not defined by the example
|
||||||
|
const gameInit = window.gameInit || function(){};
|
||||||
|
const gameUpdate = window.gameUpdate || function(){};
|
||||||
|
const gameUpdatePost = window.gameUpdatePost || function(){};
|
||||||
|
const gameRender = window.gameRender || function(){};
|
||||||
|
const gameRenderPost = window.gameRenderPost || function(){};
|
||||||
|
|
||||||
|
// Start LittleJS engine similar to the Example Browser
|
||||||
|
Promise.resolve(
|
||||||
|
window.engineInit(
|
||||||
|
gameInit,
|
||||||
|
gameUpdate,
|
||||||
|
gameUpdatePost,
|
||||||
|
gameRender,
|
||||||
|
gameRenderPost,
|
||||||
|
['tiles.png?' + Date.now()]
|
||||||
|
)
|
||||||
|
).catch((error) => {
|
||||||
|
console.error("Error starting LittleJS engine:", error);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
script.onerror = () => {
|
||||||
|
console.error("Failed to load LittleJS example:", file);
|
||||||
|
};
|
||||||
|
|
||||||
|
document.body.appendChild(script);
|
||||||
|
})();
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
# General
|
# General
|
||||||
application_id: "web-app-littlejs"
|
application_id: "web-app-littlejs"
|
||||||
entity_name: "{{ application_id | get_entity_name }}"
|
entity_name: "{{ application_id | get_entity_name }}"
|
||||||
domain: "{{ domains | get_domain(application_id) }}"
|
domain: "{{ domains | get_domain(application_id) }}"
|
||||||
|
|
||||||
LITTLEJS_HEADLINE: "LittleJS Playground"
|
LITTLEJS_HEADLINE: "LittleJS Playground"
|
||||||
|
|
||||||
@@ -23,3 +23,9 @@ LITTLEJS_INDEX_HOST_REL: "volumes/index.html"
|
|||||||
# Helper variables
|
# Helper variables
|
||||||
LITTLEJS_CONTAINER: "{{ entity_name }}"
|
LITTLEJS_CONTAINER: "{{ entity_name }}"
|
||||||
LITTLEJS_SERVICE: "{{ entity_name }}"
|
LITTLEJS_SERVICE: "{{ entity_name }}"
|
||||||
|
|
||||||
|
|
||||||
|
# Runner HTML for non-full examples
|
||||||
|
LITTLEJS_RUN_HOST_ABS: "{{ [ docker_compose.directories.volumes, 'run.html' ] | path_join }}"
|
||||||
|
LITTLEJS_RUN_HOST_REL: "volumes/run.html"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user