From db6983b4bd709ab2749db59af78961b769e4ee09 Mon Sep 17 00:00:00 2001 From: unanmed <1319491857@qq.com> Date: Sat, 3 Feb 2024 18:01:15 +0800 Subject: [PATCH] refactor: hero --- public/libs/maps.js | 1 - src/core/common/eventEmitter.ts | 2 -- src/core/main/init/settings.tsx | 4 ++-- src/core/main/setting.ts | 32 +---------------------------- src/core/plugin.ts | 36 --------------------------------- src/game/index.ts | 3 +++ src/game/system.ts | 6 ++++-- src/plugin/game/index.ts | 2 -- src/plugin/mark.ts | 4 ++-- src/plugin/ui/equipbox.tsx | 2 +- src/ui/statusBar.vue | 2 +- 11 files changed, 14 insertions(+), 80 deletions(-) diff --git a/public/libs/maps.js b/public/libs/maps.js index 6cdeaaa..6aa2790 100644 --- a/public/libs/maps.js +++ b/public/libs/maps.js @@ -2551,7 +2551,6 @@ maps.prototype._drawThumbnail_realDrawTempCanvas = function ( blocks, options ) { - // todo: storage获取方式优化 const setting = Mota.require('var', 'mainSetting'); options.ctx.imageSmoothingEnabled = !setting.getValue( 'screen.antiAliasing', diff --git a/src/core/common/eventEmitter.ts b/src/core/common/eventEmitter.ts index 24baa18..0c46260 100644 --- a/src/core/common/eventEmitter.ts +++ b/src/core/common/eventEmitter.ts @@ -1,5 +1,3 @@ -// todo: 更改utils.ts的形式,使common文件夹可以同时在渲染进程和游戏进程使用 - function has(value: T): value is NonNullable { return value !== null && value !== undefined; } diff --git a/src/core/main/init/settings.tsx b/src/core/main/init/settings.tsx index c961b40..1654571 100644 --- a/src/core/main/init/settings.tsx +++ b/src/core/main/init/settings.tsx @@ -3,8 +3,6 @@ import { Button, InputNumber, Radio } from 'ant-design-vue'; import { mainUi } from './ui'; import { gameKey } from './hotkey'; -// todo: 数字类型改为一个输入框,一个加按钮一个减按钮;新增单选框 - interface Components { Default: SettingComponent; Boolean: SettingComponent; @@ -14,6 +12,8 @@ interface Components { RadioSetting: (items: string[]) => SettingComponent; } +export type { Components as SettingDisplayComponents }; + export function createSettingComponents() { const com: Components = { Default: DefaultSetting, diff --git a/src/core/main/setting.ts b/src/core/main/setting.ts index 3fa3ba5..ad4c760 100644 --- a/src/core/main/setting.ts +++ b/src/core/main/setting.ts @@ -355,25 +355,11 @@ function handleScreenSetting( if (key === 'fullscreen') { // 全屏 triggerFullscreen(n as boolean); - } else if (key === 'halo') { - // 光环 - // core.setLocalStorage('showHalo', n); - } else if (key === 'frag') { - // 打怪特效 - // core.setLocalStorage('frag', n); - } else if (key === 'itemDetail') { - // 宝石血瓶显伤 - // core.setLocalStorage('itemDetail', n); } else if (key === 'heroDetail') { // 勇士显伤 - // core.setLocalStorage('heroDetail', n); core.drawHero(); - } else if (key === 'transition') { - // 界面动画 - // core.setLocalStorage('transition', n); } else if (key === 'antiAlias') { // 抗锯齿 - // core.setLocalStorage('antiAlias', n); for (const canvas of core.dom.gameCanvas) { if (core.domStyle.hdCanvas.includes(canvas.id)) continue; if (n) { @@ -384,12 +370,7 @@ function handleScreenSetting( } } else if (key === 'fontSize') { // 字体大小 - // core.setLocalStorage('fontSize', n); root.style.fontSize = `${n}px`; - } else if (key === 'smoothView') { - // core.setLocalStorage('smoothView', n); - } else if (key === 'criticalGem') { - // core.setLocalStorage('criticalGem', n); } } @@ -401,9 +382,6 @@ function handleActionSetting( if (key === 'autoSkill') { // 自动切换技能 flags.autoSkill = n; - } else if (key === 'fixed') { - // 定点查看 - // core.setLocalStorage('fixed', n); } } @@ -411,15 +389,7 @@ function handleUtilsSetting( key: string, n: T, o: T -) { - if (key === 'betterLoad') { - // 加载优化 - // core.setLocalStorage('betterLoad', n); - } else if (key === 'autoScale') { - // 自动放缩 - // core.setLocalStorage('autoScale', n); - } -} +) {} // ----- 游戏的所有设置项 // todo: 虚拟键盘缩放,小地图楼传缩放 diff --git a/src/core/plugin.ts b/src/core/plugin.ts index 6d1c4c7..26cedbd 100644 --- a/src/core/plugin.ts +++ b/src/core/plugin.ts @@ -38,39 +38,3 @@ Mota.Plugin.register('frag_r', frag, frag.init); Mota.Plugin.register('use_r', use); Mota.Plugin.register('gameCanvas_r', gameCanvas); Mota.Plugin.register('smooth_r', smooth, smooth.init); - -// // 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()] -// ]; - -// 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; -// }); -// } diff --git a/src/game/index.ts b/src/game/index.ts index 43b9958..44a2aff 100644 --- a/src/game/index.ts +++ b/src/game/index.ts @@ -6,6 +6,7 @@ import { Range } from '@/plugin/game/range'; import { specials } from './enemy/special'; import { gameListener, hook, loading } from './game'; import * as battle from './enemy/battle'; +import * as hero from './hero'; // ----- 类注册 Mota.register('class', 'DamageEnemy', DamageEnemy); @@ -15,6 +16,8 @@ Mota.register('class', 'IndexedEventEmitter', IndexedEventEmitter); Mota.register('class', 'Range', Range); // ----- 函数注册 Mota.register('fn', 'getEnemy', battle.getEnemy); +Mota.register('fn', 'getHeroStatusOn', hero.getHeroStatusOn); +Mota.register('fn', 'getHeroStatusOf', hero.getHeroStatusOf); // ----- 变量注册 Mota.register('var', 'enemySpecials', specials); Mota.register('var', 'hook', hook); diff --git a/src/game/system.ts b/src/game/system.ts index b124f7a..81e5526 100644 --- a/src/game/system.ts +++ b/src/game/system.ts @@ -29,7 +29,8 @@ import type { specials } from './enemy/special'; import type { Range } from '@/plugin/game/range'; import type { KeyCode } from '@/plugin/keyCodes'; import type { Ref } from 'vue'; -import * as battle from './enemy/battle'; +import type * as battle from './enemy/battle'; +import type * as hero from './hero'; interface ClassInterface { // 渲染进程与游戏进程通用 @@ -61,8 +62,9 @@ interface ClassInterface { } type _IBattle = typeof battle; +type _IHero = typeof hero; -interface FunctionInterface extends _IBattle { +interface FunctionInterface extends _IBattle, _IHero { // 定义于渲染进程,录像中会进行polyfill,但是不执行任何内容 readyAllResource(): void; // 定义于游戏进程,渲染进程依然可用 diff --git a/src/plugin/game/index.ts b/src/plugin/game/index.ts index 44d4a2e..5374d54 100644 --- a/src/plugin/game/index.ts +++ b/src/plugin/game/index.ts @@ -6,7 +6,6 @@ import * as replay from './replay'; import * as ui from './ui'; import * as rewrite from './fx/rewrite'; import * as halo from './fx/halo'; -import * as hero from '../../game/hero'; import * as loopMap from './loopMap'; import * as removeMap from './removeMap'; import * as shop from './shop'; @@ -37,7 +36,6 @@ Mota.Plugin.register('study_g', study); Mota.Plugin.register('remainEnemy_g', remainEnemy); Mota.Plugin.register('checkBlock_g', checkBlock, checkBlock.init); // todo: 这几个不应该放到插件 -Mota.Plugin.register('hero_g', hero); Mota.Plugin.register('ui_g', ui, ui.init); // export { diff --git a/src/plugin/mark.ts b/src/plugin/mark.ts index acb3db5..20b161c 100644 --- a/src/plugin/mark.ts +++ b/src/plugin/mark.ts @@ -43,7 +43,7 @@ export function markEnemy(id: EnemyIds) { id, enemy, mode: 0b011111, - lastAtk: Mota.Plugin.require('hero_g').getHeroStatusOn('atk', 'empty'), + lastAtk: Mota.requireAll('fn').getHeroStatusOn('atk', 'empty'), lastDamage: enemy.calDamage().damage, status: 0b0, update: ref(true) @@ -65,7 +65,7 @@ export function unmarkEnemy(id: EnemyIds) { } export function checkMarkedEnemy() { - const { getHeroStatusOn } = Mota.Plugin.require('hero_g'); + const { getHeroStatusOn } = Mota.requireAll('fn'); marked.forEach(v => { const { id, enemy, mode, lastAtk, lastDamage, markDamage } = v; const atk = getHeroStatusOn('atk', 'empty'); diff --git a/src/plugin/ui/equipbox.tsx b/src/plugin/ui/equipbox.tsx index d9cb668..627e30b 100644 --- a/src/plugin/ui/equipbox.tsx +++ b/src/plugin/ui/equipbox.tsx @@ -59,7 +59,7 @@ export function getNowStatus(nowEquip?: Equip, onCol: boolean = false) { 'hpmax', 'money' ] as (keyof SelectType)[]; - const { getHeroStatusOn } = Mota.Plugin.require('hero_g'); + const { getHeroStatusOn } = Mota.requireAll('fn'); return (
diff --git a/src/ui/statusBar.vue b/src/ui/statusBar.vue index dc73a48..f96df96 100644 --- a/src/ui/statusBar.vue +++ b/src/ui/statusBar.vue @@ -181,7 +181,7 @@ watch(status, update); */ function update() { toShow.forEach(v => { - hero[v] = Mota.Plugin.require('hero_g').getHeroStatusOn(v); + hero[v] = Mota.requireAll('fn').getHeroStatusOn(v); }); keys[0] = core.itemCount('yellowKey'); keys[1] = core.itemCount('blueKey');