Skip to content

Commit

Permalink
Only loop a sound once
Browse files Browse the repository at this point in the history
- Replace looping sounds array with object to allow checking if a sound is already looping or not
  • Loading branch information
selimnahimi committed Sep 29, 2023
1 parent 69a116f commit 8c1afa4
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/components/SoundscapePlayer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class SoundscapePlayer extends Vue {
timers: { [key: number]: ReturnType<typeof setTimeout> } = {};
activeLoopingSounds: Howl[] = [];
activeLoopingSounds: { [key: string]: Howl } = {};
mounted() {
console.log("playing " + this.soundscape.name);
Expand Down Expand Up @@ -55,12 +55,12 @@ class SoundscapePlayer extends Vue {
}
private stopLoops() {
this.activeLoopingSounds.forEach(sound => {
sound.stop();
sound.unload();
});
for (const sound in this.activeLoopingSounds) {
this.activeLoopingSounds[sound].stop();
this.activeLoopingSounds[sound].unload();
}
this.activeLoopingSounds = [];
this.activeLoopingSounds = {};
}
private playActionOnRepeat(action: SoundscapeAction, actionIndex: number) {
Expand Down Expand Up @@ -141,10 +141,17 @@ class SoundscapePlayer extends Vue {
if (!soundFile)
return;
if (this.soundAlreadyLooping(soundPath))
return;
let randomVolume = this.getRandomVolume(action);
SoundPlayer.playSoundFileLoop(soundFile, randomVolume)
.then(audio => this.activeLoopingSounds.push(audio));
.then(audio => this.activeLoopingSounds[soundPath] = audio);
}
private soundAlreadyLooping(soundPath: string): boolean {
return soundPath in this.activeLoopingSounds;
}
private playActionRandom(action: SoundscapeAction) {
Expand Down Expand Up @@ -190,7 +197,7 @@ class SoundscapePlayer extends Vue {
private removeSpecialCharacters(path: string): string {
// Some sounds have special characters: https://developer.valvesoftware.com/wiki/Soundscripts#Sound_Characters
return path.replace(new RegExp('[\@\>\<\^\)\}\$\!\?\&\~\`\+\(\%\*]'), '');
return path.replace(new RegExp('[@><^)}$!?&~`+(%*]'), '');
}
private appendSoundFolder(path: string) {
Expand Down

0 comments on commit 8c1afa4

Please sign in to comment.