mirror of
https://github.com/unanmed/HumanBreak.git
synced 2026-12-02 23:34:32 +08:00
refactor & fix: 插件与进程分离
This commit is contained in:
1 parent
325a1e85ec
commit
a9c64565e1
41 files changed
+473
-467
No files matched your search
+1
-83
@@ -7,13 +7,6 @@ import {
|
||||
resource as res
|
||||
} from './resource';
|
||||
|
||||
interface GameLoadEvent extends EmitableEvent {
|
||||
coreLoaded: () => void;
|
||||
autotileLoaded: () => void;
|
||||
coreInit: () => void;
|
||||
materialLoaded: () => void;
|
||||
}
|
||||
|
||||
const info = resource;
|
||||
|
||||
/**
|
||||
@@ -35,6 +28,7 @@ export function readyAllResource() {
|
||||
* 开发时的加载
|
||||
*/
|
||||
/* @__PURE__ */ async function readyDevResource() {
|
||||
const loading = Mota.require('var', 'loading');
|
||||
const loadData = (await import('../../data/resource-dev.json')).default;
|
||||
|
||||
loadData.forEach(v => {
|
||||
@@ -50,79 +44,3 @@ export function readyAllResource() {
|
||||
animates.active();
|
||||
});
|
||||
}
|
||||
|
||||
class GameLoading extends EventEmitter<GameLoadEvent> {
|
||||
private autotileLoaded: number = 0;
|
||||
private autotileNum?: number;
|
||||
private autotileListened: boolean = false;
|
||||
|
||||
private materialsNum: number = main.materials.length;
|
||||
private materialsLoaded: number = 0;
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
this.on(
|
||||
'coreInit',
|
||||
() => {
|
||||
this.autotileNum = Object.keys(
|
||||
core.material.icons.autotile
|
||||
).length;
|
||||
},
|
||||
{ immediate: true }
|
||||
);
|
||||
this.on('materialLoaded', () => {
|
||||
core.loader._loadMaterials_afterLoad();
|
||||
});
|
||||
}
|
||||
|
||||
addMaterialLoaded() {
|
||||
this.once('coreInit', () => {
|
||||
this.materialsLoaded++;
|
||||
if (this.materialsLoaded === this.materialsNum) {
|
||||
this.emit('materialLoaded');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
addAutotileLoaded() {
|
||||
this.once('coreInit', () => {
|
||||
this.autotileLoaded++;
|
||||
if (this.autotileLoaded === this.autotileNum) {
|
||||
this.emit('autotileLoaded');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 当自动原件加载完毕时
|
||||
* @param autotiles 自动原件数组
|
||||
*/
|
||||
onAutotileLoaded(
|
||||
autotiles: Partial<Record<AllIdsOf<'autotile'>, HTMLImageElement>>
|
||||
) {
|
||||
if (this.autotileListened) return;
|
||||
this.autotileListened = true;
|
||||
this.on('autotileLoaded', () => {
|
||||
const keys = Object.keys(
|
||||
core.material.icons.autotile
|
||||
) as AllIdsOf<'autotile'>[];
|
||||
|
||||
keys.forEach(v => {
|
||||
core.material.images.autotile[v] = autotiles[v]!;
|
||||
});
|
||||
|
||||
setTimeout(() => {
|
||||
core.maps._makeAutotileEdges();
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export const loading = new GameLoading();
|
||||
|
||||
declare global {
|
||||
interface Main {
|
||||
loading: GameLoading;
|
||||
}
|
||||
}
|
||||
main.loading = loading;
|
||||
@@ -4,7 +4,6 @@ import { ensureArray } from '@/plugin/utils';
|
||||
import { has } from '@/plugin/utils';
|
||||
import JSZip from 'jszip';
|
||||
import { EmitableEvent, EventEmitter } from '../common/eventEmitter';
|
||||
import { loading } from './load';
|
||||
|
||||
// todo: 应当用register去注册资源类型,然后进行分块处理
|
||||
|
||||
@@ -59,6 +58,7 @@ export class Resource<
|
||||
}
|
||||
|
||||
protected onLoad(v: ResourceData[T]) {
|
||||
const loading = Mota.require('var', 'loading');
|
||||
// 资源类型处理
|
||||
if (this.type === 'fonts') {
|
||||
document.fonts.add(new FontFace(this.name, v as ArrayBuffer));
|
||||
|
||||
Reference in new issue
Block a user