mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-10 02:54:15 +00:00
intialize soundpacks
This commit is contained in:
parent
4ba326ebc8
commit
0c52e1abfa
@ -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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user