mirror of
https://github.com/unanmed/HumanBreak.git
synced 2026-12-01 06:44:30 +08:00
资源加载,bgm和音效播放
This commit is contained in:
1 parent
6f59ea51ac
commit
5aed6393a2
16 files changed
+289
-52
No files matched your search
+12
-2
@@ -7,7 +7,7 @@ const info = resource;
|
||||
* 构建游戏包后的加载
|
||||
*/
|
||||
export function readyAllResource() {
|
||||
if (main.RESOURCE_TYPE === 'dev') return readyDevResource();
|
||||
/* @__PURE__ */ if (main.RESOURCE_TYPE === 'dev') return readyDevResource();
|
||||
info.resource.forEach(v => {
|
||||
const type = getTypeByResource(v);
|
||||
if (type === 'zip') {
|
||||
@@ -21,4 +21,14 @@ export function readyAllResource() {
|
||||
/**
|
||||
* 开发时的加载
|
||||
*/
|
||||
function readyDevResource() {}
|
||||
/* @__PURE__ */ async function readyDevResource() {
|
||||
const loadData = (await import('../../data/resource-dev.json')).default;
|
||||
|
||||
loadData.forEach(v => {
|
||||
const type = getTypeByResource(v);
|
||||
if (type !== 'zip') {
|
||||
ancTe.resource.set(v, new Resource(v, type));
|
||||
}
|
||||
});
|
||||
ancTe.resource.forEach(v => v.active());
|
||||
}
|
||||
@@ -37,12 +37,13 @@ export class Resource<
|
||||
constructor(resource: string, format: T) {
|
||||
super(resource);
|
||||
this.data = this.resolveUrl(resource);
|
||||
|
||||
this.format = format;
|
||||
this.uri = resource;
|
||||
|
||||
this.once('active', this.load);
|
||||
this.once('load', this.onLoad);
|
||||
this.once('loadstart', this.onLoadStart);
|
||||
this.once('active', () => this.load());
|
||||
this.once('load', v => this.onLoad(v));
|
||||
this.once('loadstart', v => this.onLoadStart(v));
|
||||
}
|
||||
|
||||
protected onLoadStart(v?: ResourceData[T]) {
|
||||
@@ -242,7 +243,10 @@ export class ZippedResource extends EventEmitter<ZippedEvent> {
|
||||
}
|
||||
}
|
||||
|
||||
class ResourceStore<T extends ResourceType> extends Map<string, Resource<T>> {
|
||||
export class ResourceStore<T extends ResourceType> extends Map<
|
||||
string,
|
||||
Resource<T>
|
||||
> {
|
||||
active(key: string[] | string) {
|
||||
const keys = ensureArray(key);
|
||||
keys.forEach(v => this.get(v)?.active());
|
||||
@@ -301,14 +305,3 @@ 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();
|
||||
Reference in new issue
Block a user