From 7428f41c9356755c61bafb85c90f841470bc2370 Mon Sep 17 00:00:00 2001 From: unanmed <1319491857@qq.com> Date: Sun, 17 May 2026 22:03:22 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E7=A7=BB=E9=99=A4=20data-utils=20?= =?UTF-8?q?=E5=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages-user/data-fallback/package.json | 3 +- packages-user/data-state/package.json | 3 +- packages-user/data-state/src/enemy/index.ts | 1 - packages-user/data-state/src/legacy/move.ts | 14 +- packages-user/data-utils/package.json | 6 - packages-user/data-utils/src/index.ts | 1 - packages-user/data-utils/src/utils.ts | 70 ----- packages-user/entry-data/package.json | 5 +- packages-user/entry-data/src/create.ts | 6 +- packages-user/entry-data/src/mota.ts | 8 +- packages-user/legacy-plugin-data/package.json | 5 +- .../legacy-plugin-data/src/fallback.ts | 34 +-- packages/legacy-ui/src/preset/uiIns.ts | 1 - packages/legacy-ui/src/tools/fly.ts | 72 ++--- packages/legacy-ui/src/ui/book.vue | 254 ------------------ packages/legacy-ui/src/ui/index.ts | 1 - 16 files changed, 76 insertions(+), 408 deletions(-) delete mode 100644 packages-user/data-utils/package.json delete mode 100644 packages-user/data-utils/src/index.ts delete mode 100644 packages-user/data-utils/src/utils.ts delete mode 100644 packages/legacy-ui/src/ui/book.vue diff --git a/packages-user/data-fallback/package.json b/packages-user/data-fallback/package.json index ddf8fb0..0c9d6f2 100644 --- a/packages-user/data-fallback/package.json +++ b/packages-user/data-fallback/package.json @@ -3,7 +3,6 @@ "dependencies": { "@motajs/legacy-common": "workspace:*", "@user/data-state": "workspace:*", - "@user/data-base": "workspace:*", - "@user/data-utils": "workspace:*" + "@user/data-base": "workspace:*" } } diff --git a/packages-user/data-state/package.json b/packages-user/data-state/package.json index e3e224d..e9a666b 100644 --- a/packages-user/data-state/package.json +++ b/packages-user/data-state/package.json @@ -5,7 +5,6 @@ "@motajs/common": "workspace:*", "@user/data-common": "workspace:*", "@user/data-base": "workspace:*", - "@user/data-system": "workspace:*", - "@user/data-utils": "workspace:*" + "@user/data-system": "workspace:*" } } diff --git a/packages-user/data-state/src/enemy/index.ts b/packages-user/data-state/src/enemy/index.ts index ae9c5d4..23e0ffc 100644 --- a/packages-user/data-state/src/enemy/index.ts +++ b/packages-user/data-state/src/enemy/index.ts @@ -1,7 +1,6 @@ export * from './aura'; export * from './calculator'; export * from './comparer'; -export * from './damage'; export * from './final'; export * from './legacy'; export * from './mapDamage'; diff --git a/packages-user/data-state/src/legacy/move.ts b/packages-user/data-state/src/legacy/move.ts index c91c047..0a0db29 100644 --- a/packages-user/data-state/src/legacy/move.ts +++ b/packages-user/data-state/src/legacy/move.ts @@ -272,13 +272,13 @@ export class HeroMover extends ObjectMoverBase { return super.startMove(); } - private checkAutoSave(x: number, y: number, nx: number, ny: number) { - const index = `${x},${y}`; - const nIndex = `${nx},${ny}`; - const map = core.status.thisMap.enemy.mapDamage; - const dam = map[index]; - const nextDam = map[nIndex]; - if (!dam || !nextDam) return; + private checkAutoSave(_x: number, _y: number, _nx: number, _ny: number) { + // const index = `${x},${y}`; + // const nIndex = `${nx},${ny}`; + // const map = core.status.thisMap.enemy.mapDamage; + // const dam = map[index]; + // const nextDam = map[nIndex]; + // if (!dam || !nextDam) return; // 可以在这里判断地图伤害,并进行自动存档,例如在进入或离开地图伤害时存档 // if (dam.damage > 0 || nextDam.damage > 0) { // core.autosave() diff --git a/packages-user/data-utils/package.json b/packages-user/data-utils/package.json deleted file mode 100644 index 2a42245..0000000 --- a/packages-user/data-utils/package.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "name": "@user/data-utils", - "dependencies": { - "@user/data-base": "workspace:*" - } -} \ No newline at end of file diff --git a/packages-user/data-utils/src/index.ts b/packages-user/data-utils/src/index.ts deleted file mode 100644 index 04bca77..0000000 --- a/packages-user/data-utils/src/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './utils'; diff --git a/packages-user/data-utils/src/utils.ts b/packages-user/data-utils/src/utils.ts deleted file mode 100644 index 1e1df0d..0000000 --- a/packages-user/data-utils/src/utils.ts +++ /dev/null @@ -1,70 +0,0 @@ -const backDirMap: Record = { - up: 'down', - down: 'up', - left: 'right', - right: 'left', - leftup: 'rightdown', - rightup: 'leftdown', - leftdown: 'rightup', - rightdown: 'leftup' -}; - -export function backDir(dir: Dir): Dir; -export function backDir(dir: Dir2): Dir2; -export function backDir(dir: Dir2): Dir2 { - return backDirMap[dir]; -} - -export function has(v: T): v is NonNullable { - return v !== null && v !== void 0; -} - -export function ensureArray(arr: T): T extends any[] ? T : T[] { - // @ts-expect-error 需要弃用 - return arr instanceof Array ? arr : [arr]; -} - -export function ofDir(x: number, y: number, dir: Dir2): LocArr { - const { x: dx, y: dy } = core.utils.scan2[dir]; - return [x + dx, y + dy]; -} - -/** - * 计算曼哈顿距离 - */ -export function manhattan(x1: number, y1: number, x2: number, y2: number) { - return Math.abs(x1 - x2) + Math.abs(y1 - y2); -} - -export function formatDamage(damage: number): DamageString { - let dam = ''; - let color = ''; - if (!Number.isFinite(damage)) { - dam = '???'; - color = '#f22'; - } else { - dam = core.formatBigNumber(damage, true); - if (damage <= 0) color = '#1f1'; - else if (damage < core.status.hero.hp / 3) color = '#fff'; - else if (damage < (core.status.hero.hp * 2) / 3) color = '#ff0'; - else if (damage < core.status.hero.hp) color = '#f93'; - else color = '#f22'; - } - - return { damage: dam, color: color as Color }; -} - -/** - * 获取两个坐标的相对方向 - * @param from 初始坐标 - * @param to 指向坐标 - */ -export function findDir(from: Loc, to: Loc): Dir | 'none' { - const dx = Math.sign(to.x - from.x); - const dy = Math.sign(to.y - from.y); - return ( - (Object.entries(core.utils.scan).find(v => { - return v[1].x === dx && v[1].y === dy; - })?.[0] as Dir) ?? 'none' - ); -} diff --git a/packages-user/entry-data/package.json b/packages-user/entry-data/package.json index c2e0e05..fc2b3c0 100644 --- a/packages-user/entry-data/package.json +++ b/packages-user/entry-data/package.json @@ -2,10 +2,11 @@ "name": "@user/entry-data", "dependencies": { "@motajs/legacy-common": "workspace:*", + "@user/data-common": "workspace:*", "@user/data-base": "workspace:*", + "@user/data-system": "workspace:*", "@user/data-fallback": "workspace:*", "@user/data-state": "workspace:*", - "@user/data-utils": "workspace:*", "@user/legacy-plugin-data": "workspace:*" } -} \ No newline at end of file +} diff --git a/packages-user/entry-data/src/create.ts b/packages-user/entry-data/src/create.ts index b52b60e..95be547 100644 --- a/packages-user/entry-data/src/create.ts +++ b/packages-user/entry-data/src/create.ts @@ -1,10 +1,11 @@ import { Mota } from './mota'; import * as Common from '@motajs/common'; import * as LegacyCommon from '@motajs/legacy-common'; +import * as DataCommon from '@user/data-common'; import * as DataBase from '@user/data-base'; +import * as DataSystem from '@user/data-system'; import * as DataFallback from '@user/data-fallback'; import * as DataState from '@user/data-state'; -import * as DataUtils from '@user/data-utils'; import * as LegacyPluginData from '@user/legacy-plugin-data'; export function create() { @@ -12,10 +13,11 @@ export function create() { Mota.register('@motajs/common', Common); Mota.register('@motajs/legacy-common', LegacyCommon); + Mota.register('@user/data-common', DataCommon); Mota.register('@user/data-base', DataBase); + Mota.register('@user/data-system', DataSystem); Mota.register('@user/data-fallback', DataFallback); Mota.register('@user/data-state', DataState); - Mota.register('@user/data-utils', DataUtils); Mota.register('@user/legacy-plugin-data', LegacyPluginData); DataBase.loading.emit('dataRegistered'); diff --git a/packages-user/entry-data/src/mota.ts b/packages-user/entry-data/src/mota.ts index 1a467e9..c9106e0 100644 --- a/packages-user/entry-data/src/mota.ts +++ b/packages-user/entry-data/src/mota.ts @@ -10,10 +10,11 @@ import type * as RenderVue from '@motajs/render-vue'; import type * as System from '@motajs/system'; import type * as UserClientBase from '@user/client-base'; import type * as ClientModules from '@user/client-modules'; +import type * as DataCommon from '@user/data-common'; import type * as DataBase from '@user/data-base'; -import type * as DataFallback from '@user/data-fallback'; +import type * as DataSystem from '@user/data-system'; import type * as DataState from '@user/data-state'; -import type * as DataUtils from '@user/data-utils'; +import type * as DataFallback from '@user/data-fallback'; import type * as LegacyPluginClient from '@user/legacy-plugin-client'; import type * as LegacyPluginData from '@user/legacy-plugin-data'; // ---------- 必要的第三方库 @@ -34,10 +35,11 @@ interface ModuleInterface { '@motajs/system': typeof System; '@user/client-base': typeof UserClientBase; '@user/client-modules': typeof ClientModules; + '@user/data-common': typeof DataCommon; '@user/data-base': typeof DataBase; + '@user/data-system': typeof DataSystem; '@user/data-fallback': typeof DataFallback; '@user/data-state': typeof DataState; - '@user/data-utils': typeof DataUtils; '@user/legacy-plugin-client': typeof LegacyPluginClient; '@user/legacy-plugin-data': typeof LegacyPluginData; // ---------- 必要的第三方库 diff --git a/packages-user/legacy-plugin-data/package.json b/packages-user/legacy-plugin-data/package.json index 2cd40c9..b04c0a0 100644 --- a/packages-user/legacy-plugin-data/package.json +++ b/packages-user/legacy-plugin-data/package.json @@ -2,7 +2,6 @@ "name": "@user/legacy-plugin-data", "dependencies": { "@user/data-state": "workspace:*", - "@user/data-base": "workspace:*", - "@user/data-utils": "workspace:*" + "@user/data-base": "workspace:*" } -} \ No newline at end of file +} diff --git a/packages-user/legacy-plugin-data/src/fallback.ts b/packages-user/legacy-plugin-data/src/fallback.ts index a69fb7b..1dde98a 100644 --- a/packages-user/legacy-plugin-data/src/fallback.ts +++ b/packages-user/legacy-plugin-data/src/fallback.ts @@ -325,8 +325,8 @@ export function initFallback() { callback?.(); }; - const layer = state.maps.getLayerByAlias('event')!; - layer.openDoor(x, y).then(cb); + // const layer = state.maps.getLayerByAlias('event')!; + // layer.openDoor(x, y).then(cb); const animate = fallbackIds++; core.animateFrame.lastAsyncId = animate; @@ -373,9 +373,9 @@ export function initFallback() { if (core.status.replay.speed === 24) { cb(); } else { - const num = state.tileStore.idToNumber(id)!; - const layer = state.maps.getLayerByAlias('event')!; - layer.closeDoor(num, x, y).then(cb); + // const num = state.tileStore.idToNumber(id)!; + // const layer = state.maps.getLayerByAlias('event')!; + // layer.closeDoor(num, x, y).then(cb); const animate = fallbackIds++; core.animateFrame.lastAsyncId = animate; @@ -515,20 +515,20 @@ export function initFallback() { // 先使用 mainMapRenderer 妥协 const { client } = Mota.require('@user/client-modules'); const renderer = client.mainMapRenderer; - if (renderer.layerState !== state.maps) { - callback?.(); - return; - } - const layer = state.maps.getLayerByAlias('event'); - if (!layer) { - callback?.(); - return; - } + // if (renderer.layerState !== state.maps) { + // callback?.(); + // return; + // } + // const layer = state.maps.getLayerByAlias('event'); + // if (!layer) { + // callback?.(); + // return; + // } core.removeBlock(sx, sy); - const moving = renderer.addMovingBlock(layer, block.id, sx, sy); + // const moving = renderer.addMovingBlock(layer, block.id, sx, sy); core.updateStatusBar(); - await moving.moveRelative(fn, time); - moving.destroy(); + // await moving.moveRelative(fn, time); + // moving.destroy(); if (keep) { core.setBlock(block.id, ex, ey); diff --git a/packages/legacy-ui/src/preset/uiIns.ts b/packages/legacy-ui/src/preset/uiIns.ts index aac5eef..79cf479 100644 --- a/packages/legacy-ui/src/preset/uiIns.ts +++ b/packages/legacy-ui/src/preset/uiIns.ts @@ -4,7 +4,6 @@ import { VirtualKey } from '@motajs/legacy-system'; export const mainUi = new UiController(); mainUi.register( - new GameUi('book', UI.Book), new GameUi('toolbox', UI.Toolbox), new GameUi('equipbox', UI.Equipbox), new GameUi('settings', UI.Settings), diff --git a/packages/legacy-ui/src/tools/fly.ts b/packages/legacy-ui/src/tools/fly.ts index a28a961..fc8fc1c 100644 --- a/packages/legacy-ui/src/tools/fly.ts +++ b/packages/legacy-ui/src/tools/fly.ts @@ -522,45 +522,45 @@ export class MinimapDrawer { ctx.textBaseline = 'middle'; ctx.font = `3px "normal"`; ctx.strokeStyle = 'black'; - Mota.require('@user/data-state').ensureFloorDamage(floorId); + // Mota.require('@user/data-state').ensureFloorDamage(floorId); ctx.fillStyle = 'rgba(0, 0, 0, 0.6)'; ctx.fillRect(x - 6, y - 2, 12, 4); ctx.fillStyle = 'white'; - const enemy = core.status.maps[floorId].enemy.list; - if (enemy.size === 0) { - ctx.strokeStyle = 'lightgreen'; - ctx.lineCap = 'round'; - ctx.lineJoin = 'round'; - ctx.beginPath(); - ctx.moveTo(x - 1.5, y); - ctx.lineTo(x - 0.5, y + 1); - ctx.lineTo(x + 1.5, y - 1); - ctx.stroke(); - } else if (enemy.size <= 2) { - const idSet = new Set(); - enemy.forEach(v => { - idSet.add(v.id); - }); - const ids: EnemyIds[] = [...idSet]; - if (ids.length === 1) { - core.drawIcon(ctx, ids[0], x - 2, y - 2, 4, 4); - } else if (ids.length === 2) { - core.drawIcon(ctx, ids[0], x - 4, y - 2, 4, 4); - core.drawIcon(ctx, ids[1], x, y - 2, 4, 4); - } else { - core.drawIcon(ctx, ids[0], x - 5, y - 2, 4, 4); - core.drawIcon(ctx, ids[1], x - 1, y - 2, 4, 4); - ctx.fillStyle = 'white'; - ctx.strokeStyle = 'black'; - ctx.strokeText('…', x + 4, y); - ctx.fillText('…', x + 4, y); - } - } else { - ctx.fillStyle = 'white'; - ctx.textAlign = 'center'; - ctx.textBaseline = 'middle'; - ctx.fillText(`+${enemy.size}`, x, y); - } + // const enemy = core.status.maps[floorId].enemy.list; + // if (enemy.size === 0) { + // ctx.strokeStyle = 'lightgreen'; + // ctx.lineCap = 'round'; + // ctx.lineJoin = 'round'; + // ctx.beginPath(); + // ctx.moveTo(x - 1.5, y); + // ctx.lineTo(x - 0.5, y + 1); + // ctx.lineTo(x + 1.5, y - 1); + // ctx.stroke(); + // } else if (enemy.size <= 2) { + // const idSet = new Set(); + // enemy.forEach(v => { + // idSet.add(v.id); + // }); + // const ids: EnemyIds[] = [...idSet]; + // if (ids.length === 1) { + // core.drawIcon(ctx, ids[0], x - 2, y - 2, 4, 4); + // } else if (ids.length === 2) { + // core.drawIcon(ctx, ids[0], x - 4, y - 2, 4, 4); + // core.drawIcon(ctx, ids[1], x, y - 2, 4, 4); + // } else { + // core.drawIcon(ctx, ids[0], x - 5, y - 2, 4, 4); + // core.drawIcon(ctx, ids[1], x - 1, y - 2, 4, 4); + // ctx.fillStyle = 'white'; + // ctx.strokeStyle = 'black'; + // ctx.strokeText('…', x + 4, y); + // ctx.fillText('…', x + 4, y); + // } + // } else { + // ctx.fillStyle = 'white'; + // ctx.textAlign = 'center'; + // ctx.textBaseline = 'middle'; + // ctx.fillText(`+${enemy.size}`, x, y); + // } ctx.restore(); } diff --git a/packages/legacy-ui/src/ui/book.vue b/packages/legacy-ui/src/ui/book.vue deleted file mode 100644 index ec0ca28..0000000 --- a/packages/legacy-ui/src/ui/book.vue +++ /dev/null @@ -1,254 +0,0 @@ - - - - - - diff --git a/packages/legacy-ui/src/ui/index.ts b/packages/legacy-ui/src/ui/index.ts index cc85b9e..a24dbd3 100644 --- a/packages/legacy-ui/src/ui/index.ts +++ b/packages/legacy-ui/src/ui/index.ts @@ -1,4 +1,3 @@ -export { default as Book } from './book.vue'; export { default as BookDetail } from './bookDetail.vue'; export { default as Equipbox } from './equipbox.vue'; export { default as Fly } from './fly.vue';