intialize soundpacks

This commit is contained in:
SrGooglo 2023-03-31 23:16:25 +00:00
parent 4ba326ebc8
commit 0c52e1abfa

View File

@ -1,28 +1,53 @@
import Core from "evite/src/core"
import { Howl } from "howler"
import config from "config"
import axios from "axios"
import store from "store"
export default class SoundCore extends Core {
static refName = "sound"
static namespace = "sound"
soundsPool = {}
public = {
play: this.play,
getSounds: this.getSounds,
}
async getSounds() {
// TODO: Load custom soundpacks manifests
let soundPack = config.defaultSoundPack ?? {}
async initialize() {
let soundpack = config.defaultSoundPack ?? {}
return soundPack
const storedCustomSoundpack = store.get("soundpack_manifest")
if (storedCustomSoundpack) {
// check if is valid url with regex
const urlRegex = /^(ftp|http|https):\/\/[^ "]+$/;
if (urlRegex.test(storedCustomSoundpack)) {
// load with axios
const { data } = await axios.get(storedCustomSoundpack)
soundpack = data
} else {
console.error(`Soundpack [${storedCustomSoundpack}] is not a valid url.`)
return false
}
}
for (const [name, path] of Object.entries(soundpack)) {
this.soundsPool[name] = new Howl({
volume: window.app.cores.settings.get("generalAudioVolume") ?? 0.5,
src: [path],
})
}
console.log(this.soundsPool)
}
async play(name, options) {
let soundPack = await this.getSounds()
if (soundPack[name]) {
if (this.soundsPool[name]) {
return new Howl({
volume: window.app.cores.settings.get("generalAudioVolume") ?? 0.5,
...options,