2024-04-17 14:23:54 -04:00
|
|
|
import { writable, readable, readonly, type Writable, type Readable } from 'svelte/store'
|
2024-01-25 03:05:13 -05:00
|
|
|
import type { AlertType } from '$lib/components/util/alert.svelte'
|
2024-01-21 23:51:15 -05:00
|
|
|
|
2024-01-27 01:38:04 -05:00
|
|
|
export const pageWidth: Writable<number> = writable()
|
2024-01-21 23:51:15 -05:00
|
|
|
|
2024-01-27 01:38:04 -05:00
|
|
|
export const newestAlert: Writable<[AlertType, string]> = writable()
|
2024-01-21 23:51:15 -05:00
|
|
|
|
|
|
|
|
const youtubeMusicBackground: string = 'https://www.gstatic.com/youtube/media/ytm/images/sbg/wsbg@4000x2250.png' // Default Youtube music background
|
|
|
|
|
export const backgroundImage: Writable<string> = writable(youtubeMusicBackground)
|
2024-04-16 10:05:11 -04:00
|
|
|
|
|
|
|
|
class Queue {
|
2024-04-17 14:23:54 -04:00
|
|
|
private currentPos: number | null
|
|
|
|
|
private songs: Song[]
|
2024-04-16 10:05:11 -04:00
|
|
|
|
|
|
|
|
constructor() {
|
2024-04-17 14:23:54 -04:00
|
|
|
this.currentPos = null
|
|
|
|
|
this.songs = []
|
2024-04-16 10:05:11 -04:00
|
|
|
}
|
|
|
|
|
|
2024-04-17 14:23:54 -04:00
|
|
|
public enqueue = (...songs: Song[]) => {
|
|
|
|
|
this.songs.push(...songs)
|
|
|
|
|
writeableQueue.set(this)
|
2024-04-16 10:05:11 -04:00
|
|
|
}
|
|
|
|
|
|
2024-04-17 14:23:54 -04:00
|
|
|
public next = () => {
|
|
|
|
|
if (this.songs.length === 0) return
|
2024-04-16 10:05:11 -04:00
|
|
|
|
2024-04-17 14:23:54 -04:00
|
|
|
if (!this.currentPos) {
|
|
|
|
|
this.currentPos = 0
|
|
|
|
|
} else {
|
|
|
|
|
if (!(this.songs.length > this.currentPos + 1)) return
|
2024-04-16 10:05:11 -04:00
|
|
|
this.currentPos += 1
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-17 14:23:54 -04:00
|
|
|
writeableQueue.set(this)
|
2024-04-16 10:05:11 -04:00
|
|
|
}
|
|
|
|
|
|
2024-04-17 14:23:54 -04:00
|
|
|
public current = () => {
|
|
|
|
|
if (this.songs.length > 0) {
|
|
|
|
|
if (!this.currentPos) this.currentPos = 0
|
|
|
|
|
return this.songs[this.currentPos]
|
2024-04-16 10:05:11 -04:00
|
|
|
}
|
2024-04-17 14:23:54 -04:00
|
|
|
return null
|
|
|
|
|
}
|
2024-04-16 10:05:11 -04:00
|
|
|
|
2024-04-17 14:23:54 -04:00
|
|
|
public getSongs = () => {
|
|
|
|
|
return this.songs
|
2024-04-16 10:05:11 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-17 14:23:54 -04:00
|
|
|
const writeableQueue: Writable<Queue> = writable(new Queue())
|
|
|
|
|
export const queue: Readable<Queue> = readonly(writeableQueue)
|