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 9e93d44
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ You can listen to [the soundtrack here](https://youtu.be/0JXQqLwuy6E).
## Licenses

### Code
- The CSS loader / spinner is MIT ([https://github.com/vineethtrv/css-loader]).
- The CSS background pattern is MIT ([https://github.com/Afif13/CSS-Pattern]).
- The CSS loader / spinner is MIT: https://github.com/vineethtrv/css-loader
- The CSS background pattern is MIT: https://github.com/Afif13/CSS-Pattern
- The remainder of the code is written by [Pyrious](https://github.com/benfrankel) and [necrashter](https://github.com/necrashter/), and is dual-licensed under MIT and Apache 2.0.

### Audio
Expand Down
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 9e93d44

Please sign in to comment.