const gameSound = {
    move: new Audio('/audio/move.wav'),
    fish: new Audio('/audio/fish.wav'),
}

export default class AudioPlayer {

    constructor(settings) {
        this.settings = settings
    }

    async gameAsync(name) {
        if (!navigator.userActivation.isActive) return
        return new Promise(ended=>{
            let sound = this.game(name)
            sound.onended = ended
        })
    }
    
    game(name) {
        if (!navigator.userActivation.isActive) return
        gameSound[name].play()
        gameSound[name].muted = this.settings.muted
        gameSound[name].volume = (this.settings.game * this.settings.master) / 10000
        return gameSound[name]
    }
}