summaryrefslogtreecommitdiff
path: root/2026/games/rpc2dot0/index.js
diff options
context:
space:
mode:
authorLLLL Colonq <llll@colonq>2026-08-18 00:08:28 -0400
committerLLLL Colonq <llll@colonq>2026-08-18 00:08:28 -0400
commit32a62cfcb925225359a5c90761b795f2f737ebd2 (patch)
tree95c2261964803b19f2d39cb35d8d514ed6e5a6f4 /2026/games/rpc2dot0/index.js
parentde99c5f7636a952025ea13de02bafd25bcb6bdec (diff)
Re-populate games
Diffstat (limited to '2026/games/rpc2dot0/index.js')
-rw-r--r--2026/games/rpc2dot0/index.js48
1 files changed, 48 insertions, 0 deletions
diff --git a/2026/games/rpc2dot0/index.js b/2026/games/rpc2dot0/index.js
new file mode 100644
index 0000000..2a8d674
--- /dev/null
+++ b/2026/games/rpc2dot0/index.js
@@ -0,0 +1,48 @@
+import init, { main_js, set_difficulty_js, receive_op_js } from './pkg/eatyourgreens.js';
+
+let is_embedded = false;
+let currentDifficulty = 1.0;
+
+window.addEventListener("DOMContentLoaded", async (event) => {
+ await init();
+ is_embedded = window.parent !== window;
+ main_js(is_embedded);
+ window.addEventListener("message", (ev) => {
+ if (ev.data && ev.data.op === 'play_video') {
+ play_video(ev.data.video_url);
+ return;
+ }
+
+ if (is_embedded && ev.data && ev.data.op) {
+ currentDifficulty = ev.data.difficulty || currentDifficulty;
+ set_difficulty_js(currentDifficulty);
+ receive_op_js(ev.data.op);
+ }
+ });
+});
+
+
+// os (inside computer)
+const osBox = document.getElementById('os-box');
+const video = document.getElementById('ad-video');
+
+video.addEventListener('ended', () => {
+ osBox.style.display = 'none';
+ receive_op_js('video_finished');
+});
+
+function play_video(videoUrl) {
+ if (!videoUrl) {
+ return;
+ }
+ osBox.style.display = 'block';
+ video.src = videoUrl;
+ video.muted = false;
+ video.volume = 0.85;
+ video.play().catch((e) => {
+ console.error("Failed to play video with sound:", e);
+ // fallback if autoplay policy blocked it
+ video.muted = true;
+ video.play();
+ });
+}