Global const for composable

This commit is contained in:
Dennis Postma 2025-02-06 21:46:51 +01:00
parent 12735756d7
commit db52bcfff3
2 changed files with 8 additions and 3 deletions

View File

@ -30,9 +30,10 @@ import Map from '@/components/game/map/Map.vue'
import { useGameComposable } from '@/composables/useGameComposable'
import { useGameStore } from '@/stores/gameStore'
import { Game, Scene } from 'phavuer'
import { onMounted } from 'vue'
const gameStore = useGameStore()
const { playSound } = useGameComposable()
const { playSound, stopSound } = useGameComposable()
const gameConfig = {
name: config.name,
@ -68,4 +69,8 @@ function preloadScene(scene: Phaser.Scene) {
scene.load.image('blank_tile', '/assets/map/blank_tile.png')
scene.load.image('waypoint', '/assets/waypoint.png')
}
onMounted(() => {
stopSound('/assets/music/intro.mp3')
})
</script>

View File

@ -1,6 +1,6 @@
export function useGameComposable() {
const activeSounds: { [key: string]: HTMLAudioElement } = {}
const activeSounds: { [key: string]: HTMLAudioElement } = {}
export function useGameComposable() {
const playSound = (sound: string, loop: boolean = false, ignoreIfPlaying: boolean = false) => {
// If sound is already playing and we want to ignore
if (ignoreIfPlaying && activeSounds[sound] && !activeSounds[sound].paused) {