mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-11 19:44: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 Core from "evite/src/core"
|
||||||
import { Howl } from "howler"
|
import { Howl } from "howler"
|
||||||
import config from "config"
|
import config from "config"
|
||||||
|
import axios from "axios"
|
||||||
|
import store from "store"
|
||||||
|
|
||||||
export default class SoundCore extends Core {
|
export default class SoundCore extends Core {
|
||||||
static refName = "sound"
|
static refName = "sound"
|
||||||
|
|
||||||
static namespace = "sound"
|
static namespace = "sound"
|
||||||
|
|
||||||
|
soundsPool = {}
|
||||||
|
|
||||||
public = {
|
public = {
|
||||||
play: this.play,
|
play: this.play,
|
||||||
getSounds: this.getSounds,
|
getSounds: this.getSounds,
|
||||||
}
|
}
|
||||||
|
|
||||||
async getSounds() {
|
async initialize() {
|
||||||
// TODO: Load custom soundpacks manifests
|
let soundpack = config.defaultSoundPack ?? {}
|
||||||
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) {
|
async play(name, options) {
|
||||||
let soundPack = await this.getSounds()
|
if (this.soundsPool[name]) {
|
||||||
|
|
||||||
if (soundPack[name]) {
|
|
||||||
return new Howl({
|
return new Howl({
|
||||||
volume: window.app.cores.settings.get("generalAudioVolume") ?? 0.5,
|
volume: window.app.cores.settings.get("generalAudioVolume") ?? 0.5,
|
||||||
...options,
|
...options,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user