mirror of
https://github.com/unanmed/HumanBreak.git
synced 2025-05-08 00:33:25 +08:00
音乐从某个时刻开始播放
This commit is contained in:
parent
77efd767ee
commit
d4c03cdaec
@ -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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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) {
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user