Global const for composable
This commit is contained in:
parent
12735756d7
commit
db52bcfff3
@ -30,9 +30,10 @@ import Map from '@/components/game/map/Map.vue'
|
|||||||
import { useGameComposable } from '@/composables/useGameComposable'
|
import { useGameComposable } from '@/composables/useGameComposable'
|
||||||
import { useGameStore } from '@/stores/gameStore'
|
import { useGameStore } from '@/stores/gameStore'
|
||||||
import { Game, Scene } from 'phavuer'
|
import { Game, Scene } from 'phavuer'
|
||||||
|
import { onMounted } from 'vue'
|
||||||
|
|
||||||
const gameStore = useGameStore()
|
const gameStore = useGameStore()
|
||||||
const { playSound } = useGameComposable()
|
const { playSound, stopSound } = useGameComposable()
|
||||||
|
|
||||||
const gameConfig = {
|
const gameConfig = {
|
||||||
name: config.name,
|
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('blank_tile', '/assets/map/blank_tile.png')
|
||||||
scene.load.image('waypoint', '/assets/waypoint.png')
|
scene.load.image('waypoint', '/assets/waypoint.png')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
stopSound('/assets/music/intro.mp3')
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
@ -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) => {
|
const playSound = (sound: string, loop: boolean = false, ignoreIfPlaying: boolean = false) => {
|
||||||
// If sound is already playing and we want to ignore
|
// If sound is already playing and we want to ignore
|
||||||
if (ignoreIfPlaying && activeSounds[sound] && !activeSounds[sound].paused) {
|
if (ignoreIfPlaying && activeSounds[sound] && !activeSounds[sound].paused) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user