From 5119227a41a60d2ee8ed5bac3460b6e8f3b5f49a Mon Sep 17 00:00:00 2001 From: unanmed <1319491857@qq.com> Date: Wed, 24 Jan 2024 21:32:49 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E6=8E=A5=E5=8F=A3=E4=B8=8E?= =?UTF-8?q?=E8=BF=9B=E7=A8=8B=E9=80=9A=E8=AE=AF=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .prettierignore | 3 +- public/libs/control.js | 23 ++-- public/libs/events.js | 13 +- public/libs/maps.js | 7 +- public/project/functions.js | 2 +- public/project/items.js | 6 +- src/core/audio/bgm.ts | 2 + src/core/audio/sound.ts | 2 + src/core/index.ts | 99 ++++++++------ src/core/loader/load.ts | 17 ++- src/core/loader/resource.ts | 9 +- src/core/main/init/fixed.ts | 1 + src/core/main/init/index.ts | 1 - src/core/main/setting.ts | 65 +++++++--- src/core/main/storage.ts | 3 + src/core/plugin.ts | 100 +++++++-------- src/game/index.ts | 1 + src/game/system.ts | 228 +++++++++++++++++++++++++++++++++ src/main.ts | 3 +- src/plugin/game/hook.ts | 6 +- src/plugin/game/skillTree.js | 2 +- src/plugin/game/ui.js | 22 ++-- src/plugin/keyCodes.ts | 2 +- src/plugin/ui/achievement.ts | 4 +- src/types/plugin.d.ts | 4 +- src/ui/achievement.vue | 2 +- src/ui/bgmList.vue | 3 +- src/ui/book.vue | 6 +- src/ui/chapter.vue | 3 +- src/ui/completeAchievement.vue | 3 +- src/ui/desc.vue | 3 +- src/ui/equipbox.vue | 7 +- src/ui/fixedDetail.vue | 3 +- src/ui/fly.vue | 3 +- src/ui/markedEnemy.vue | 3 +- src/ui/settings.vue | 3 +- src/ui/shop.vue | 3 +- src/ui/skill.vue | 3 +- src/ui/skillTree.vue | 3 +- src/ui/start.vue | 3 +- src/ui/toolbox.vue | 11 +- 41 files changed, 506 insertions(+), 181 deletions(-) create mode 100644 src/game/index.ts create mode 100644 src/game/system.ts diff --git a/.prettierignore b/.prettierignore index ba4d211..4998941 100644 --- a/.prettierignore +++ b/.prettierignore @@ -7,4 +7,5 @@ public/project/floors/*.js public/project/maps.js public/_server/**/*.js script/**/*.js -public/editor.html \ No newline at end of file +public/editor.html +keyCodes.ts \ No newline at end of file diff --git a/public/libs/control.js b/public/libs/control.js index c4fa532..af0555b 100644 --- a/public/libs/control.js +++ b/public/libs/control.js @@ -2317,7 +2317,7 @@ control.prototype._doSL_load = function (id, callback) { 1 )[0]; if (!main.replayChecking) { - mota.ui.fixed.closeByName('start'); + Mota.require('var', 'fixedUi').closeByName('start'); } if (core.isPlaying() && !core.status.gameOver) { core.control.autosave(0); @@ -2334,7 +2334,7 @@ control.prototype._doSL_load = function (id, callback) { null, function (data) { if (!main.replayChecking && data) { - mota.ui.fixed.closeByName('start'); + Mota.require('var', 'fixedUi').closeByName('start'); } if (id == 'autoSave' && data != null) { core.saves.autosave.data = data; @@ -3012,9 +3012,6 @@ control.prototype.removeSwitch = function (x, y, floorId, name) { ////// 锁定状态栏,常常用于事件处理 ////// control.prototype.lockControl = function () { core.status.lockControl = true; - if (!main.replayChecking) { - // mota.plugin.fixed.showFixed.value = false; - } }; ////// 解锁状态栏 ////// @@ -3342,23 +3339,24 @@ control.prototype.screenFlash = function ( }); }; +// todo: deprecate playBgm, pauseBgm, resumeBgm, triggerBgm ////// 播放背景音乐 ////// control.prototype.playBgm = function (bgm, startTime) { bgm = core.getMappedName(bgm); if (main.mode !== 'play') return; - mota.bgm.play(bgm, startTime); + Mota.require('var', 'bgm').play(bgm, startTime); }; ////// 暂停背景音乐的播放 ////// control.prototype.pauseBgm = function () { if (main.mode !== 'play') return; - mota.bgm.pause(); + Mota.require('var', 'bgm').pause(); }; ////// 恢复背景音乐的播放 ////// control.prototype.resumeBgm = function (resumeTime) { if (main.mode !== 'play') return; - mota.bgm.resume(); + Mota.require('var', 'bgm').resume(); }; ////// 更改背景音乐的播放 ////// @@ -3371,6 +3369,7 @@ control.prototype.triggerBgm = function () { core.setLocalStorage('bgmStatus', core.musicStatus.bgmStatus); }; +// todo: deprecate playSound, stopSound, getPlayingSounds ////// 播放音频 ////// control.prototype.playSound = function (sound, pitch, callback) { sound = core.getMappedName(sound); @@ -3380,19 +3379,19 @@ control.prototype.playSound = function (sound, pitch, callback) { !core.material.sounds[sound] ) return; - mota.sound.play(sound, callback); + Mota.require('var', 'sound').play(sound, callback); }; ////// 停止所有音频 ////// control.prototype.stopSound = function (id) { - if (typeof id === 'number') mota.sound.stop(id); - else mota.sound.stopAll(); + if (typeof id === 'number') Mota.require('var', 'sound').stop(id); + else Mota.require('var', 'sound').stopAll(); }; ////// 获得当前正在播放的所有(指定)音效的id列表 ////// control.prototype.getPlayingSounds = function (name) { name = core.getMappedName(name); - return mota.sound.getPlaying(name); + return Mota.require('var', 'sound').getPlaying(name); }; ////// 检查bgm状态 ////// diff --git a/public/libs/events.js b/public/libs/events.js index 1ca09e0..f2e4355 100644 --- a/public/libs/events.js +++ b/public/libs/events.js @@ -26,7 +26,7 @@ events.prototype.startGame = function (hard, seed, route, callback) { hard = hard || ''; core.dom.gameGroup.style.display = 'block'; if (!main.replayChecking) { - mota.ui.fixed.closeByName('start'); + Mota.require('var', 'fixedUi').closeByName('start'); } if (main.mode != 'play') return; @@ -471,7 +471,12 @@ events.prototype.openDoor = function (x, y, needKey, callback) { core.removeBlock(x, y); setTimeout(function () { core.status.replay.animate = false; - mota.game.hook.emit('afterOpenDoor', block.event.id, x, y); + Mota.require('var', 'hook').emit( + 'afterOpenDoor', + block.event.id, + x, + y + ); if (callback) callback(); }, 1); // +1是为了录像检测系统 } else { @@ -556,7 +561,7 @@ events.prototype._openDoor_animate = function (block, x, y, callback) { core.maps._removeBlockFromMap(core.status.floorId, block); if (!locked) core.unlockControl(); core.status.replay.animate = false; - mota.game.hook.emit('afterOpenDoor', block.event.id, x, y); + Mota.require('var', 'hook').emit('afterOpenDoor', block.event.id, x, y); if (callback) callback(); }; @@ -636,7 +641,7 @@ events.prototype.getItem = function (id, num, x, y, isGentleClick, callback) { itemHint.push(id); } - mota.game.hook.emit('afterGetItem', id, x, y, isGentleClick); + Mota.require('var', 'hook').emit('afterGetItem', id, x, y, isGentleClick); if (callback) callback(); }; diff --git a/public/libs/maps.js b/public/libs/maps.js index 5011f21..3839ea0 100644 --- a/public/libs/maps.js +++ b/public/libs/maps.js @@ -2551,8 +2551,11 @@ maps.prototype._drawThumbnail_realDrawTempCanvas = function ( blocks, options ) { - options.ctx.imageSmoothingEnabled = core.getLocalStorage( - 'antiAliasing', + // todo: storage获取方式优化 + const storage = mota.storage; + const s = storage.get(storage.fromAuthor('AncTe', 'setting')); + options.ctx.imageSmoothingEnabled = !s.getValue( + 'screen.antiAliasing', true ); // 缩略图:背景 diff --git a/public/project/functions.js b/public/project/functions.js index 42d43b4..8907daa 100644 --- a/public/project/functions.js +++ b/public/project/functions.js @@ -51,7 +51,7 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a = { else core.showStatusBar(); if (main.mode === 'play' && !main.replayChecking) { mota.plugin.fly.splitArea(); - mota.game.hook.emit('reset'); + Mota.require('var', 'hook').emit('reset'); } else { flags.autoSkill ??= true; } diff --git a/public/project/items.js b/public/project/items.js index ffde2a8..263c252 100644 --- a/public/project/items.js +++ b/public/project/items.js @@ -1168,14 +1168,14 @@ var items_296f5d02_12fd_4166_a7c1_b5e830c9ee3a = "name": "系统设置", "canUseItemEffect": "true", "text": "内含所有系统设置项", - "useItemEffect": "if (!core.isReplaying()) mota.ui.main.open('settings');" + "useItemEffect": "if (!core.isReplaying()) Mota.require('var', 'mainUi').open('settings');" }, "I560": { "cls": "constants", "name": "百科全书", "canUseItemEffect": "true", "text": "一个包含游戏中所有功能详细说明的百科全书,可以查看游戏中所有的功能", - "useItemEffect": "if (!core.isReplaying()) mota.ui.main.open('desc');" + "useItemEffect": "if (!core.isReplaying()) Mota.require('var', 'mainUi').open('desc');" }, "I565": { "cls": "constants", @@ -1233,7 +1233,7 @@ var items_296f5d02_12fd_4166_a7c1_b5e830c9ee3a = "cls": "constants", "name": "成就", "canUseItemEffect": "true", - "useItemEffect": "mota.ui.main.open('achievement');", + "useItemEffect": "Mota.require('var', 'mainUi')open('achievement');", "text": "可以查看成就" } } \ No newline at end of file diff --git a/src/core/audio/bgm.ts b/src/core/audio/bgm.ts index b409c83..900d198 100644 --- a/src/core/audio/bgm.ts +++ b/src/core/audio/bgm.ts @@ -70,3 +70,5 @@ export class BgmController extends ResourceController { return this.list[`bgms.${id}`]; } } + +export const bgm = new BgmController(); diff --git a/src/core/audio/sound.ts b/src/core/audio/sound.ts index 236d8e5..0d54ea3 100644 --- a/src/core/audio/sound.ts +++ b/src/core/audio/sound.ts @@ -215,3 +215,5 @@ export class SoundController extends ResourceController< } } } + +export const sound = new SoundController(); diff --git a/src/core/index.ts b/src/core/index.ts index adeecb2..458c7ed 100644 --- a/src/core/index.ts +++ b/src/core/index.ts @@ -1,15 +1,24 @@ -import { BgmController } from './audio/bgm'; -import { SoundController } from './audio/sound'; +import { BgmController, bgm } from './audio/bgm'; +import { SoundController, sound } from './audio/sound'; import { EventEmitter } from './common/eventEmitter'; import { loading, readyAllResource } from './loader/load'; -import { ResourceStore, ResourceType } from './loader/resource'; +import { + ResourceStore, + ResourceType, + resource, + zipResource +} from './loader/resource'; import { UiController } from './main/custom/ui'; -import { GameEvent, hook } from './main/game'; -import { fixedUi, mainUi } from './main/init/ui'; +import { GameEvent, gameListener, hook } from './main/game'; import { GameStorage } from './main/storage'; -import { resolvePlugin } from './plugin'; +// import { resolvePlugin } from './plugin'; import './main/init/'; import './main/custom/toolbar'; +import { fixedUi, mainUi } from './main/init/ui'; +import { gameKey } from './main/init/hotkey'; +import { mainSetting, settingStorage } from './main/setting'; +import { isMobile } from '../plugin/use'; +import { KeyCode } from '@/plugin/keyCodes'; interface AncTePlugin { pop: ReturnType; @@ -33,42 +42,54 @@ interface AncTePlugin { frag: ReturnType; } -export interface Mota { - sound: SoundController; - /** 游戏资源 */ - resource: ResourceStore>; - zipResource: ResourceStore<'zip'>; - bgm: BgmController; - plugin: AncTePlugin; - game: { - hook: EventEmitter; - storage: typeof GameStorage; - }; - ui: { - main: UiController; - fixed: UiController; - }; -} +// export interface Mota { +// sound: SoundController; +// /** 游戏资源 */ +// resource: ResourceStore>; +// zipResource: ResourceStore<'zip'>; +// bgm: BgmController; +// plugin: AncTePlugin; +// hook: EventEmitter; +// classes: { +// storage: typeof GameStorage; +// }; +// ui: { +// main: UiController; +// fixed: UiController; +// }; +// } function ready() { - window.mota = { - bgm: new BgmController(), - resource: new ResourceStore(), - zipResource: new ResourceStore(), - sound: new SoundController(), - // @ts-ignore - plugin: {}, - game: { - hook, - storage: GameStorage - }, - ui: { - main: mainUi, - fixed: fixedUi - } - }; + // window.mota = { + // bgm: new BgmController(), + // resource: new ResourceStore(), + // zipResource: new ResourceStore(), + // sound: new SoundController(), + // // @ts-ignore + // plugin: {}, + // hook, + // storage: GameStorage, + // ui: { + // main: mainUi, + // fixed: fixedUi + // } + // }; readyAllResource(); - loading.once('coreInit', resolvePlugin); + // loading.once('coreInit', resolvePlugin); } ready(); + +Mota.register('var', 'mainUi', mainUi); +Mota.register('var', 'fixedUi', fixedUi); +Mota.register('var', 'hook', hook); +Mota.register('var', 'gameListener', gameListener); +Mota.register('var', 'bgm', bgm); +Mota.register('var', 'sound', sound); +Mota.register('var', 'gameKey', gameKey); +Mota.register('var', 'loading', loading); +Mota.register('var', 'mainSetting', mainSetting); +Mota.register('var', 'KeyCode', KeyCode); +Mota.register('var', 'resource', resource); +Mota.register('var', 'zipResource', zipResource); +Mota.register('var', 'settingStorage', settingStorage); diff --git a/src/core/loader/load.ts b/src/core/loader/load.ts index 9b09d6e..2898d96 100644 --- a/src/core/loader/load.ts +++ b/src/core/loader/load.ts @@ -1,6 +1,11 @@ import resource from '@/data/resource.json'; import { EmitableEvent, EventEmitter } from '../common/eventEmitter'; -import { Resource, getTypeByResource } from './resource'; +import { + Resource, + getTypeByResource, + zipResource, + resource as res +} from './resource'; interface GameLoadEvent extends EmitableEvent { coreLoaded: () => void; @@ -19,9 +24,9 @@ export function readyAllResource() { info.resource.forEach(v => { const type = getTypeByResource(v); if (type === 'zip') { - mota.zipResource.set(v, new Resource(v, 'zip')); + zipResource.set(v, new Resource(v, 'zip')); } else { - mota.resource.set(v, new Resource(v, type)); + res.set(v, new Resource(v, type)); } }); } @@ -35,13 +40,13 @@ export function readyAllResource() { loadData.forEach(v => { const type = getTypeByResource(v); if (type !== 'zip') { - mota.resource.set(v, new Resource(v, type)); + res.set(v, new Resource(v, type)); } }); - mota.resource.forEach(v => v.active()); + res.forEach(v => v.active()); loading.once('coreInit', () => { const animates = new Resource('__all_animates__', 'text'); - mota.resource.set('__all_animates__', animates); + res.set('__all_animates__', animates); animates.active(); }); } diff --git a/src/core/loader/resource.ts b/src/core/loader/resource.ts index 3dbb5df..0fccfcf 100644 --- a/src/core/loader/resource.ts +++ b/src/core/loader/resource.ts @@ -54,7 +54,7 @@ export class Resource< protected onLoadStart(v?: ResourceData[T]) { if (this.format === 'bgm') { // bgm 单独处理,因为它可以边播放边加载 - mota.bgm.add(this.uri, v!); + Mota.require('var', 'bgm').add(this.uri, v!); } } @@ -63,7 +63,7 @@ export class Resource< if (this.type === 'fonts') { document.fonts.add(new FontFace(this.name, v as ArrayBuffer)); } else if (this.type === 'sounds') { - mota.sound.add(this.uri, v as ArrayBuffer); + Mota.require('var', 'sound').add(this.uri, v as ArrayBuffer); } else if (this.type === 'images') { const name = `${this.name}${this.ext}` as ImageIds; loading.on( @@ -111,7 +111,7 @@ export class Resource< const id = `${base}.${name}`; const type = getTypeByResource(id) as NonZipResource; const format = getZipFormatByType(type); - mota.resource.set( + resource.set( id, new Resource(id, type).setData(file.async(format)) ); @@ -377,3 +377,6 @@ export function getZipFormatByType(type: ResourceType): 'arraybuffer' | 'text' { if (type === 'text' || type === 'json') return 'text'; else return 'arraybuffer'; } + +export const resource = new ResourceStore(); +export const zipResource = new ResourceStore(); diff --git a/src/core/main/init/fixed.ts b/src/core/main/init/fixed.ts index 93865d9..2f8ba9d 100644 --- a/src/core/main/init/fixed.ts +++ b/src/core/main/init/fixed.ts @@ -34,6 +34,7 @@ const closeFixed = () => { }); }; +// todo: 应当在这里实现查看临界与特殊属性的功能 export let hovered: Block | null; gameListener.on('hoverBlock', block => { diff --git a/src/core/main/init/index.ts b/src/core/main/init/index.ts index 076c3d8..7e2a8e9 100644 --- a/src/core/main/init/index.ts +++ b/src/core/main/init/index.ts @@ -1,3 +1,2 @@ import './fixed'; -import './hotkey'; import './keyboard'; diff --git a/src/core/main/setting.ts b/src/core/main/setting.ts index ef8fdc6..b0cf611 100644 --- a/src/core/main/setting.ts +++ b/src/core/main/setting.ts @@ -3,7 +3,7 @@ import { EmitableEvent, EventEmitter } from '../common/eventEmitter'; import { loading } from '../loader/load'; import { hook } from './game'; import { GameStorage } from './storage'; -import { triggerFullscreen } from '@/plugin/utils'; +import { has, triggerFullscreen } from '@/plugin/utils'; import { createSettingComponents } from './init/settings'; export interface SettingComponentProps { @@ -46,6 +46,8 @@ export interface SettingDisplayInfo { const COM = createSettingComponents(); export class MotaSetting extends EventEmitter { + static noStorage: string[] = []; + readonly list: Record = {}; /** @@ -145,6 +147,31 @@ export class MotaSetting extends EventEmitter { this.emit('valueChange', key, old, value); } + /** + * 获取一个设置的值,如果获取到的是一个MotaSetting实例,那么返回undefined + * @param key 要获取的设置 + */ + getValue(key: string): boolean | number | undefined; + /** + * 获取一个设置的值,如果获取到的是一个MotaSetting实例,那么返回defaultValue + * @param key 要获取的设置 + * @param defaultValue 设置的默认值 + */ + getValue(key: string, defaultValue: T): T; + getValue( + key: string, + defaultValue?: T + ): T | undefined { + const setting = this.getSetting(key); + if (!has(setting) && !has(defaultValue)) return void 0; + if (setting instanceof MotaSetting) { + if (has(setting)) return defaultValue; + return void 0; + } else { + return has(setting) ? (setting.value as T) : (defaultValue as T); + } + } + /** * 设置一个设置的值显示函数 * @param key 要设置的设置的键 @@ -277,8 +304,10 @@ export class SettingDisplayer extends EventEmitter { // todo: 优化存储方式 export const mainSetting = new MotaSetting(); +// 添加不参与全局存储的设置 +MotaSetting.noStorage.push('action.autoSkill', 'screen.fullscreen'); -interface SettingStorage { +export interface SettingStorage { showHalo: boolean; frag: boolean; itemDetail: boolean; @@ -298,8 +327,14 @@ const storage = new GameStorage( GameStorage.fromAuthor('AncTe', 'setting') ); +export { storage as settingStorage }; + // ----- 监听设置修改 mainSetting.on('valueChange', (key, n, o) => { + if (!MotaSetting.noStorage.includes(key)) { + storage.setValue(key, n); + } + const [root, setting] = key.split('.'); if (root === 'screen') { @@ -323,25 +358,23 @@ function handleScreenSetting( triggerFullscreen(n as boolean); } else if (key === 'halo') { // 光环 - core.setLocalStorage('showHalo', n); + // core.setLocalStorage('showHalo', n); } else if (key === 'frag') { // 打怪特效 - core.setLocalStorage('frag', n); + // core.setLocalStorage('frag', n); } else if (key === 'itemDetail') { // 宝石血瓶显伤 - core.setLocalStorage('itemDetail', n); + // core.setLocalStorage('itemDetail', n); } else if (key === 'heroDetail') { // 勇士显伤 - core.setLocalStorage('heroDetail', n); + // core.setLocalStorage('heroDetail', n); core.drawHero(); - // storage.setValue('heroDetail', n as boolean); } else if (key === 'transition') { // 界面动画 - core.setLocalStorage('transition', n); - // transition.value = n as boolean; + // core.setLocalStorage('transition', n); } else if (key === 'antiAlias') { // 抗锯齿 - core.setLocalStorage('antiAlias', n); + // core.setLocalStorage('antiAlias', n); for (const canvas of core.dom.gameCanvas) { if (core.domStyle.hdCanvas.includes(canvas.id)) continue; if (n) { @@ -352,12 +385,12 @@ function handleScreenSetting( } } else if (key === 'fontSize') { // 字体大小 - core.setLocalStorage('fontSize', n); + // core.setLocalStorage('fontSize', n); root.style.fontSize = `${n}px`; } else if (key === 'smoothView') { - core.setLocalStorage('smoothView', n); + // core.setLocalStorage('smoothView', n); } else if (key === 'criticalGem') { - core.setLocalStorage('criticalGem', n); + // core.setLocalStorage('criticalGem', n); } } @@ -371,7 +404,7 @@ function handleActionSetting( flags.autoSkill = n; } else if (key === 'fixed') { // 定点查看 - core.setLocalStorage('fixed', n); + // core.setLocalStorage('fixed', n); } } @@ -382,10 +415,10 @@ function handleUtilsSetting( ) { if (key === 'betterLoad') { // 加载优化 - core.setLocalStorage('betterLoad', n); + // core.setLocalStorage('betterLoad', n); } else if (key === 'autoScale') { // 自动放缩 - core.setLocalStorage('autoScale', n); + // core.setLocalStorage('autoScale', n); } } diff --git a/src/core/main/storage.ts b/src/core/main/storage.ts index 1ad3046..05fea91 100644 --- a/src/core/main/storage.ts +++ b/src/core/main/storage.ts @@ -84,3 +84,6 @@ export class GameStorage { window.addEventListener('unload', () => { GameStorage.list.forEach(v => v.write()); }); +window.addEventListener('blur', () => { + GameStorage.list.forEach(v => v.write()); +}); diff --git a/src/core/plugin.ts b/src/core/plugin.ts index ca335b6..3757fae 100644 --- a/src/core/plugin.ts +++ b/src/core/plugin.ts @@ -1,54 +1,54 @@ -import pop from '@/plugin/pop'; -import use from '@/plugin/use'; -import animate from '@/plugin/animateController'; -import utils from '@/plugin/utils'; -import status from '@/plugin/ui/statusBar'; -import fly from '@/plugin/ui/fly'; -import chase from '@/plugin/chase/chase'; -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 { Mota } from '.'; +// import pop from '@/plugin/pop'; +// import use from '@/plugin/use'; +// import animate from '@/plugin/animateController'; +// import utils from '@/plugin/utils'; +// import status from '@/plugin/ui/statusBar'; +// import fly from '@/plugin/ui/fly'; +// import chase from '@/plugin/chase/chase'; +// 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 { Mota } from '.'; -// todo: 将插件更改为注册形式,分为渲染进程和游戏进程两部分,同时分配优先级 +// // todo: 将插件更改为注册形式,分为渲染进程和游戏进程两部分,同时分配优先级 -export function resolvePlugin() { - const toForward: [keyof Mota['plugin'], any][] = [ - ['pop', pop()], - ['use', use()], - ['animate', animate()], - ['utils', utils()], - ['status', status()], - ['fly', fly()], - ['chase', chase()], - ['webglUtils', webglUtils()], - ['shadow', shadow()], - ['gameShadow', gameShadow()], - ['achievement', achievement()], - ['completion', completion()], - ['path', path()], - ['gameCanvas', gameCanvas()], - ['noise', noise()], - ['smooth', smooth()], - ['frag', frag()] - ]; +// export function resolvePlugin() { +// const toForward: [keyof Mota['plugin'], any][] = [ +// ['pop', pop()], +// ['use', use()], +// ['animate', animate()], +// ['utils', utils()], +// ['status', status()], +// ['fly', fly()], +// ['chase', chase()], +// ['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) { - mota.plugin[key] = obj; - } +// for (const [key, obj] of toForward) { +// mota.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; - }); -} +// // 完成度相关 +// 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; +// }); +// } diff --git a/src/game/index.ts b/src/game/index.ts new file mode 100644 index 0000000..da933d9 --- /dev/null +++ b/src/game/index.ts @@ -0,0 +1 @@ +import './system'; diff --git a/src/game/system.ts b/src/game/system.ts new file mode 100644 index 0000000..1703fb0 --- /dev/null +++ b/src/game/system.ts @@ -0,0 +1,228 @@ +import type { AudioPlayer } from '@/core/audio/audio'; +import type { BgmController } from '@/core/audio/bgm'; +import type { SoundController, SoundEffect } from '@/core/audio/sound'; +import type { Disposable } from '@/core/common/disposable'; +import type { + EventEmitter, + IndexedEventEmitter +} from '@/core/common/eventEmitter'; +import type { loading } from '@/core/loader/load'; +import type { + Resource, + ResourceStore, + ResourceType, + ZippedResource +} from '@/core/loader/resource'; +import type { Hotkey } from '@/core/main/custom/hotkey'; +import type { Keyboard } from '@/core/main/custom/keyboard'; +import type { CustomToolbar } from '@/core/main/custom/toolbar'; +import type { Focus, GameUi, UiController } from '@/core/main/custom/ui'; +import type { gameListener, hook } from '@/core/main/game'; +import type { + MotaSetting, + SettingDisplayer, + SettingStorage +} from '@/core/main/setting'; +import type { GameStorage } from '@/core/main/storage'; +import type { DamageEnemy, EnemyCollection } from '@/plugin/game/enemy/damage'; +import type { enemySpecials } from '@/plugin/game/enemy/special'; +import type { Range } from '@/plugin/game/range'; +import type { KeyCode } from '@/plugin/keyCodes'; + +interface ClassInterface { + // 渲染进程与游戏进程通用 + EventEmitter: typeof EventEmitter; + IndexedEventEmitter: typeof IndexedEventEmitter; + Disposable: typeof Disposable; + // 定义于渲染进程,录像中会进行polyfill,但是不执行任何内容 + GameStorage: typeof GameStorage; + MotaSetting: typeof MotaSetting; + SettingDisplayer: typeof SettingDisplayer; + Resource: typeof Resource; + ZippedResource: typeof ZippedResource; + ResourceStore: typeof ResourceStore; + Focus: typeof Focus; + GameUi: typeof GameUi; + UiController: typeof UiController; + Hotkey: typeof Hotkey; + Keyboard: typeof Keyboard; + CustomToolbar: typeof CustomToolbar; + AudioPlayer: typeof AudioPlayer; + SoundEffect: typeof SoundEffect; + SoundController: typeof SoundController; + BgmController: typeof BgmController; + // todo: 放到插件 ShaderEffect: typeof ShaderEffect; + // 定义于游戏进程,渲染进程依然可用 + Range: typeof Range; + EnemyCollection: typeof EnemyCollection; + DamageEnemy: typeof DamageEnemy; +} + +interface FunctionInterface { + // 定义于渲染进程,录像中会进行polyfill,但是不执行任何内容 + readyAllResource(): void; + // 定义于游戏进程,渲染进程依然可用 + + // todo +} + +interface VariableInterface { + // 定义于渲染进程,录像中会进行polyfill + loading: typeof loading; + hook: typeof hook; + gameListener: typeof gameListener; + mainSetting: MotaSetting; + gameKey: Hotkey; + mainUi: UiController; + fixedUi: UiController; + KeyCode: typeof KeyCode; + // isMobile: boolean; + bgm: BgmController; + sound: SoundController; + resource: ResourceStore>; + zipResource: ResourceStore<'zip'>; + settingStorage: GameStorage; + // 定义于游戏进程,渲染进程依然可用 + haloSpecials: number[]; + enemySpecials: typeof enemySpecials; +} + +interface SystemInterfaceMap { + class: ClassInterface; + fn: FunctionInterface; + var: VariableInterface; +} + +type InterfaceType = keyof SystemInterfaceMap; + +export interface IMota { + /** + * 获取一个样板接口 + * @param type 要获取的接口类型 + * @param key 接口名称 + */ + require( + type: T, + key: K + ): SystemInterfaceMap[T][K]; + /** + * 获取一个样板接口 + * @param type 要获取的接口类型 + * @param key 接口名称 + */ + require(type: InterfaceType, key: string): any; + + /** + * 获取一种接口的所有内容 + * @param type 要获取的接口类型 + */ + requireAll(type: T): SystemInterfaceMap[T]; + + /** + * 注册一个样板接口 + * @param type 要注册的接口类型 + * @param key 接口名称 + * @param data 接口内容 + */ + register( + type: T, + key: K, + data: SystemInterfaceMap[T][K] + ): void; + /** + * 注册一个样板接口 + * @param type 要注册的接口类型 + * @param key 接口名称 + * @param data 接口内容 + */ + register(type: InterfaceType, key: string, data: any): void; +} + +/** + * 样板接口系统,通过 Mota 获取到样板的核心功能,不可实例化 + */ +class Mota { + private static classes: Record = {}; + private static functions: Record = {}; + private static variables: Record = {}; + + constructor() { + throw new Error(`System interface class cannot be constructed.`); + } + + /** + * 获取一个样板接口 + * @param type 要获取的接口类型 + * @param key 接口名称 + */ + static require< + T extends InterfaceType, + K extends keyof SystemInterfaceMap[T] + >(type: T, key: K): SystemInterfaceMap[T][K]; + /** + * 获取一个样板接口 + * @param type 要获取的接口类型 + * @param key 接口名称 + */ + static require(type: InterfaceType, key: string): any; + static require(type: InterfaceType, key: string): any { + const data = this.getByType(type)[key]; + if (!!data) return data; + else { + throw new Error( + `Cannot resolve require: type='${type}',key='${key}'` + ); + } + } + + /** + * 获取一种接口的所有内容 + * @param type 要获取的接口类型 + */ + static requireAll(type: T): SystemInterfaceMap[T] { + return this.getByType(type) as SystemInterfaceMap[T]; + } + + /** + * 注册一个样板接口 + * @param type 要注册的接口类型 + * @param key 接口名称 + * @param data 接口内容 + */ + static register< + T extends InterfaceType, + K extends keyof SystemInterfaceMap[T] + >(type: T, key: K, data: SystemInterfaceMap[T][K]): void; + /** + * 注册一个样板接口 + * @param type 要注册的接口类型 + * @param key 接口名称 + * @param data 接口内容 + */ + static register(type: InterfaceType, key: string, data: any): void; + static register(type: InterfaceType, key: string, data: any) { + const obj = this.getByType(type); + if (key in obj) { + console.warn( + `重复的样板接口注册: type='${type}', key='${key}',已将其覆盖` + ); + } + obj[key] = data; + } + + private static getByType(type: InterfaceType) { + return type === 'class' + ? this.classes + : type === 'fn' + ? this.functions + : this.variables; + } +} + +declare global { + interface Window { + Mota: IMota; + } +} + +window.Mota = Mota; diff --git a/src/main.ts b/src/main.ts index f008abf..f7bd542 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,12 +1,11 @@ import { createApp } from 'vue'; import App from './App.vue'; -import App2 from './App2.vue'; import './styles.less'; import 'ant-design-vue/dist/antd.dark.css'; +import './game/index'; import './core/index'; createApp(App).mount('#root'); -// createApp(App2).mount('#root2'); main.init('play'); main.listen(); diff --git a/src/plugin/game/hook.ts b/src/plugin/game/hook.ts index ee9ecad..4f78a30 100644 --- a/src/plugin/game/hook.ts +++ b/src/plugin/game/hook.ts @@ -11,7 +11,9 @@ const potionItems: AllIdsOf<'items'>[] = [ 'I491' ]; -mota.game.hook.on('afterGetItem', (itemId, x, y, isGentleClick) => { +const hook = Mota.require('var', 'hook'); + +hook.on('afterGetItem', (itemId, x, y, isGentleClick) => { // 获得一个道具后触发的事件 // itemId:获得的道具ID;x和y是该道具所在的坐标 // isGentleClick:是否是轻按触发的 @@ -45,7 +47,7 @@ mota.game.hook.on('afterGetItem', (itemId, x, y, isGentleClick) => { if (todo.length > 0) core.insertAction(todo, x, y); }); -mota.game.hook.on('afterOpenDoor', (doorId, x, y) => { +hook.on('afterOpenDoor', (doorId, x, y) => { // 开一个门后触发的事件 const todo: any[] = []; diff --git a/src/plugin/game/skillTree.js b/src/plugin/game/skillTree.js index 5a94a76..bcb0848 100644 --- a/src/plugin/game/skillTree.js +++ b/src/plugin/game/skillTree.js @@ -227,7 +227,7 @@ export function getSkillConsume(skill) { export function openTree() { if (main.replayChecking) return; - mota.ui.main.open('skillTree'); + Mota.require('var', 'mainUi').open('skillTree'); } /** diff --git a/src/plugin/game/ui.js b/src/plugin/game/ui.js index e3b022d..180accf 100644 --- a/src/plugin/game/ui.js +++ b/src/plugin/game/ui.js @@ -2,6 +2,8 @@ export {}; (function () { + const { mainUi, fixedUi } = Mota.requireAll('var'); + if (main.replayChecking) return (core.plugin.gameUi = { openItemShop: () => 0, @@ -10,7 +12,7 @@ export {}; function openItemShop(itemShopId) { if (!core.isReplaying()) { - mota.ui.main.open('shop', { + Mota.require('var', 'mainUi').open('shop', { shopId: itemShopId }); } @@ -23,19 +25,19 @@ export {}; } ui.prototype.drawBook = function () { - if (!core.isReplaying()) return mota.ui.main.open('book'); + if (!core.isReplaying()) return mainUi.open('book'); }; ui.prototype._drawToolbox = function () { - if (!core.isReplaying()) return mota.ui.main.open('toolbox'); + if (!core.isReplaying()) return mainUi.open('toolbox'); }; ui.prototype._drawEquipbox = function () { - if (!core.isReplaying()) return mota.ui.main.open('equipbox'); + if (!core.isReplaying()) return mainUi.open('equipbox'); }; ui.prototype.drawFly = function () { - if (!core.isReplaying()) return mota.ui.main.open('fly'); + if (!core.isReplaying()) return mainUi.open('fly'); }; control.prototype.updateStatusBar_update = function () { @@ -48,15 +50,15 @@ export {}; core.control.noAutoEvents = true; // 更新vue状态栏 updateVueStatusBar(); - mota.game.hook.emit('statusBarUpdate'); + Mota.require('var', 'hook').emit('statusBarUpdate'); }; // todo: 多个状态栏分离与控制 control.prototype.showStatusBar = function () { if (main.mode == 'editor') return; core.removeFlag('hideStatusBar'); - if (!mota.ui.fixed.hasName('statusBar')) { - mota.ui.fixed.open('statusBar'); + if (!fixedUi.hasName('statusBar')) { + fixedUi.open('statusBar'); } core.dom.tools.hard.style.display = 'block'; core.dom.toolBar.style.display = 'block'; @@ -68,7 +70,7 @@ export {}; // 如果原本就是隐藏的,则先显示 if (!core.domStyle.showStatusBar) this.showStatusBar(); if (core.isReplaying()) showToolbox = true; - mota.ui.fixed.closeByName('statusBar'); + fixedUi.closeByName('statusBar'); var toolItems = core.dom.tools; core.setFlag('hideStatusBar', true); @@ -87,7 +89,7 @@ export {}; function openSkill() { if (core.isReplaying()) return; - mota.ui.main.open('skill'); + mainUi.open('skill'); } core.plugin.gameUi = { diff --git a/src/plugin/keyCodes.ts b/src/plugin/keyCodes.ts index 44488db..4af6901 100644 --- a/src/plugin/keyCodes.ts +++ b/src/plugin/keyCodes.ts @@ -8,7 +8,7 @@ * Inspired somewhat from https://msdn.microsoft.com/en-us/library/windows/desktop/dd375731(v=vs.85).aspx * But these are "more general", as they should work across browsers & OS`s. */ -export const enum KeyCode { +export enum KeyCode { DependsOnKbLayout = -1, /** diff --git a/src/plugin/ui/achievement.ts b/src/plugin/ui/achievement.ts index c55981a..51bc9a7 100644 --- a/src/plugin/ui/achievement.ts +++ b/src/plugin/ui/achievement.ts @@ -51,7 +51,9 @@ export function completeAchievement(type: AchievementType, index: number) { if (type === 'explore' && !Object.values(achiDict).includes(index)) { checkCompletionAchievement(); } - mota.ui.fixed.open('completeAchi', { complete: `${type},${index}` }); + Mota.require('var', 'fixedUi').open('completeAchi', { + complete: `${type},${index}` + }); } /** diff --git a/src/types/plugin.d.ts b/src/types/plugin.d.ts index c63694f..2370125 100644 --- a/src/types/plugin.d.ts +++ b/src/types/plugin.d.ts @@ -361,7 +361,7 @@ type Forward = { type ForwardKeys = keyof Forward; -declare const mota: import('../core/index').Mota; +declare const Mota: import('../game/system').IMota; interface Window { - mota: import('../core/index').Mota; + Mota: import('../game/system').IMota; } diff --git a/src/ui/achievement.vue b/src/ui/achievement.vue index 8042f3c..cfc2113 100644 --- a/src/ui/achievement.vue +++ b/src/ui/achievement.vue @@ -176,7 +176,7 @@ function getAllAchievements(type: AchievementType): ResolvedAchievement[] { } function exit() { - mota.ui.main.close(props.num); + Mota.require('var', 'mainUi').close(props.num); } diff --git a/src/ui/bgmList.vue b/src/ui/bgmList.vue index 28dc547..1d02372 100644 --- a/src/ui/bgmList.vue +++ b/src/ui/bgmList.vue @@ -32,6 +32,7 @@ import { computed, onMounted, ref } from 'vue'; import Colomn from '../components/colomn.vue'; import bgm from '../data/bgm.json'; import { splitText } from '../plugin/utils'; +import { mainUi } from '@/core/main/init/ui'; const props = defineProps<{ num: number; @@ -55,7 +56,7 @@ const content = computed(() => { const name = computed(() => list[selected.value]!.name); function exit() { - mota.ui.main.close(props.num); + mainUi.close(props.num); } function select(id: BgmIds) { diff --git a/src/ui/book.vue b/src/ui/book.vue index 05e7bc6..7c479ef 100644 --- a/src/ui/book.vue +++ b/src/ui/book.vue @@ -45,11 +45,11 @@ import Scroll from '../components/scroll.vue'; import { getDamageColor, has, keycode } from '../plugin/utils'; import BookDetail from './bookDetail.vue'; import { LeftOutlined } from '@ant-design/icons-vue'; -import { KeyCode } from '../plugin/keyCodes'; import { ToShowEnemy, detailInfo } from '../plugin/ui/book'; import { getDetailedEnemy } from '../plugin/ui/fixed'; import { GameUi } from '@/core/main/custom/ui'; import { gameKey } from '@/core/main/init/hotkey'; +import { mainUi } from '@/core/main/init/ui'; const props = defineProps<{ num: number; @@ -118,8 +118,8 @@ async function show() { * 退出怪物手册 */ async function exit() { - const hold = mota.ui.main.holdOn(); - mota.ui.main.close(props.num); + const hold = mainUi.holdOn(); + mainUi.close(props.num); if (core.events.recoverEvents(core.status.event.interval)) { return; } else if (has(core.status.event.ui)) { diff --git a/src/ui/chapter.vue b/src/ui/chapter.vue index f2c24e6..8b2a30c 100644 --- a/src/ui/chapter.vue +++ b/src/ui/chapter.vue @@ -10,6 +10,7 @@ import { Animation, hyper, sleep } from 'mutate-animate'; import { onMounted } from 'vue'; import { has } from '../plugin/utils'; import { GameUi } from '@/core/main/custom/ui'; +import { fixedUi } from '@/core/main/init/ui'; const props = defineProps<{ num: number; @@ -56,7 +57,7 @@ onMounted(async () => { } if (time >= 4050) { - mota.ui.fixed.close(props.num); + fixedUi.close(props.num); ani.ticker.destroy(); } diff --git a/src/ui/completeAchievement.vue b/src/ui/completeAchievement.vue index 1d61ffe..23ab899 100644 --- a/src/ui/completeAchievement.vue +++ b/src/ui/completeAchievement.vue @@ -28,6 +28,7 @@ import { totalPoint } from '../plugin/ui/achievement'; import { GameUi } from '@/core/main/custom/ui'; +import { fixedUi } from '@/core/main/init/ui'; const height = window.innerHeight; @@ -62,7 +63,7 @@ onMounted(async () => { now.value = Math.floor(nowPoint + point * ratio); }); await sleep(4600); - mota.ui.fixed.close(props.num); + fixedUi.close(props.num); }); diff --git a/src/ui/desc.vue b/src/ui/desc.vue index b590b1e..355d776 100644 --- a/src/ui/desc.vue +++ b/src/ui/desc.vue @@ -24,6 +24,7 @@ import { splitText } from '../plugin/utils'; import Colomn from '../components/colomn.vue'; import { GameUi } from '@/core/main/custom/ui'; import { gameKey } from '@/core/main/init/hotkey'; +import { mainUi } from '@/core/main/init/ui'; const props = defineProps<{ num: number; @@ -35,7 +36,7 @@ type DescKey = keyof typeof desc; const selected = ref(Object.keys(desc)[0] as DescKey); function exit() { - mota.ui.main.close(props.num); + mainUi.close(props.num); } const content = computed(() => { diff --git a/src/ui/equipbox.vue b/src/ui/equipbox.vue index afbadc9..a6138a4 100644 --- a/src/ui/equipbox.vue +++ b/src/ui/equipbox.vue @@ -197,6 +197,7 @@ import { hyper } from 'mutate-animate'; import { GameUi } from '@/core/main/custom/ui'; import { gameKey } from '@/core/main/init/hotkey'; import { getStatusLabel } from '../plugin/utils'; +import { mainUi } from '@/core/main/init/ui'; const props = defineProps<{ num: number; @@ -316,7 +317,7 @@ function changeSort() { } function exit() { - mota.ui.main.close(props.num); + mainUi.close(props.num); } function clickList(i: number) { @@ -434,10 +435,10 @@ function dragout(e: Event) { } function toTool() { - mota.ui.main.holdOn(); + mainUi.holdOn(); exit(); nextTick(() => { - mota.ui.main.open('toolbox'); + mainUi.open('toolbox'); }); } diff --git a/src/ui/fixedDetail.vue b/src/ui/fixedDetail.vue index 9d4925b..33db5c2 100644 --- a/src/ui/fixedDetail.vue +++ b/src/ui/fixedDetail.vue @@ -14,6 +14,7 @@ import BookDetail from './bookDetail.vue'; import { detailInfo } from '../plugin/ui/book'; import { hovered } from '@/core/main/init/fixed'; import { GameUi } from '@/core/main/custom/ui'; +import { mainUi } from '@/core/main/init/ui'; const props = defineProps<{ num: number; @@ -41,7 +42,7 @@ if (hovered) { } function close() { - mota.ui.main.close(props.num); + mainUi.close(props.num); } diff --git a/src/ui/fly.vue b/src/ui/fly.vue index 2e55398..7fa231f 100644 --- a/src/ui/fly.vue +++ b/src/ui/fly.vue @@ -102,6 +102,7 @@ import { downloadCanvasImage, tip } from '../plugin/utils'; import { GameUi } from '@/core/main/custom/ui'; import { gameKey } from '@/core/main/init/hotkey'; import { createChangable } from '@/plugin/ui/common'; +import { mainUi } from '@/core/main/init/ui'; const props = defineProps<{ num: number; @@ -158,7 +159,7 @@ let thumbCtx: CanvasRenderingContext2D; let downloadMode = false; function exit() { - mota.ui.main.close(props.num); + mainUi.close(props.num); } const title = computed(() => { diff --git a/src/ui/markedEnemy.vue b/src/ui/markedEnemy.vue index 9ac9a37..c9d0568 100644 --- a/src/ui/markedEnemy.vue +++ b/src/ui/markedEnemy.vue @@ -57,6 +57,7 @@ import Box from '../components/box.vue'; import Scroll from '../components/scroll.vue'; import BoxAnimate from '../components/boxAnimate.vue'; import { GameUi } from '@/core/main/custom/ui'; +import { fixedUi } from '@/core/main/init/ui'; const props = defineProps<{ num: number; @@ -99,7 +100,7 @@ const info = reactive({ const hidden = ref(false); watch(hidden, n => { - if (n) mota.ui.fixed.close(props.num); + if (n) fixedUi.close(props.num); }); watch(enemy.update, update); diff --git a/src/ui/settings.vue b/src/ui/settings.vue index 3582b1a..e9b3150 100644 --- a/src/ui/settings.vue +++ b/src/ui/settings.vue @@ -85,6 +85,7 @@ import { sleep } from 'mutate-animate'; import { KeyCode } from '../plugin/keyCodes'; import { gameKey } from '@/core/main/init/hotkey'; import { GameUi } from '@/core/main/custom/ui'; +import { mainUi } from '@/core/main/init/ui'; const props = defineProps<{ info?: MotaSetting; @@ -143,7 +144,7 @@ function click(key: string, index: number, item: MotaSettingItem) { } function exit() { - mota.ui.main.close(props.num); + mainUi.close(props.num); } gameKey.use(props.ui.symbol); diff --git a/src/ui/shop.vue b/src/ui/shop.vue index 0e5dbeb..0922de0 100644 --- a/src/ui/shop.vue +++ b/src/ui/shop.vue @@ -174,6 +174,7 @@ import Scroll from '../components/scroll.vue'; import BoxAnimate from '../components/boxAnimate.vue'; import { GameUi } from '@/core/main/custom/ui'; import { gameKey } from '@/core/main/init/hotkey'; +import { mainUi } from '@/core/main/init/ui'; const props = defineProps<{ num: number; @@ -306,7 +307,7 @@ gameKey function exit() { if (bought) core.status.route.push('closeShop'); - mota.ui.main.close(props.num); + mainUi.close(props.num); } onMounted(async () => { diff --git a/src/ui/skill.vue b/src/ui/skill.vue index c630024..f332b54 100644 --- a/src/ui/skill.vue +++ b/src/ui/skill.vue @@ -21,6 +21,7 @@ import { computed, ref } from 'vue'; import skills from '../data/skill.json'; import { has } from '../plugin/utils'; import Column from '../components/colomn.vue'; +import { mainUi } from '@/core/main/init/ui'; const props = defineProps<{ num: number; @@ -64,7 +65,7 @@ const content = computed(() => { }); function exit() { - mota.ui.main.close(props.num); + mainUi.close(props.num); } diff --git a/src/ui/skillTree.vue b/src/ui/skillTree.vue index 7c8b3dc..4ae6292 100644 --- a/src/ui/skillTree.vue +++ b/src/ui/skillTree.vue @@ -82,6 +82,7 @@ import { isMobile } from '../plugin/use'; import { sleep } from 'mutate-animate'; import { gameKey } from '@/core/main/init/hotkey'; import { GameUi } from '@/core/main/custom/ui'; +import { mainUi } from '@/core/main/init/ui'; const props = defineProps<{ num: number; @@ -179,7 +180,7 @@ const level = computed(() => { }); function exit() { - mota.ui.main.close(props.num); + mainUi.close(props.num); } function resize() { diff --git a/src/ui/start.vue b/src/ui/start.vue index 44b8389..a5cf6f1 100644 --- a/src/ui/start.vue +++ b/src/ui/start.vue @@ -72,6 +72,7 @@ import { loading } from '../core/loader/load'; import { isMobile } from '../plugin/use'; import { GameUi } from '@/core/main/custom/ui'; import { gameKey } from '@/core/main/init/hotkey'; +import { mainUi } from '@/core/main/init/ui'; const props = defineProps<{ num: number; @@ -155,7 +156,7 @@ async function clickStartButton(id: string) { } if (id === 'replay') core.chooseReplayFile(); if (id === 'achievement') { - mota.ui.main.open('achievement'); + mainUi.open('achievement'); } } diff --git a/src/ui/toolbox.vue b/src/ui/toolbox.vue index dd66d81..61440d1 100644 --- a/src/ui/toolbox.vue +++ b/src/ui/toolbox.vue @@ -119,6 +119,7 @@ import { message } from 'ant-design-vue'; import { KeyCode } from '../plugin/keyCodes'; import { GameUi } from '@/core/main/custom/ui'; import { gameKey } from '@/core/main/init/hotkey'; +import { mainUi } from '@/core/main/init/ui'; const props = defineProps<{ num: number; @@ -172,17 +173,17 @@ async function select(id: ShowItemIds, nouse: boolean = false) { } function exit() { - mota.ui.main.close(props.num); + mainUi.close(props.num); } function use(id: ShowItemIds) { if (id === 'none') return; if (core.canUseItem(id)) { - const hold = mota.ui.main.holdOn(); + const hold = mainUi.holdOn(); exit(); nextTick(() => { core.useItem(id, false, () => { - if (mota.ui.main.stack.length === 0) { + if (mainUi.stack.length === 0) { hold.end(); } }); @@ -196,10 +197,10 @@ function use(id: ShowItemIds) { } async function toEquip() { - mota.ui.main.holdOn(); + mainUi.holdOn(); exit(); nextTick(() => { - mota.ui.main.open('equipbox'); + mainUi.open('equipbox'); }); }