-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaudio.js
51 lines (41 loc) · 1.56 KB
/
audio.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
const audioAssets = {
// https://freesound.org/people/Duisterwho/sounds/645495/
'click': 'assets/click.wav',
// https://freesound.org/people/MattRuthSound/sounds/561571/
'down': 'assets/down.wav',
// https://freesound.org/people/el_boss/sounds/560701/
'rotate': 'assets/rotate.mp3',
// https://freesound.org/people/Duisterwho/sounds/645398/
'shake': 'assets/shake.wav',
// https://freesound.org/people/ilip33/sounds/593222/
'snap': 'assets/snap.wav',
// https://freesound.org/people/MattRuthSound/sounds/561572/
'up': 'assets/up.wav',
};
let AUDIO_ENABLED = true;
// @param key - string - asset key
function audio(key) {
if (AUDIO_ENABLED) {
let audio = new Audio(audioAssets[key]);
audio.play();
}
}
// @param enabled - boolean - if true, audio SFX are enabled
function setAudioEnabled(enabled) {
AUDIO_ENABLED = enabled;
if (AUDIO_ENABLED) {
document.getElementById("soundOn").classList.remove("remove");
document.getElementById("soundOff").classList.add("remove");
} else {
document.getElementById("soundOn").classList.add("remove");
document.getElementById("soundOff").classList.remove("remove");
}
setSoundEnabled(AUDIO_ENABLED); // Save setting
}
function audioSetup() {
let clicks = document.querySelectorAll('button,#diskSpace,#export,#import,#backToMenu,#soundOff,#ghostImageOn,#ghostImageOff');
for (let click of clicks) {
click.addEventListener('click', function() { audio('click') });
}
setAudioEnabled(isSoundEnabled());
}