mirror of
https://github.com/unanmed/HumanBreak.git
synced 2025-01-18 20:09:27 +08:00
fix: audio提前加载占用流量
This commit is contained in:
parent
8024a39e39
commit
27af3ff5d1
@ -100,7 +100,7 @@ export class ImageResource extends Resource<HTMLImageElement> {
|
|||||||
super(uri, 'image');
|
super(uri, 'image');
|
||||||
}
|
}
|
||||||
|
|
||||||
load(onProgress?: ProgressFn): Promise<HTMLImageElement> {
|
load(_onProgress?: ProgressFn): Promise<HTMLImageElement> {
|
||||||
const img = new Image();
|
const img = new Image();
|
||||||
img.src = this.resolveURI();
|
img.src = this.resolveURI();
|
||||||
this.resource = img;
|
this.resource = img;
|
||||||
@ -229,9 +229,10 @@ export class AudioResource extends Resource<HTMLAudioElement> {
|
|||||||
super(uri, 'audio');
|
super(uri, 'audio');
|
||||||
}
|
}
|
||||||
|
|
||||||
load(onProgress?: ProgressFn): Promise<HTMLAudioElement> {
|
load(_onProgress?: ProgressFn): Promise<HTMLAudioElement> {
|
||||||
const audio = new Audio();
|
const audio = new Audio();
|
||||||
audio.src = this.resolveURI();
|
audio.src = this.resolveURI();
|
||||||
|
audio.preload = 'none';
|
||||||
this.resource = audio;
|
this.resource = audio;
|
||||||
return new Promise<HTMLAudioElement>(res => {
|
return new Promise<HTMLAudioElement>(res => {
|
||||||
this.loaded = true;
|
this.loaded = true;
|
||||||
@ -383,13 +384,12 @@ export class LoadTask<
|
|||||||
}
|
}
|
||||||
this.loaded = now;
|
this.loaded = now;
|
||||||
})
|
})
|
||||||
.catch(reason => {
|
.catch(() => {
|
||||||
LoadTask.errorTask++;
|
LoadTask.errorTask++;
|
||||||
logger.error(2, this.resource.type, this.resource.uri);
|
logger.error(2, this.resource.type, this.resource.uri);
|
||||||
});
|
});
|
||||||
this.emit('loadStart', this.resource);
|
this.emit('loadStart', this.resource);
|
||||||
const value = await load;
|
const value = await load;
|
||||||
// @ts-ignore
|
|
||||||
LoadTask.loadedTaskList.add(this);
|
LoadTask.loadedTaskList.add(this);
|
||||||
this.loaded = totalByte;
|
this.loaded = totalByte;
|
||||||
LoadTask.loadedTask++;
|
LoadTask.loadedTask++;
|
||||||
@ -407,7 +407,6 @@ export class LoadTask<
|
|||||||
uri: string
|
uri: string
|
||||||
): LoadTask<T> {
|
): LoadTask<T> {
|
||||||
const task = new LoadTask(type, uri);
|
const task = new LoadTask(type, uri);
|
||||||
// @ts-ignore
|
|
||||||
this.taskList.add(task);
|
this.taskList.add(task);
|
||||||
return task;
|
return task;
|
||||||
}
|
}
|
||||||
@ -541,7 +540,7 @@ export function loadDefaultResource() {
|
|||||||
.forEach(v => {
|
.forEach(v => {
|
||||||
const res = LoadTask.add('material', `material/${v}`);
|
const res = LoadTask.add('material', `material/${v}`);
|
||||||
res.once('load', res => {
|
res.once('load', res => {
|
||||||
// @ts-ignore
|
// @ts-expect-error 不能推导
|
||||||
core.material.images[
|
core.material.images[
|
||||||
v.slice(0, -4) as SelectKey<
|
v.slice(0, -4) as SelectKey<
|
||||||
MaterialImages,
|
MaterialImages,
|
||||||
@ -554,7 +553,7 @@ export function loadDefaultResource() {
|
|||||||
weathers.forEach(v => {
|
weathers.forEach(v => {
|
||||||
const res = LoadTask.add('material', `material/${v}.png`);
|
const res = LoadTask.add('material', `material/${v}.png`);
|
||||||
res.once('load', res => {
|
res.once('load', res => {
|
||||||
// @ts-ignore
|
// @ts-expect-error 需要赋值
|
||||||
core.animateFrame.weather[v] = res.resource;
|
core.animateFrame.weather[v] = res.resource;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -674,7 +673,6 @@ export async function loadCompressedResource() {
|
|||||||
|
|
||||||
// material
|
// material
|
||||||
if (materialImages.some(v => name === v + '.png')) {
|
if (materialImages.some(v => name === v + '.png')) {
|
||||||
// @ts-ignore
|
|
||||||
core.material.images[
|
core.material.images[
|
||||||
name.slice(0, -4) as SelectKey<
|
name.slice(0, -4) as SelectKey<
|
||||||
MaterialImages,
|
MaterialImages,
|
||||||
@ -682,7 +680,7 @@ export async function loadCompressedResource() {
|
|||||||
>
|
>
|
||||||
] = image;
|
] = image;
|
||||||
} else if (weathers.some(v => name === v + '.png')) {
|
} else if (weathers.some(v => name === v + '.png')) {
|
||||||
// @ts-ignore
|
// @ts-expect-error 需要赋值
|
||||||
core.animateFrame.weather[v] = image;
|
core.animateFrame.weather[v] = image;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user