From fa722bbc24a0aa2f1c68a170a6c7569548094dbf Mon Sep 17 00:00:00 2001 From: Ben Frankel Date: Sun, 17 Dec 2023 18:58:19 -0800 Subject: [PATCH] Start music on web on 2nd click (Join -> Dark Mode) --- src/upgrade.rs | 7 +++---- web/index.html | 13 ++++++++++--- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/upgrade.rs b/src/upgrade.rs index 4eb5133..8885d72 100644 --- a/src/upgrade.rs +++ b/src/upgrade.rs @@ -336,7 +336,7 @@ fn load_upgrade_sequence(mut commands: Commands) { vec![TouchOfLifePlugin], "\"I don't know what I'm making, but I should start spawning entities.\"".to_string(), ), - + // Reward (vec![ImportLibrary], String::new()), @@ -353,14 +353,14 @@ fn load_upgrade_sequence(mut commands: Commands) { vec![Inspiration], "\"I should spawn a lot of entities for a higher Theme Interpretation score... Is 50 enough?\"".to_string(), ), - + // Reward ( vec![UtilPlugin], "\"I can lay some groundwork now to support all of these entities.\"".to_string(), ), (vec![Autocomplete], String::new()), - + // Explain technical debt ( vec![SpeedPlugin], @@ -375,7 +375,6 @@ fn load_upgrade_sequence(mut commands: Commands) { "\"Much better.\"".to_string(), ), - // End tutorial ( vec![Brainstorm], diff --git a/web/index.html b/web/index.html index c07afaf..68fcb9d 100644 --- a/web/index.html +++ b/web/index.html @@ -36,8 +36,18 @@ }); observer.observe(bevy, { attributes: true }); + // Play background music + let clicks = 0; function playMusic() { + // Trigger and remove the event listener on the second click + clicks++; + if (clicks < 2) { + return; + } else { + document.removeEventListener('click', playMusic); + } + // Create an AudioContext const audioContext = new (window.AudioContext || window.webkitAudioContext)(); @@ -75,9 +85,6 @@ }; request.send(); - - // Remove the click event listener after the first click - document.removeEventListener('click', playMusic); } // Add an event listener for the DOMContentLoaded event (if the browser supports the Web Audio API)