Skip to content

Commit

Permalink
Start music on web on 2nd click (Join -> Dark Mode)
Browse files Browse the repository at this point in the history
  • Loading branch information
benfrankel committed Dec 18, 2023
1 parent 9810f06 commit fa722bb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
7 changes: 3 additions & 4 deletions src/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()),

Expand All @@ -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],
Expand All @@ -375,7 +375,6 @@ fn load_upgrade_sequence(mut commands: Commands) {
"\"Much better.\"".to_string(),
),


// End tutorial
(
vec![Brainstorm],
Expand Down
13 changes: 10 additions & 3 deletions web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -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)();

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit fa722bb

Please sign in to comment.