Skip to content

Commit

Permalink
Merge pull request #115 from trifle-labs/106-song-seed
Browse files Browse the repository at this point in the history
use prando to deterministically choose song from seed
  • Loading branch information
okwme authored Apr 13, 2024
2 parents 60e1504 + 3d24ff5 commit 423b882
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/sound.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const {
start,
loaded
} = Tone
import Prando from 'prando'

const whistle_8_T7 = new URL(
'/public/sound/whistle/whistle_8_T7.mp3',
Expand Down Expand Up @@ -205,6 +206,10 @@ export default class Sound {
if (typeof window === 'undefined') return
this.anybody = anybody
window.addEventListener('keydown', this.handleKeyDown)
const rng = new Prando(anybody.seed?.toString(16))
const songs = Object.values(SONGS)
const rand = rng.nextInt(0, songs.length - 1)
this.currentSong = songs[rand]
}

handleKeyDown = (e) => {
Expand All @@ -228,11 +233,7 @@ export default class Sound {
// this function must be called in response to a user action
// otherwise safari and chrome will block the audio
resume() {
const randomSong =
Object.values(SONGS)[
Math.floor(Math.random() * Object.values(SONGS).length)
]
this.play(randomSong)
this.play(this.currentSong)
this.playOneShot(bongoHard, -20)
}

Expand Down Expand Up @@ -396,7 +397,6 @@ export default class Sound {
})
this.voices = null
this.currentMeasure = 0
this.currentSong = null
this.playedGameOver = false
}

Expand Down

0 comments on commit 423b882

Please sign in to comment.