refactor: 移除 data-utils 包

This commit is contained in:
unanmed 2026-05-17 22:03:22 +08:00
parent 0f5b1f4d80
commit 7428f41c93
16 changed files with 76 additions and 408 deletions

View File

@ -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:*"
}
}

View File

@ -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:*"
}
}

View File

@ -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';

View File

@ -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()

View File

@ -1,6 +0,0 @@
{
"name": "@user/data-utils",
"dependencies": {
"@user/data-base": "workspace:*"
}
}

View File

@ -1 +0,0 @@
export * from './utils';

View File

@ -1,70 +0,0 @@
const backDirMap: Record<Dir2, Dir2> = {
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<T>(v: T): v is NonNullable<T> {
return v !== null && v !== void 0;
}
export function ensureArray<T>(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'
);
}

View File

@ -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:*"
}
}
}

View File

@ -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');

View File

@ -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;
// ---------- 必要的第三方库

View File

@ -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:*"
}
}
}

View File

@ -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);

View File

@ -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),

View File

@ -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<EnemyIds>();
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<EnemyIds>();
// 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();
}

View File

@ -1,254 +0,0 @@
<!-- 怪物手册ui -->
<template>
<div id="book">
<div id="tools">
<span id="back" class="button-text tools" @click="exit"
><left-outlined />返回游戏</span
>
</div>
<div v-if="enemy.length === 0" id="none">
<div>本层无怪物</div>
</div>
<Scroll
v-else
style="width: 100%; height: 94%; font-family: normal"
v-model:now="scroll"
v-model:drag="drag"
>
<div v-for="(e, i) of toShow" class="enemy">
<EnemyOne
:selected="i === selected"
:enemy="e"
:key="i"
@select="select(e, i)"
@hover="selected = i"
></EnemyOne>
<Divider
dashed
style="width: 100%; border-color: #ddd4"
></Divider>
</div>
</Scroll>
</div>
<BookDetail
v-if="detail"
:from-book="true"
@close="closeDetail()"
></BookDetail>
</template>
<script setup lang="tsx">
import { onUnmounted, ref } from 'vue';
import EnemyOne from '../components/enemyOne.vue';
import Scroll from '../components/scroll.vue';
import BookDetail from './bookDetail.vue';
import { LeftOutlined } from '@ant-design/icons-vue';
import { ToShowEnemy, detailInfo } from '../tools/book';
import { getDetailedEnemy } from '../tools/fixed';
import { gameKey } from '@motajs/system';
import { mainSetting } from '../preset/settingIns';
import { isMobile } from '../use';
import { IMountedVBind } from '../interface';
import { isNil } from 'lodash-es';
import { Divider } from 'ant-design-vue';
const props = defineProps<IMountedVBind>();
const floorId =
// @ts-ignore
core.floorIds[core.status.event?.ui?.index] ?? core.status.floorId;
const enemy = core.getCurrentEnemys(floorId);
const toShow: ToShowEnemy[] = enemy.map(v =>
getDetailedEnemy(v.enemy, floorId)
);
const scroll = ref(0);
const drag = ref(false);
const detail = ref(false);
const selected = ref(0);
const settingScale = mainSetting.getValue('ui.bookScale', 100) / 100;
const scale = isMobile
? Math.max(settingScale * 15, 20)
: Math.max(
(window.innerWidth / window.innerHeight) * 15 * settingScale,
20
);
/**
* 选择怪物展示详细信息
* @param enemy 选择的怪物
* @param index 选择的怪物索引
*/
function select(enemy: ToShowEnemy, index: number) {
if (drag.value) return;
const h = window.innerHeight;
const y = index * h * 0.2 - scroll.value;
detailInfo.enemy = enemy;
detailInfo.pos = y;
detail.value = true;
hide();
}
/**
* 隐藏怪物手册
*/
async function hide() {
const div = document.getElementById('book') as HTMLDivElement;
div.style.display = 'none';
}
/**
* 关闭详细信息
*/
async function closeDetail() {
show();
detail.value = false;
}
/**
* 显示怪物手册
*/
async function show() {
const div = document.getElementById('book') as HTMLDivElement;
div.style.display = 'flex';
}
/**
* 退出怪物手册
*/
async function exit() {
const hold = props.controller.holdOn();
props.controller.close(props.num);
if (core.events.recoverEvents(core.status.event.interval)) {
hold.end(true);
return;
} else if (!isNil(core.status.event.ui)) {
core.status.boxAnimateObjs = [];
// @ts-ignore
core.ui._drawViewMaps(core.status.event.ui);
hold.end(true);
} else hold.end();
}
function checkScroll() {
const h = window.innerHeight;
const y = (selected.value * h * scale) / 100 - scroll.value;
if (y < 0) {
scroll.value += y - 20;
}
if (y > h * 0.655) {
scroll.value += y - h * 0.655 + 20;
}
}
//
setTimeout(() => {
gameKey.use(props.ui.symbol);
gameKey
.realize(
'@book_up',
() => {
if (selected.value > 0) {
selected.value--;
}
checkScroll();
},
{ type: 'down-repeat' }
)
.realize(
'@book_down',
() => {
if (selected.value < enemy.length - 1) {
selected.value++;
}
checkScroll();
},
{ type: 'down-repeat' }
)
.realize(
'@book_pageDown',
() => {
if (selected.value >= enemy.length - 5) {
selected.value = enemy.length - 1;
} else {
selected.value += 5;
}
checkScroll();
},
{ type: 'down-repeat' }
)
.realize(
'@book_pageUp',
() => {
if (selected.value <= 4) {
selected.value = 0;
} else {
selected.value -= 5;
}
checkScroll();
},
{ type: 'down-repeat' }
)
.realize('exit', () => {
exit();
})
.realize('confirm', () => {
select(toShow[selected.value], selected.value);
});
}, 0);
onUnmounted(() => {
gameKey.dispose(props.ui.symbol);
});
</script>
<style lang="less" scoped>
#book {
user-select: none;
width: 80%;
height: 100%;
overflow: hidden;
display: flex;
flex-direction: column;
justify-content: space-between;
}
#tools {
height: 6%;
font-size: 3.2vh;
}
#none {
width: 100%;
height: 100%;
font-size: 6vw;
display: flex;
justify-content: center;
align-items: center;
}
.enemy {
display: flex;
flex-direction: column;
height: v-bind('scale + "vh"');
width: 100%;
padding: 0 1% 0 1%;
}
@media screen and (max-width: 600px) {
#tools {
transform: translateY(-50%);
}
#book {
width: 100%;
padding: 5%;
}
.enemy {
height: v-bind('scale * 2 / 3 + "vh"');
}
}
</style>

View File

@ -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';