音乐从某个时刻开始播放

This commit is contained in:
unanmed 2023-06-18 22:42:09 +08:00
parent 77efd767ee
commit d4c03cdaec
3 changed files with 22 additions and 15 deletions

View File

@ -11,7 +11,7 @@ class BgmController extends ResourceController<HTMLAudioElement> {
*/
add(uri: string, data: HTMLAudioElement) {
if (this.list[uri]) {
console.warn(`Repeated bgm: '${uri}'`);
console.warn(`Repeated bgm: '${uri}'.`);
}
this.list[uri] = data;
data.loop = true;
@ -21,8 +21,12 @@ class BgmController extends ResourceController<HTMLAudioElement> {
* bgm
* @param id bgm的id
*/
play(id: BgmIds) {
play(id: BgmIds, when: number = 0) {
if (this.playing === id) return;
this.stop();
const bgm = this.get(id);
bgm.currentTime = when;
bgm.play();
}
/**

View File

@ -1,6 +1,11 @@
export abstract class ResourceController<D, T = D> {
list: Record<string, T> = {};
/**
*
* @param uri uri
* @param data
*/
abstract add(uri: string, data: D): void;
remove(uri: string) {

View File

@ -271,19 +271,6 @@ class ResourceStore<T extends ResourceType> extends Map<string, Resource<T>> {
}
}
declare global {
interface AncTe {
/** 游戏资源 */
resource: ResourceStore<Exclude<ResourceType, 'zip'>>;
zipResource: ResourceStore<'zip'>;
}
}
ancTe.resource = new ResourceStore();
ancTe.zipResource = new ResourceStore();
console.log(JSZip.external.Promise);
export function getTypeByResource(resource: string): ResourceType {
const type = resource.split('.')[0];
@ -301,3 +288,14 @@ export function getZipFormatByType(type: ResourceType): 'arraybuffer' | 'text' {
if (type === 'text' || type === 'json') return 'text';
else return 'arraybuffer';
}
declare global {
interface AncTe {
/** 游戏资源 */
resource: ResourceStore<Exclude<ResourceType, 'zip'>>;
zipResource: ResourceStore<'zip'>;
}
}
ancTe.resource = new ResourceStore();
ancTe.zipResource = new ResourceStore();