From 960dbd429a1b728551dbe493898481f74232d322 Mon Sep 17 00:00:00 2001 From: unanmed <1319491857@qq.com> Date: Wed, 5 Mar 2025 21:16:37 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20src/core/main=20=E5=85=A8=E9=83=A8?= =?UTF-8?q?=E7=A7=BB=E5=85=A5=20monorepo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + .madgerc | 12 + package.json | 1 + packages/client-base/src/index.ts | 1 + packages/client-base/src/types.ts | 4 + packages/legacy-system/package.json | 6 + packages/legacy-system/src/index.ts | 2 + .../legacy-system/src}/misc.tsx | 4 +- .../legacy-system/src}/storage.ts | 0 packages/legacy-ui/package.json | 4 +- packages/legacy-ui/src/components/index.ts | 6 + packages/legacy-ui/src/components/minimap.vue | 3 +- .../legacy-ui/src/controller.ts | 7 +- .../legacy-ui/src}/danmaku.ts | 56 +- packages/legacy-ui/src/index.ts | 5 + packages/legacy-ui/src/mark.ts | 2 +- packages/legacy-ui/src/preset/danmaku.ts | 43 + .../legacy-ui/src/preset}/fixed.ts | 2 +- .../legacy-ui/src/preset}/hotkey.ts | 4 +- packages/legacy-ui/src/preset/index.ts | 6 + .../legacy-ui/src/preset}/keyboard.ts | 4 +- .../legacy-ui/src/preset}/settings.tsx | 10 +- packages/legacy-ui/src/preset/ui.ts | 364 +++++ packages/legacy-ui/src/setting.ts | 308 +++++ packages/legacy-ui/src/tools/fly.ts | 2 +- packages/legacy-ui/src/ui/book.vue | 8 +- packages/legacy-ui/src/ui/bookDetail.vue | 2 +- packages/legacy-ui/src/ui/chapter.vue | 4 +- .../legacy-ui/src/ui/completeAchievement.vue | 4 +- packages/legacy-ui/src/ui/danmaku.vue | 4 +- packages/legacy-ui/src/ui/danmakuEditor.vue | 12 +- packages/legacy-ui/src/ui/desc.vue | 6 +- packages/legacy-ui/src/ui/equipbox.vue | 6 +- packages/legacy-ui/src/ui/fixed.vue | 2 +- packages/legacy-ui/src/ui/fixedDetail.vue | 6 +- packages/legacy-ui/src/ui/fly.vue | 10 +- packages/legacy-ui/src/ui/hotkey.vue | 8 +- packages/legacy-ui/src/ui/load.vue | 4 +- packages/legacy-ui/src/ui/markedEnemy.vue | 4 +- packages/legacy-ui/src/ui/settings.vue | 10 +- packages/legacy-ui/src/ui/shop.vue | 6 +- packages/legacy-ui/src/ui/skill.vue | 2 +- packages/legacy-ui/src/ui/skillTree.vue | 6 +- packages/legacy-ui/src/ui/start.vue | 10 +- packages/legacy-ui/src/ui/toolEditor.vue | 586 -------- packages/legacy-ui/src/ui/toolbar.vue | 138 -- packages/legacy-ui/src/ui/toolbox.vue | 6 +- packages/legacy-ui/src/utils.ts | 5 +- packages/render-vue/package.json | 3 +- packages/render-vue/src/use.ts | 3 +- packages/system-action/package.json | 6 + .../system-action/src}/hotkey.ts | 0 packages/system-action/src/index.ts | 2 + .../system-action/src}/keyboard.ts | 8 +- packages/system/package.json | 3 +- packages/system/src/index.ts | 1 + pnpm-lock.yaml | 1187 +++++++++++++---- src/App.vue | 2 +- src/core/index.ts | 64 +- src/core/interface.ts | 21 - src/core/main/custom/toolbar.ts | 386 ------ src/core/main/init/index.ts | 3 - src/core/main/init/toolbar.tsx | 1071 --------------- src/core/main/init/ui.ts | 74 - src/core/main/setting.ts | 574 -------- src/core/package.ts | 15 - src/game/state/hero.ts | 122 +- src/game/state/item.ts | 51 +- src/game/state/move.ts | 31 +- src/game/state/state.ts | 127 -- src/game/system.ts | 2 +- src/{core/main => module}/action/move.ts | 4 +- src/module/fallback/audio.ts | 2 +- src/module/render/ui/settings.tsx | 6 +- src/module/render/ui/toolbar.tsx | 4 +- src/package.json | 4 +- src/plugin/fx/halo.ts | 2 +- src/plugin/fx/itemDetail.ts | 2 +- src/plugin/fx/portal.ts | 2 +- 79 files changed, 1872 insertions(+), 3616 deletions(-) create mode 100644 .madgerc create mode 100644 packages/client-base/src/types.ts create mode 100644 packages/legacy-system/package.json create mode 100644 packages/legacy-system/src/index.ts rename {src/core/main/init => packages/legacy-system/src}/misc.tsx (71%) rename {src/core/main => packages/legacy-system/src}/storage.ts (100%) create mode 100644 packages/legacy-ui/src/components/index.ts rename src/core/main/custom/ui.ts => packages/legacy-ui/src/controller.ts (98%) rename {src/core/main/custom => packages/legacy-ui/src}/danmaku.ts (90%) create mode 100644 packages/legacy-ui/src/preset/danmaku.ts rename {src/core/main/init => packages/legacy-ui/src/preset}/fixed.ts (96%) rename {src/core/main/init => packages/legacy-ui/src/preset}/hotkey.ts (99%) create mode 100644 packages/legacy-ui/src/preset/index.ts rename {src/core/main/init => packages/legacy-ui/src/preset}/keyboard.ts (99%) rename {src/core/main/init => packages/legacy-ui/src/preset}/settings.tsx (95%) create mode 100644 packages/legacy-ui/src/preset/ui.ts create mode 100644 packages/legacy-ui/src/setting.ts delete mode 100644 packages/legacy-ui/src/ui/toolEditor.vue delete mode 100644 packages/legacy-ui/src/ui/toolbar.vue create mode 100644 packages/system-action/package.json rename {src/core/main/custom => packages/system-action/src}/hotkey.ts (100%) create mode 100644 packages/system-action/src/index.ts rename {src/core/main/custom => packages/system-action/src}/keyboard.ts (96%) delete mode 100644 src/core/interface.ts delete mode 100644 src/core/main/custom/toolbar.ts delete mode 100644 src/core/main/init/index.ts delete mode 100644 src/core/main/init/toolbar.tsx delete mode 100644 src/core/main/init/ui.ts delete mode 100644 src/core/main/setting.ts delete mode 100644 src/core/package.ts delete mode 100644 src/game/state/state.ts rename src/{core/main => module}/action/move.ts (97%) diff --git a/.gitignore b/.gitignore index d31fd2d..190dc03 100644 --- a/.gitignore +++ b/.gitignore @@ -49,3 +49,4 @@ script/people.ts docs/ user.ts .antlr +graph.svg \ No newline at end of file diff --git a/.madgerc b/.madgerc new file mode 100644 index 0000000..edc2560 --- /dev/null +++ b/.madgerc @@ -0,0 +1,12 @@ +{ + "fileExtensions": [ + "ts", + "tsx" + ], + "tsConfig": "./tsconfig.json", + "detectiveOptions": { + "ts": { + "skipTypeImports": true + } + } +} \ No newline at end of file diff --git a/package.json b/package.json index 9c56503..415433e 100644 --- a/package.json +++ b/package.json @@ -63,6 +63,7 @@ "glob": "^11.0.1", "globals": "^15.14.0", "less": "^4.2.0", + "madge": "^8.0.0", "postcss-preset-env": "^9.6.0", "rollup": "^3.29.4", "terser": "^5.31.6", diff --git a/packages/client-base/src/index.ts b/packages/client-base/src/index.ts index ff0f25a..192a965 100644 --- a/packages/client-base/src/index.ts +++ b/packages/client-base/src/index.ts @@ -1 +1,2 @@ export * from './keyCodes'; +export * from './types'; diff --git a/packages/client-base/src/types.ts b/packages/client-base/src/types.ts new file mode 100644 index 0000000..7e28266 --- /dev/null +++ b/packages/client-base/src/types.ts @@ -0,0 +1,4 @@ +export interface ResponseBase { + code: number; + message: string; +} diff --git a/packages/legacy-system/package.json b/packages/legacy-system/package.json new file mode 100644 index 0000000..488ee33 --- /dev/null +++ b/packages/legacy-system/package.json @@ -0,0 +1,6 @@ +{ + "name": "@motajs/legacy-system", + "dependencies": { + "@motajs/system-action": "workspace:*" + } +} \ No newline at end of file diff --git a/packages/legacy-system/src/index.ts b/packages/legacy-system/src/index.ts new file mode 100644 index 0000000..ef18468 --- /dev/null +++ b/packages/legacy-system/src/index.ts @@ -0,0 +1,2 @@ +export * from './misc'; +export * from './storage'; diff --git a/src/core/main/init/misc.tsx b/packages/legacy-system/src/misc.tsx similarity index 71% rename from src/core/main/init/misc.tsx rename to packages/legacy-system/src/misc.tsx index 7b80101..5b9bf05 100644 --- a/src/core/main/init/misc.tsx +++ b/packages/legacy-system/src/misc.tsx @@ -1,5 +1,5 @@ -import { Keyboard } from '../custom/keyboard'; -import KeyboardUI from '@/panel/keyboard.vue'; +import { Keyboard } from '@motajs/system-action'; +import KeyboardUI from '../panel/keyboard.vue'; interface VirtualKeyProps { keyboard: Keyboard; diff --git a/src/core/main/storage.ts b/packages/legacy-system/src/storage.ts similarity index 100% rename from src/core/main/storage.ts rename to packages/legacy-system/src/storage.ts diff --git a/packages/legacy-ui/package.json b/packages/legacy-ui/package.json index 1edd02b..6ef2946 100644 --- a/packages/legacy-ui/package.json +++ b/packages/legacy-ui/package.json @@ -4,6 +4,8 @@ "@motajs/render": "workspace:*", "@motajs/common": "workspace:*", "@motajs/client": "workspace:*", - "@motajs/client-base": "workspace:*" + "@motajs/client-base": "workspace:*", + "@motajs/legacy-system": "workspace:*", + "@motajs/system-action": "workspace:*" } } \ No newline at end of file diff --git a/packages/legacy-ui/src/components/index.ts b/packages/legacy-ui/src/components/index.ts new file mode 100644 index 0000000..d8700d7 --- /dev/null +++ b/packages/legacy-ui/src/components/index.ts @@ -0,0 +1,6 @@ +export { default as Box } from './box.vue'; +export { default as BoxAnimate } from './boxAnimate.vue'; +export { default as Column } from './colomn.vue'; +export { default as EnemyOne } from './enemyOne.vue'; +export { default as Minimap } from './minimap.vue'; +export { default as Scroll } from './scroll.vue'; diff --git a/packages/legacy-ui/src/components/minimap.vue b/packages/legacy-ui/src/components/minimap.vue index 7509a4d..509f57a 100644 --- a/packages/legacy-ui/src/components/minimap.vue +++ b/packages/legacy-ui/src/components/minimap.vue @@ -8,7 +8,7 @@ import { requireUniqueSymbol } from '../utils'; import { MinimapDrawer, getArea } from '../tools/fly'; import { useDrag, useWheel } from '../use'; import { debounce } from 'lodash-es'; -import { mainSetting } from '@/core/main/setting'; +import { mainSetting } from '../preset/ui'; const props = defineProps<{ action?: boolean; @@ -168,6 +168,7 @@ onMounted(() => { }); onUnmounted(() => { + const hook = Mota.require('var', 'hook'); hook.off('afterChangeFloor', onChange); hook.off('afterBattle', afterBattle); }); diff --git a/src/core/main/custom/ui.ts b/packages/legacy-ui/src/controller.ts similarity index 98% rename from src/core/main/custom/ui.ts rename to packages/legacy-ui/src/controller.ts index 5a2ca94..3ba155f 100644 --- a/src/core/main/custom/ui.ts +++ b/packages/legacy-ui/src/controller.ts @@ -1,6 +1,5 @@ import { Component, shallowReactive } from 'vue'; import { EventEmitter } from '@motajs/legacy-common'; -import { Hotkey } from './hotkey'; interface FocusEvent { focus: (before: T | null, after: T) => void; @@ -125,6 +124,7 @@ type UiVBind = Record; interface MountedVBind { num: number; ui: GameUi; + controller: UiController; [x: string]: any; } @@ -132,14 +132,12 @@ export class GameUi extends EventEmitter { static uiList: GameUi[] = []; component: Component; - hotkey?: Hotkey; id: string; symbol: symbol = Symbol(); - constructor(id: string, component: Component, hotkey?: Hotkey) { + constructor(id: string, component: Component) { super(); this.component = component; - this.hotkey = hotkey; this.id = id; GameUi.uiList.push(this); } @@ -273,6 +271,7 @@ export class UiController extends Focus { const bind = { num, ui, + controller: this, ...(vBind ?? {}) }; const sui = ui.with(bind, vOn); diff --git a/src/core/main/custom/danmaku.ts b/packages/legacy-ui/src/danmaku.ts similarity index 90% rename from src/core/main/custom/danmaku.ts rename to packages/legacy-ui/src/danmaku.ts index 732a02c..c064b00 100644 --- a/src/core/main/custom/danmaku.ts +++ b/packages/legacy-ui/src/danmaku.ts @@ -1,18 +1,10 @@ -import BoxAnimate from '@/components/boxAnimate.vue'; import { EventEmitter } from 'eventemitter3'; import { logger } from '@motajs/common'; -import { ResponseBase } from '@/core/interface'; -import { - deleteWith, - ensureArray, - getIconHeight, - parseCss, - tip -} from '@motajs/legacy-ui'; +import { deleteWith, ensureArray, parseCss, tip } from '@motajs/legacy-ui'; +import { ResponseBase } from '@motajs/client-base'; import axios, { AxiosResponse, toFormData } from 'axios'; -import { Component, VNode, h, shallowReactive } from 'vue'; +import { VNode, h, shallowReactive } from 'vue'; // /* @__PURE__ */ import { id, password } from '../../../../user'; -import { mainSetting } from '../setting'; type CSSObj = Partial>; @@ -213,8 +205,8 @@ export class Danmaku extends EventEmitter { * @param stroke 描边颜色 */ color(fill?: string, stroke?: string) { - fill && (this.textColor = fill); - stroke && (this.strokeColor = stroke); + if (fill) this.textColor = fill; + if (stroke) this.strokeColor = stroke; } /** @@ -492,41 +484,3 @@ export class Danmaku extends EventEmitter { this.specList[type] = fn; } } - -// 图标类型 -Danmaku.registerSpecContent('i', content => { - const height = getIconHeight(content as AllIds); - - return h(BoxAnimate as Component, { - id: content, - noborder: true, - noAnimate: true, - width: 32, - height - }); -}); - -if (import.meta.env.DEV) { - Danmaku.backend = `/danmaku`; -} - -Mota.require('var', 'hook').once('reset', () => { - Danmaku.fetch(); -}); - -// 勇士移动后显示弹幕 -Mota.require('var', 'hook').on('moveOneStep', (x, y, floor) => { - const enabled = mainSetting.getValue('ui.danmaku', true); - if (!enabled) return; - const f = Danmaku.allInPos[floor]; - if (f) { - const danmaku = f[`${x},${y}`]; - if (danmaku) { - danmaku.forEach(v => { - setTimeout(() => { - v.show(); - }, Math.random() * 1000); - }); - } - } -}); diff --git a/packages/legacy-ui/src/index.ts b/packages/legacy-ui/src/index.ts index 6f9797a..a841522 100644 --- a/packages/legacy-ui/src/index.ts +++ b/packages/legacy-ui/src/index.ts @@ -1,7 +1,12 @@ export * as UI from './ui'; +export * as Components from './components'; +export * from './preset'; export * from './tools'; export * from './animateController'; +export * from './controller'; +export * from './danmaku'; export * from './mark'; +export * from './setting'; export * from './use'; export * from './utils'; diff --git a/packages/legacy-ui/src/mark.ts b/packages/legacy-ui/src/mark.ts index 2678b40..afbc9f3 100644 --- a/packages/legacy-ui/src/mark.ts +++ b/packages/legacy-ui/src/mark.ts @@ -1,4 +1,4 @@ -import { fixedUi } from '@/core/main/init/ui'; +import { fixedUi } from './preset/ui'; import type { DamageEnemy } from '@/game/enemy/damage'; import { tip } from './utils'; import { ref, Ref } from 'vue'; diff --git a/packages/legacy-ui/src/preset/danmaku.ts b/packages/legacy-ui/src/preset/danmaku.ts new file mode 100644 index 0000000..ddd1a7c --- /dev/null +++ b/packages/legacy-ui/src/preset/danmaku.ts @@ -0,0 +1,43 @@ +import { Danmaku } from '../danmaku'; +import { Component, h } from 'vue'; +import { mainSetting } from './ui'; +import { getIconHeight } from '../utils'; +import { BoxAnimate } from '../components'; + +// 图标类型 +Danmaku.registerSpecContent('i', content => { + const height = getIconHeight(content as AllIds); + + return h(BoxAnimate as Component, { + id: content, + noborder: true, + noAnimate: true, + width: 32, + height + }); +}); + +if (import.meta.env.DEV) { + Danmaku.backend = `/danmaku`; +} + +Mota.require('var', 'hook').once('reset', () => { + Danmaku.fetch(); +}); + +// 勇士移动后显示弹幕 +Mota.require('var', 'hook').on('moveOneStep', (x, y, floor) => { + const enabled = mainSetting.getValue('ui.danmaku', true); + if (!enabled) return; + const f = Danmaku.allInPos[floor]; + if (f) { + const danmaku = f[`${x},${y}`]; + if (danmaku) { + danmaku.forEach(v => { + setTimeout(() => { + v.show(); + }, Math.random() * 1000); + }); + } + } +}); diff --git a/src/core/main/init/fixed.ts b/packages/legacy-ui/src/preset/fixed.ts similarity index 96% rename from src/core/main/init/fixed.ts rename to packages/legacy-ui/src/preset/fixed.ts index 1770790..9d869a5 100644 --- a/src/core/main/init/fixed.ts +++ b/packages/legacy-ui/src/preset/fixed.ts @@ -18,7 +18,7 @@ const showFixed = debounce((block: Block) => { if (!enemy) return; fixedUi.open( 'fixed', - { enemy, close, loc: [cx, cy] }, + { enemy, close, loc: [cx, cy], hovered }, { close: closeFixed } ); }, 200); diff --git a/src/core/main/init/hotkey.ts b/packages/legacy-ui/src/preset/hotkey.ts similarity index 99% rename from src/core/main/init/hotkey.ts rename to packages/legacy-ui/src/preset/hotkey.ts index 1a80f1c..667179d 100644 --- a/src/core/main/init/hotkey.ts +++ b/packages/legacy-ui/src/preset/hotkey.ts @@ -1,5 +1,5 @@ import { KeyCode } from '@motajs/client-base'; -import { gameKey, HotkeyJSON } from '../custom/hotkey'; +import { gameKey, HotkeyJSON } from '@motajs/system-action'; import { openDanmakuPoster, tip, @@ -9,7 +9,7 @@ import { } from '@motajs/legacy-ui'; import { hovered } from './fixed'; import { mainUi } from './ui'; -import { GameStorage } from '../storage'; +import { GameStorage } from '@motajs/legacy-system'; export const mainScope = Symbol.for('@key_main'); diff --git a/packages/legacy-ui/src/preset/index.ts b/packages/legacy-ui/src/preset/index.ts new file mode 100644 index 0000000..44f0eec --- /dev/null +++ b/packages/legacy-ui/src/preset/index.ts @@ -0,0 +1,6 @@ +export * from './ui'; +export * from './settings'; +export * from './danmaku'; +export * from './fixed'; +export * from './hotkey'; +export * from './keyboard'; diff --git a/src/core/main/init/keyboard.ts b/packages/legacy-ui/src/preset/keyboard.ts similarity index 99% rename from src/core/main/init/keyboard.ts rename to packages/legacy-ui/src/preset/keyboard.ts index 6076300..c210371 100644 --- a/src/core/main/init/keyboard.ts +++ b/packages/legacy-ui/src/preset/keyboard.ts @@ -1,5 +1,5 @@ import { KeyCode } from '@motajs/client-base'; -import { Keyboard } from '../custom/keyboard'; +import { Keyboard } from '@motajs/system-action'; const qweKey = new Keyboard('qwe'); // 字母键盘,A-Z const numKey = new Keyboard('num'); // 数字键盘,1-0 @@ -239,7 +239,7 @@ numKey y: 0, width: 45, height: 45, - text: `\$
4
` + text: `$
4
` }) .add({ key: KeyCode.Digit5, diff --git a/src/core/main/init/settings.tsx b/packages/legacy-ui/src/preset/settings.tsx similarity index 95% rename from src/core/main/init/settings.tsx rename to packages/legacy-ui/src/preset/settings.tsx index 7f3298d..6351e96 100644 --- a/src/core/main/init/settings.tsx +++ b/packages/legacy-ui/src/preset/settings.tsx @@ -1,7 +1,7 @@ import type { SettingComponent, SettingComponentProps } from '../setting'; import { Button, InputNumber, Radio } from 'ant-design-vue'; import { mainUi } from './ui'; -import { gameKey } from '../custom/hotkey'; +import { gameKey } from '@motajs/system-action'; interface Components { Default: SettingComponent; @@ -28,7 +28,7 @@ export function createSettingComponents() { return com; } -function DefaultSetting(props: SettingComponentProps) { +function DefaultSetting(_props: SettingComponentProps) { return (
未知的设置类型 @@ -149,7 +149,7 @@ function showSpecialSetting(id: string, vBind?: any) { mainUi.open(id, vBind); } -function HotkeySetting(props: SettingComponentProps) { +function HotkeySetting(_props: SettingComponentProps) { return (