mirror of
https://github.com/unanmed/HumanBreak.git
synced 2026-11-29 05:24:30 +08:00
修改插件加载机制
This commit is contained in:
1 parent
0604c56e98
commit
d2746c4dc5
43 files changed
+527
-490
No files matched your search
+40
-14
@@ -1,20 +1,43 @@
|
||||
import { BgmController } from './audio/bgm';
|
||||
import { SoundController } from './audio/sound';
|
||||
import { readyAllResource } from './loader/load';
|
||||
import { loading, readyAllResource } from './loader/load';
|
||||
import { ResourceStore, ResourceType } from './loader/resource';
|
||||
import { resolvePlugin } from './plugin';
|
||||
|
||||
declare global {
|
||||
interface AncTe {
|
||||
sound: SoundController;
|
||||
/** 游戏资源 */
|
||||
resource: ResourceStore<Exclude<ResourceType, 'zip'>>;
|
||||
zipResource: ResourceStore<'zip'>;
|
||||
bgm: BgmController;
|
||||
}
|
||||
interface Window {
|
||||
ancTe: AncTe;
|
||||
}
|
||||
const ancTe: AncTe;
|
||||
interface AncTePlugin {
|
||||
pop: ReturnType<typeof import('../plugin/pop').default>;
|
||||
ui: ReturnType<typeof import('../plugin/uiController').default>;
|
||||
use: ReturnType<typeof import('../plugin/use').default>;
|
||||
animate: ReturnType<typeof import('../plugin/animateController').default>;
|
||||
utils: ReturnType<typeof import('../plugin/utils').default>;
|
||||
status: ReturnType<typeof import('../plugin/ui/statusBar').default>;
|
||||
mark: ReturnType<typeof import('../plugin/mark').default>;
|
||||
setting: ReturnType<typeof import('../plugin/settings').default>;
|
||||
chapter: ReturnType<typeof import('../plugin/ui/chapter').default>;
|
||||
fly: ReturnType<typeof import('../plugin/ui/fly').default>;
|
||||
chase: ReturnType<typeof import('../plugin/chase/chase').default>;
|
||||
fixed: ReturnType<typeof import('../plugin/ui/fixed').default>;
|
||||
webglUtils: ReturnType<typeof import('../plugin/webgl/utils').default>;
|
||||
shadow: ReturnType<typeof import('../plugin/shadow/shadow').default>;
|
||||
gameShadow: ReturnType<
|
||||
typeof import('../plugin/shadow/gameShadow').default
|
||||
>;
|
||||
achievement: ReturnType<typeof import('../plugin/ui/achievement').default>;
|
||||
completion: ReturnType<typeof import('../plugin/completion').default>;
|
||||
path: ReturnType<typeof import('../plugin/fx/path').default>;
|
||||
gameCanvas: ReturnType<typeof import('../plugin/fx/gameCanvas').default>;
|
||||
noise: ReturnType<typeof import('../plugin/fx/noise').default>;
|
||||
smooth: ReturnType<typeof import('../plugin/fx/smoothView').default>;
|
||||
frag: ReturnType<typeof import('../plugin/fx/frag').default>;
|
||||
}
|
||||
|
||||
export interface AncTe {
|
||||
sound: SoundController;
|
||||
/** 游戏资源 */
|
||||
resource: ResourceStore<Exclude<ResourceType, 'zip'>>;
|
||||
zipResource: ResourceStore<'zip'>;
|
||||
bgm: BgmController;
|
||||
plugin: AncTePlugin;
|
||||
}
|
||||
|
||||
function ready() {
|
||||
@@ -22,9 +45,12 @@ function ready() {
|
||||
bgm: new BgmController(),
|
||||
resource: new ResourceStore(),
|
||||
zipResource: new ResourceStore(),
|
||||
sound: new SoundController()
|
||||
sound: new SoundController(),
|
||||
// @ts-ignore
|
||||
plugin: {}
|
||||
};
|
||||
|
||||
readyAllResource();
|
||||
loading.once('coreInit', resolvePlugin);
|
||||
}
|
||||
ready();
|
||||
@@ -1,5 +1,4 @@
|
||||
import resource from '../../data/resource.json';
|
||||
import { has } from '../../plugin/utils';
|
||||
import { EmitableEvent, EventEmitter } from '../common/eventEmitter';
|
||||
import { Resource, getTypeByResource } from './resource';
|
||||
|
||||
@@ -118,7 +117,7 @@ export const loading = new GameLoading();
|
||||
|
||||
declare global {
|
||||
interface Main {
|
||||
loading: EventEmitter<GameLoadEvent>;
|
||||
loading: GameLoading;
|
||||
}
|
||||
}
|
||||
main.loading = loading;
|
||||
@@ -0,0 +1,62 @@
|
||||
import pop from '../plugin/pop';
|
||||
import ui from '../plugin/uiController';
|
||||
import use from '../plugin/use';
|
||||
import animate from '../plugin/animateController';
|
||||
import utils from '../plugin/utils';
|
||||
import status from '../plugin/ui/statusBar';
|
||||
import mark from '../plugin/mark';
|
||||
import setting from '../plugin/settings';
|
||||
import chapter from '../plugin/ui/chapter';
|
||||
import fly from '../plugin/ui/fly';
|
||||
import chase from '../plugin/chase/chase';
|
||||
import fixed from '../plugin/ui/fixed';
|
||||
import webglUtils from '../plugin/webgl/utils';
|
||||
import shadow from '../plugin/shadow/shadow';
|
||||
import gameShadow from '../plugin/shadow/gameShadow';
|
||||
import achievement from '../plugin/ui/achievement';
|
||||
import completion, { floors } from '../plugin/completion';
|
||||
import path from '../plugin/fx/path';
|
||||
import gameCanvas from '../plugin/fx/gameCanvas';
|
||||
import noise from '../plugin/fx/noise';
|
||||
import smooth from '../plugin/fx/smoothView';
|
||||
import frag from '../plugin/fx/frag';
|
||||
import { AncTe } from '.';
|
||||
|
||||
export function resolvePlugin() {
|
||||
const toForward: [keyof AncTe['plugin'], any][] = [
|
||||
['pop', pop()],
|
||||
['ui', ui()],
|
||||
['use', use()],
|
||||
['animate', animate()],
|
||||
['utils', utils()],
|
||||
['status', status()],
|
||||
['mark', mark()],
|
||||
['setting', setting()],
|
||||
['chapter', chapter()],
|
||||
['fly', fly()],
|
||||
['chase', chase()],
|
||||
['fixed', fixed()],
|
||||
['webglUtils', webglUtils()],
|
||||
['shadow', shadow()],
|
||||
['gameShadow', gameShadow()],
|
||||
['achievement', achievement()],
|
||||
['completion', completion()],
|
||||
['path', path()],
|
||||
['gameCanvas', gameCanvas()],
|
||||
['noise', noise()],
|
||||
['smooth', smooth()],
|
||||
['frag', frag()]
|
||||
];
|
||||
|
||||
for (const [key, obj] of toForward) {
|
||||
ancTe.plugin[key] = obj;
|
||||
}
|
||||
|
||||
// 完成度相关
|
||||
Object.values(floors).forEach((v, i) => {
|
||||
const from = core.floorIds.indexOf(v[0]);
|
||||
const to = core.floorIds.indexOf(v[1]);
|
||||
const all = core.floorIds.slice(from, to + 1);
|
||||
floors[i + 1] = all;
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user