2024-04-16 10:05:11 -04:00
|
|
|
import { writable, readable, 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 {
|
|
|
|
|
public currentPos: number
|
|
|
|
|
public queue: Song[]
|
|
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
|
this.queue = []
|
|
|
|
|
this.currentPos = 0
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public enqueue = (...songs: Song[]): void => {
|
|
|
|
|
this.queue.push(...songs)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public getStart = (): Song | undefined => {
|
|
|
|
|
return this.queue[0]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public getCurrent = (): Song => {
|
|
|
|
|
return this.queue[this.currentPos]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public next = (): Song | undefined => {
|
|
|
|
|
if (this.queue.length > this.currentPos + 1) {
|
|
|
|
|
this.currentPos += 1
|
|
|
|
|
return this.queue[this.currentPos]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return undefined
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public previous = (): Song | undefined => {
|
|
|
|
|
if (this.currentPos > 0) {
|
|
|
|
|
this.currentPos -= 1
|
|
|
|
|
return this.queue[this.currentPos]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return undefined
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const queue: Readable<Queue> = readable(new Queue())
|