Skip to content

Commit 36f7241

Browse files
Merge pull request #68 from RadKod/67
feat: add app sound fx option
2 parents aa44bd5 + 20237a3 commit 36f7241

File tree

9 files changed

+70
-6
lines changed

9 files changed

+70
-6
lines changed

components/Dialog/MenuDialog/MenuDialog.component.vue

+11
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ Dialog.dialog.menu-dialog(
1515
Cell.menu-dialog-nav__item(icon="eye-o" size="large" :title="$t('dialog.menu.darkTheme')")
1616
template(#right-icon)
1717
SwitchInput(v-model="isDark" size="22px" @change="toggleDarkTheme")
18+
Cell.menu-dialog-nav__item(icon="music-o" size="large" :title="$t('dialog.menu.soundFx')")
19+
template(#right-icon)
20+
SwitchInput(v-model="isActiveSoundFx" size="22px" @change="toggleSoundFx")
1821
Cell.menu-dialog-nav__item(
1922
v-if="$route.path === localePath({ name: 'Main' })"
2023
icon="font-o"
@@ -153,6 +156,12 @@ export default defineComponent({
153156
}
154157
}
155158
159+
const isActiveSoundFx = computed(() => store.getters['app/isActiveSoundFx'])
160+
161+
const toggleSoundFx = isChecked => {
162+
store.commit('app/SET_IS_ACTIVE_SOUND_FX', isChecked)
163+
}
164+
156165
const openSuggestQuestion = () => {
157166
window.open(
158167
'https://docs.google.com/forms/d/e/1FAIpQLSec4_MAFiDOjpd9pywfocFsfJQoXfMpLT3HIaHpO0Lz3clnaA/viewform?usp=sf_link',
@@ -217,6 +226,8 @@ export default defineComponent({
217226
state,
218227
isDark,
219228
toggleDarkTheme,
229+
isActiveSoundFx,
230+
toggleSoundFx,
220231
openSuggestQuestion,
221232
openRoomSharer,
222233
openAppSharer

hooks/useGameScene.js

+35-6
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,29 @@ export default () => {
315315
}
316316
})
317317

318+
const isActiveSoundFx = computed(() => store.getters['app/isActiveSoundFx'])
319+
320+
watch(
321+
() => isActiveSoundFx.value,
322+
value => {
323+
if (value) {
324+
startSoundFx.mute(false)
325+
correctSoundFx.mute(false)
326+
wrongSoundFx.mute(false)
327+
passSoundFx.mute(false)
328+
halfTimeSoundFx.mute(false)
329+
radkodEasterEggSoundFx.mute(false)
330+
} else {
331+
startSoundFx.mute(true)
332+
correctSoundFx.mute(true)
333+
wrongSoundFx.mute(true)
334+
passSoundFx.mute(true)
335+
halfTimeSoundFx.mute(true)
336+
radkodEasterEggSoundFx.mute(true)
337+
}
338+
}
339+
)
340+
318341
const soundFx = reactive({
319342
start: null,
320343
correct: null,
@@ -325,27 +348,33 @@ export default () => {
325348
})
326349

327350
const startSoundFx = new Howl({
328-
src: [`${WEB_CDN}/assets/sound/fx/start.wav`]
351+
src: [`${WEB_CDN}/assets/sound/fx/start.wav`],
352+
mute: isActiveSoundFx.value ? false : true
329353
})
330354

331355
const correctSoundFx = new Howl({
332-
src: [`${WEB_CDN}/assets/sound/fx/correct.wav`]
356+
src: [`${WEB_CDN}/assets/sound/fx/correct.wav`],
357+
mute: isActiveSoundFx.value ? false : true
333358
})
334359

335360
const wrongSoundFx = new Howl({
336-
src: [`${WEB_CDN}/assets/sound/fx/wrong.wav`]
361+
src: [`${WEB_CDN}/assets/sound/fx/wrong.wav`],
362+
mute: isActiveSoundFx.value ? false : true
337363
})
338364

339365
const passSoundFx = new Howl({
340-
src: [`${WEB_CDN}/assets/sound/fx/pass.wav`]
366+
src: [`${WEB_CDN}/assets/sound/fx/pass.wav`],
367+
mute: isActiveSoundFx.value ? false : true
341368
})
342369

343370
const halfTimeSoundFx = new Howl({
344-
src: [`${WEB_CDN}/assets/sound/fx/half-time.wav`]
371+
src: [`${WEB_CDN}/assets/sound/fx/half-time.wav`],
372+
mute: isActiveSoundFx.value ? false : true
345373
})
346374

347375
const radkodEasterEggSoundFx = new Howl({
348-
src: [`${WEB_CDN}/assets/sound/fx/radkod-easter-egg.mp3`]
376+
src: [`${WEB_CDN}/assets/sound/fx/radkod-easter-egg.mp3`],
377+
mute: isActiveSoundFx.value ? false : true
349378
})
350379

351380
soundFx.start = startSoundFx

locales/en.js

+1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ export default {
8888
usernameEdit: 'Change the player name',
8989
menu: 'Menu',
9090
darkTheme: 'Dark theme',
91+
soundFx: 'Sound fx',
9192
switchLocale: 'Choose language',
9293
suggestQa: 'Do you want to suggest a question?',
9394
howToPLay: 'How to play?',

locales/tr.js

+1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ export default {
8888
usernameEdit: 'Oyuncu adını değiştir',
8989
menu: 'Menü',
9090
darkTheme: 'Koyu tema',
91+
soundFx: 'Ses efekleri',
9192
switchLocale: 'Dil değiştir',
9293
suggestQa: 'Soru önermek ister misin?',
9394
howToPLay: 'Nasıl oynanır?',

plugins/vuex-persist.js

+3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ export default ({ store }) => {
1010
username: state.auth.user.username
1111
}
1212
},
13+
app: {
14+
soundFx: state.app.soundFx
15+
},
1316
daily: {
1417
isGameOver: state.daily.isGameOver,
1518
currentDate: state.daily.currentDate,

store/app/actions.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default {}

store/app/getters.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export default {
2+
root(state) {
3+
return state
4+
},
5+
isActiveSoundFx(state) {
6+
return state.soundFx.isActive
7+
}
8+
}

store/app/mutations.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export default {
2+
SET_IS_ACTIVE_SOUND_FX(state, isActive) {
3+
state.soundFx.isActive = isActive
4+
}
5+
}

store/app/state.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export default () => ({
2+
soundFx: {
3+
isActive: true
4+
}
5+
})

0 commit comments

Comments
 (0)