mirror of
https://github.com/motajs/template.git
synced 2026-11-05 17:04:31 +08:00
refactor: Delete global loading & hook object
This commit is contained in:
1 parent
7c155be5ce
commit
d8fa4b8507
16 files changed
+33
-978
No files matched your search
@@ -11,9 +11,7 @@ import {
|
||||
import { IRenderTreeRoot, MotaRenderer } from '@motajs/render';
|
||||
import {
|
||||
ITextureManager,
|
||||
IAutotileProcessor,
|
||||
TextureManager,
|
||||
AutotileProcessor,
|
||||
ISaveSystem,
|
||||
SaveSystem
|
||||
} from '@user/client-base';
|
||||
@@ -38,8 +36,6 @@ import {
|
||||
MAIN_WIDTH,
|
||||
VARIATOR_DEBUG_SPEED
|
||||
} from './shared';
|
||||
import { loading } from '@user/data-base';
|
||||
import { fallbackLoad } from './fallback/load';
|
||||
import { WebLoadStarter } from '@motajs/loader';
|
||||
|
||||
export class ClientCore extends CoreState implements IClientCore {
|
||||
@@ -90,10 +86,10 @@ export class ClientCore extends CoreState implements IClientCore {
|
||||
//#endregion
|
||||
|
||||
// 兼容层
|
||||
loading.once('loaded', () => {
|
||||
fallbackLoad(this.materials);
|
||||
loading.emit('assetBuilt');
|
||||
});
|
||||
// loading.once('loaded', () => {
|
||||
// fallbackLoad(this.materials);
|
||||
// loading.emit('assetBuilt');
|
||||
// });
|
||||
|
||||
//#region 渲染系统
|
||||
|
||||
@@ -126,9 +122,9 @@ export class ClientCore extends CoreState implements IClientCore {
|
||||
this.mainMapExtension = new MapExtensionManager(this.mainMapRenderer);
|
||||
|
||||
// 兼容层
|
||||
loading.once('assetBuilt', () => {
|
||||
this.initMapExtensions();
|
||||
});
|
||||
// loading.once('assetBuilt', () => {
|
||||
// this.initMapExtensions();
|
||||
// });
|
||||
|
||||
//#endregion
|
||||
|
||||
|
||||
@@ -1,13 +1,9 @@
|
||||
import { loading } from '@user/data-base';
|
||||
import { patchAll } from './fallback';
|
||||
import { createGameRenderer, createRender } from './render';
|
||||
import { createRender } from './render';
|
||||
|
||||
export function create() {
|
||||
patchAll();
|
||||
createRender();
|
||||
loading.once('coreInit', () => {
|
||||
createGameRenderer();
|
||||
});
|
||||
}
|
||||
|
||||
export * from './action';
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
import { Font } from '@motajs/render';
|
||||
import { defineComponent } from 'vue';
|
||||
import { DEFAULT_FONT, MAIN_HEIGHT, MAIN_WIDTH } from '../shared';
|
||||
import { hook } from '@user/data-base';
|
||||
import { createElements } from '@user/client-base';
|
||||
import { mainRenderer } from './renderer';
|
||||
import { createUI } from './ui';
|
||||
import { createAction } from './action';
|
||||
import { sceneController } from './scene';
|
||||
import { GameTitleUI } from './ui/title';
|
||||
import { createWeather } from './weather';
|
||||
import { createApp } from './renderer';
|
||||
import { LoadSceneUI } from './ui/load';
|
||||
@@ -34,10 +32,10 @@ export function createRender() {
|
||||
createAction();
|
||||
createWeather();
|
||||
|
||||
hook.on('restart', () => {
|
||||
sceneController.closeAll();
|
||||
sceneController.open(GameTitleUI, {});
|
||||
});
|
||||
// hook.on('restart', () => {
|
||||
// sceneController.closeAll();
|
||||
// sceneController.open(GameTitleUI, {});
|
||||
// });
|
||||
|
||||
Font.setDefaults(DEFAULT_FONT);
|
||||
}
|
||||
|
||||
@@ -23,7 +23,6 @@ import { transitioned } from '../use';
|
||||
import { cosh, CurveMode, linear } from '@motajs/animate';
|
||||
import { clamp } from 'lodash-es';
|
||||
import { sleep } from '@motajs/common';
|
||||
import { loading } from '@user/data-base';
|
||||
import { GameTitleUI } from './title';
|
||||
import { client } from '../../core';
|
||||
|
||||
@@ -62,7 +61,6 @@ export const LoadScene = defineComponent<ILoadProps>(props => {
|
||||
];
|
||||
|
||||
const loadEnd = async () => {
|
||||
loading.emit('loaded');
|
||||
alpha.set(0);
|
||||
await sleep(400);
|
||||
props.controller.closeAll();
|
||||
|
||||
@@ -26,7 +26,6 @@ import {
|
||||
} from './statusBar';
|
||||
import { ReplayingStatus } from './toolbar';
|
||||
import { state } from '@user/data-state';
|
||||
import { hook } from '@user/data-base';
|
||||
import { mainUIController } from './controller';
|
||||
import { isNil } from 'lodash-es';
|
||||
import { using } from '../renderer';
|
||||
@@ -138,14 +137,19 @@ const MainScene = defineComponent(() => {
|
||||
locked.value = core.status.lockControl;
|
||||
};
|
||||
|
||||
// 监听状态栏更新事件
|
||||
hook.on('statusBarUpdate', updateStatus);
|
||||
hook.on('statusBarUpdate', updateDataFallback);
|
||||
// 保留函数调用,避免被识别为未使用函数而报错
|
||||
// 后续修改后需要删除
|
||||
updateDataFallback();
|
||||
updateStatus();
|
||||
|
||||
onUnmounted(() => {
|
||||
hook.off('statusBarUpdate', updateStatus);
|
||||
hook.off('statusBarUpdate', updateDataFallback);
|
||||
});
|
||||
// 监听状态栏更新事件
|
||||
// hook.on('statusBarUpdate', updateStatus);
|
||||
// hook.on('statusBarUpdate', updateDataFallback);
|
||||
|
||||
// onUnmounted(() => {
|
||||
// hook.off('statusBarUpdate', updateStatus);
|
||||
// hook.off('statusBarUpdate', updateDataFallback);
|
||||
// });
|
||||
|
||||
//#region sprite 渲染
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@ import {
|
||||
import { logger } from '@motajs/common';
|
||||
import { IRenderItem, IRenderTreeRoot } from '@motajs/render';
|
||||
import { Hotkey, gameKey } from '@motajs/system';
|
||||
import { loading } from '@user/data-base';
|
||||
import {
|
||||
ComponentInternalInstance,
|
||||
getCurrentInstance,
|
||||
@@ -65,18 +64,6 @@ export function onOrientationChange(hook: OrientationHook) {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 当游戏加载完成时执行函数,如果调用此函数时游戏已经加载,那么会立刻调用传入的钩子函数
|
||||
* @param hook 当游戏加载完成时执行的函数
|
||||
*/
|
||||
export function onLoaded(hook: () => void) {
|
||||
if (!loading.loaded) {
|
||||
loading.once('loaded', hook);
|
||||
} else {
|
||||
hook();
|
||||
}
|
||||
}
|
||||
|
||||
type KeyUsing = [Hotkey, symbol];
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user