mirror of
https://github.com/danbulant/heaventaker
synced 2026-06-21 07:42:43 +00:00
44 lines
No EOL
908 B
JavaScript
44 lines
No EOL
908 B
JavaScript
import { Howl } from "howler";
|
|
|
|
export const musicStore = {
|
|
departure: {
|
|
src: "mittsies-departure.mp3",
|
|
bpm: 128,
|
|
scale: 1/2,
|
|
/** @type {Howl} */
|
|
howl: null
|
|
}
|
|
}
|
|
|
|
export class Music {
|
|
static current = musicStore.departure;
|
|
|
|
/**
|
|
* @param {keyof musicStore} key
|
|
*/
|
|
static play(key) {
|
|
this.current.howl.pause();
|
|
this.current = musicStore[key];
|
|
if(!this.current.howl) this.prepare();
|
|
this.current.howl.play();
|
|
}
|
|
|
|
static prepare() {
|
|
this.current.howl = new Howl({
|
|
src: "./sound/" + this.current.src,
|
|
html5: true,
|
|
loop: true
|
|
});
|
|
}
|
|
|
|
static startPlaying() {
|
|
if(!this.current.howl.playing())
|
|
this.current.howl.play();
|
|
}
|
|
}
|
|
Music.prepare();
|
|
Music.startPlaying();
|
|
|
|
export function startPlaying(e) {
|
|
Music.startPlaying();
|
|
} |