Skip to content

Commit

Permalink
Feature/background music and sounds (#33)
Browse files Browse the repository at this point in the history
Background music, click sound for buttons, error notification sound,
sound for chat notifications and success notification are added

---------

Co-authored-by: eisenmls <[email protected]>
  • Loading branch information
katyaganina and eisenmls authored Jul 9, 2024
1 parent 74a6065 commit 1da9e1d
Show file tree
Hide file tree
Showing 13 changed files with 106 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module.exports = {
'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
},

extends: ['plugin:vue/vue3-essential', 'eslint:recommended', '@vue/typescript/recommended', 'plugin:prettier/recommended'],
extends: ['plugin:vue/vue3-essential', 'eslint:recommended', '@vue/typescript/recommended'],

overrides: [
{
Expand Down
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,21 @@ To remove the container you can use the following command:
```sh
docker rm bugfinder
```

## Audio sources

1. Background music
https://pixabay.com/de/music/optimistisch-walking-while-looking-at-the-moon-187621/

2. Click
https://pixabay.com/de/sound-effects/interface-button-154180/

3. Error notification
https://pixabay.com/de/sound-effects/error-126627/

4. Classic notifications from the chat
https://pixabay.com/de/sound-effects/notifications-sound-127856/

5. Success notification
https://pixabay.com/de/sound-effects/short-success-sound-glockenspiel-treasure-video-game-6346/

30 changes: 28 additions & 2 deletions src/App.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
<script setup lang="ts">
import { ref } from 'vue';
import { ref, onMounted, onUnmounted } from 'vue';
import HomeView from '@/views/HomeView.vue';
import GameView from '@/views/GameView.vue';
import FinishView from '@/views/FinishView.vue';
import backgroundMusicSource from '/src/assets/music/background_music.mp3';
import clickSoundSource from '/src/assets/music/click_sound.mp3';
const backgroundMusic = new Audio(backgroundMusicSource);
const clickSound = new Audio(clickSoundSource);
onMounted(() => {
backgroundMusic.loop = true;
backgroundMusic.play();
});
onUnmounted(() => {
backgroundMusic.pause();
backgroundMusic.currentTime = 0;
});
enum views {
home,
Expand All @@ -17,6 +32,17 @@ function changeView(newView: views) {
function closeGame() {
window.parent.postMessage('CLOSE ME');
}
function playClickSound(){
clickSound.play();
}
async function handleCloseGame() {
await playClickSound();
setTimeout(() => {
closeGame();
}, 500);
}
</script>

<template>
Expand All @@ -26,7 +52,7 @@ function closeGame() {
<span class="navbar-brand mb-0 h1">Bugfinder</span>
</div>
<div class="mr-1">
<b-button variant="danger" class="nav-buttons close-button" id="close-button" v-on:click="closeGame">
<b-button variant="danger" class="nav-buttons close-button" id="close-button" v-on:click="handleCloseGame">
<em class="bi-x"></em>
</b-button>
</div>
Expand Down
Binary file added src/assets/music/background_music.mp3
Binary file not shown.
Binary file added src/assets/music/click_sound.mp3
Binary file not shown.
Binary file added src/assets/music/error_sound.mp3
Binary file not shown.
Binary file added src/assets/music/notification_sound.mp3
Binary file not shown.
Binary file added src/assets/music/success_sound.mp3
Binary file not shown.
24 changes: 21 additions & 3 deletions src/components/ChatBox.vue
Original file line number Diff line number Diff line change
@@ -1,15 +1,33 @@
<script setup lang="ts">
import { ChatParticipant } from '@/models/chat';
import { ChatColor, ChatParticipant } from '@/models/chat';
import { watch } from 'vue';
import { chatHistory } from '@/services/chat';
import notificationSoundSource from '/src/assets/music/notification_sound.mp3';
import successSoundSource from '/src/assets/music/success_sound.mp3';
import errorSoundSource from '/src/assets/music/error_sound.mp3';
const notificationSound = new Audio(notificationSoundSource);
const successSound = new Audio(successSoundSource);
const errorSound = new Audio(errorSoundSource);
watch(
() => chatHistory,
() => {
() => chatHistory.value,
(newChatHistory) => {
const chatBox = document.getElementById('chat-box');
if (chatBox) {
chatBox.lastElementChild?.scrollIntoView();
}
const lastMessage = newChatHistory[newChatHistory.length - 1];
if (lastMessage && lastMessage.from === ChatParticipant.OTHER) {
if (lastMessage.color === ChatColor.LIGHT || lastMessage.color === ChatColor.PRIMARY) {
notificationSound.play();
} else if (lastMessage.color === ChatColor.WARNING) {
errorSound.play();
} else if (lastMessage.color === ChatColor.SUCCESS) {
successSound.play();
}
}
},
{ deep: true }
);
Expand Down
9 changes: 9 additions & 0 deletions src/components/CodeBox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import { CodeVisualizer } from '@/services/code-visualizer';
import WordBox from '@/components/WordBox.vue';
import SelectBugModal from '@/components/SelectBugModal.vue';
import { ref, watch } from 'vue';
import clickSoundSource from '/src/assets/music/click_sound.mp3';
const clickSound = new Audio(clickSoundSource);
const props = defineProps<{
code: ICode;
codeFeedback: CodeFeedback;
Expand All @@ -27,7 +29,9 @@ const emptyBug = new Bug(-1, ErrorType.UNDEFINED, '');
const currentEditingBug = ref(emptyBug);
const showModal = ref(false);
function submit() {
playClickSound();
if (!submitted.value) {
submitted.value = true;
emit('submitSolution', new Solution(undefined, selectedBugs.value));
Expand All @@ -38,6 +42,7 @@ function selectBug(word: IWord) {
if (submitted.value) {
return;
}
playClickSound();
if (selectedBugs.value.find((bug) => bug.wordId == word.id) == null) {
let wordString = word.wordContent;
if (wordString == space) {
Expand Down Expand Up @@ -79,6 +84,10 @@ function getWordById(wordId: number | string): IWord | undefined {
return props.code.words.find((word) => word.id == wordId);
}
function playClickSound(){
clickSound.play();
}
watch(
() => props.code,
(newCode) => {
Expand Down
16 changes: 15 additions & 1 deletion src/views/FinishView.vue
Original file line number Diff line number Diff line change
@@ -1,14 +1,28 @@
<script setup lang="ts">
import clickSoundSource from '/src/assets/music/click_sound.mp3';
const clickSound = new Audio(clickSoundSource);
function closeGame() {
window.parent.postMessage('CLOSE ME');
}
async function handleCloseGame() {
await playClickSound();
setTimeout(() => {
closeGame();
}, 500);
}
function playClickSound(){
clickSound.play();
}
</script>

<template>
<main>
<div class="text-center position-absolute top-50 start-50 translate-middle">
<h2>You finished the Game!</h2>
<b-button variant="danger" id="close-button" v-on:click="closeGame"> Back to game </b-button>
<b-button variant="danger" id="close-button" v-on:click="handleCloseGame"> Back to game </b-button>
</div>
</main>
</template>
8 changes: 8 additions & 0 deletions src/views/GameView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import { ICode, ISolution } from '@/models/code';
import * as chat from '@/services/chat';
import { CodeFeedback } from '@/services/code-feedback';
import { Ref, ref } from 'vue';
import clickSoundSource from '/src/assets/music/click_sound.mp3';
const clickSound = new Audio(clickSoundSource);
const emit = defineEmits<{
(e: 'endGame'): void;
Expand All @@ -28,6 +31,7 @@ const showNextButton = ref(false);
chat.sendStartMessgae();
async function nextCode() {
playClickSound();
if (await game.hasNextCode()) {
await chat.sendNextCode();
await game.nextCode();
Expand All @@ -49,6 +53,10 @@ async function submitSolution(selectedBugs: ISolution) {
showNextButton.value = true;
}, 2000);
}
function playClickSound(){
clickSound.play();
}
</script>

<template>
Expand Down
7 changes: 6 additions & 1 deletion src/views/HomeView.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<script setup lang="ts">
import { BASE_URL } from '@/app';
import { ref } from 'vue';
import clickSoundSource from '/src/assets/music/click_sound.mp3';
const clickSound = new Audio(clickSoundSource);
const emit = defineEmits<{
(e: 'startGame'): void;
}>();
Expand All @@ -22,6 +24,9 @@ fetch(`${BASE_URL}/configurations/${configurationId}`)
.catch(() => {
configuration.value = 'Server not reachable';
});
function playClickSound(){
clickSound.play();
}
</script>

<template>
Expand All @@ -34,7 +39,7 @@ fetch(`${BASE_URL}/configurations/${configurationId}`)
<div class="alert alert-danger">{{ configuration }}</div>
</div>
<div v-if="typeof configuration === 'object'">
<button class="btn btn-primary" @click="emit('startGame')">Start</button>
<button class="btn btn-primary" @click="playClickSound(); emit('startGame')">Start</button>
</div>
</div>
<div v-if="configurationId?.length === 0">
Expand Down

0 comments on commit 1da9e1d

Please sign in to comment.