diff options
| author | LLLL Colonq <llll@colonq> | 2026-08-26 23:47:59 -0400 |
|---|---|---|
| committer | LLLL Colonq <llll@colonq> | 2026-08-26 23:47:59 -0400 |
| commit | 0d2d8cd897e94bd94e0b3ae7c6ce9aa580a44a0a (patch) | |
| tree | e9039d1c3aedca515d6cb499451d4b73aca4f5fd /2026/games_submissions/rpc2dot0/index.js | |
| parent | 242943e5b023ce40eb3be826c418a478d4672f78 (diff) | |
Add a_tension_span
Diffstat (limited to '2026/games_submissions/rpc2dot0/index.js')
| -rw-r--r-- | 2026/games_submissions/rpc2dot0/index.js | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/2026/games_submissions/rpc2dot0/index.js b/2026/games_submissions/rpc2dot0/index.js new file mode 100644 index 0000000..2a8d674 --- /dev/null +++ b/2026/games_submissions/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(); + }); +} |
