mirror of
https://github.com/motajs/template.git
synced 2026-11-19 02:34:30 +08:00
refactor: 渲染端初始化移动至主插件
This commit is contained in:
1 parent
7fde97ff1e
commit
0a133058ca
12 files changed
+118
-187
No files matched your search
+15
-3
@@ -4,8 +4,17 @@ import {
|
||||
IClientCore,
|
||||
IClientCoreConfig
|
||||
} from '@user/client-modules';
|
||||
import { CLIENT_CORE_URL, TILESET_RESERVE, TILESET_UNIT } from '../constant';
|
||||
import {
|
||||
CLIENT_CORE_URL,
|
||||
RENDER_CANVAS,
|
||||
RENDER_HEIGHT,
|
||||
RENDER_WIDTH,
|
||||
TILESET_RESERVE,
|
||||
TILESET_UNIT
|
||||
} from '../constant';
|
||||
import { createCoreStateConfig } from '../data/entry';
|
||||
import { MainClientPlugin } from './initialize';
|
||||
import { clientPlugins } from './plugin';
|
||||
|
||||
/**
|
||||
* 创建渲染端配置对象
|
||||
@@ -18,6 +27,10 @@ export function createClientCoreConfig(
|
||||
clientURL: CLIENT_CORE_URL,
|
||||
tilesetReserve: TILESET_RESERVE,
|
||||
tilesetUnit: TILESET_UNIT,
|
||||
rendererCanvas: RENDER_CANVAS,
|
||||
renderWidth: RENDER_WIDTH,
|
||||
renderHeight: RENDER_HEIGHT,
|
||||
clientPlugins: [new MainClientPlugin(), ...clientPlugins],
|
||||
|
||||
...createCoreStateConfig(starter)
|
||||
};
|
||||
@@ -25,7 +38,7 @@ export function createClientCoreConfig(
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建渲染端主对象,返回经过初始化的主对象实例
|
||||
* 创建渲染端主对象,返回未经过异步初始化的主对象实例,需要手动调用 `state.load` 初始化
|
||||
* @param starter 加载启动器
|
||||
*/
|
||||
export async function createClientCore(
|
||||
@@ -33,6 +46,5 @@ export async function createClientCore(
|
||||
): Promise<IClientCore> {
|
||||
const config = createClientCoreConfig(starter);
|
||||
const state = new ClientCore(config);
|
||||
await state.load();
|
||||
return state;
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
import { logger } from '@motajs/common';
|
||||
import {
|
||||
excitationDivider,
|
||||
IClientCore,
|
||||
IClientCoreConfig,
|
||||
IClientPluginDefine
|
||||
} from '@user/client-modules';
|
||||
import { ICoreStateCoreConfig } from '@user/data-state';
|
||||
import {
|
||||
DEBUG_DIVIDER,
|
||||
DEBUG_VARIATOR,
|
||||
DIVIDER_DEBUG_DIVIDER,
|
||||
VARIATOR_DEBUG_SPEED
|
||||
} from '../constant';
|
||||
import { ExcitationVariator } from '@motajs/animate';
|
||||
|
||||
export class MainClientPlugin implements IClientPluginDefine {
|
||||
id: string = 'main-client-plugin';
|
||||
dependencies: readonly string[] = [];
|
||||
|
||||
awake(state: IClientCore): void {
|
||||
// 渲染调试配置
|
||||
if (DEBUG_VARIATOR) {
|
||||
const variator = new ExcitationVariator();
|
||||
variator.bindExcitation(state.rafExcitation);
|
||||
variator.setSpeed(VARIATOR_DEBUG_SPEED);
|
||||
excitationDivider.bindExcitation(variator);
|
||||
} else {
|
||||
excitationDivider.bindExcitation(state.rafExcitation);
|
||||
}
|
||||
|
||||
if (DEBUG_DIVIDER) {
|
||||
excitationDivider.setDivider(DIVIDER_DEBUG_DIVIDER);
|
||||
}
|
||||
}
|
||||
|
||||
async initialize(): Promise<void> {}
|
||||
|
||||
async afterLoad(state: IClientCore): Promise<void> {
|
||||
const core = state.loader.getConfig<ICoreStateCoreConfig>('core');
|
||||
const client = state.loader.getConfig<IClientCoreConfig>('client');
|
||||
if (!core) {
|
||||
logger.error(79, 'Data');
|
||||
return;
|
||||
}
|
||||
if (!client) {
|
||||
logger.error(79, 'Client');
|
||||
return;
|
||||
}
|
||||
|
||||
// 存档初始化
|
||||
state.save.init(`@game/${core.name}`);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export * from './list';
|
||||
@@ -0,0 +1,4 @@
|
||||
import { IClientPluginDefine } from '@user/client-modules';
|
||||
|
||||
/** 渲染端插件列表 */
|
||||
export const clientPlugins: IClientPluginDefine[] = [];
|
||||
Reference in new issue
Block a user