diff options
| author | LLLL Colonq <llll@colonq> | 2026-08-04 04:35:44 -0400 |
|---|---|---|
| committer | LLLL Colonq <llll@colonq> | 2026-08-04 04:35:44 -0400 |
| commit | 3c7796f066647090ed8436778bdfe25f11844c05 (patch) | |
| tree | 0644a101004d91af4fcdc2f51fcc2e03f7f255ce /2026/games/rpc2dot0/index.js | |
| parent | a75221ab93f59d688f90cd83f0284ff98951fcfa (diff) | |
Prepare for upload
Diffstat (limited to '2026/games/rpc2dot0/index.js')
| -rw-r--r-- | 2026/games/rpc2dot0/index.js | 48 |
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(); + }); +} |
