Skip to content

Commit df31f5f

Browse files
committed
feat: Implement PC Logic Adapter and Decision Engine
- Added PcLogicAdapter for handling PC logic input states. - Introduced RuleBasedDecisionEngine for generating action plans based on observed game states. - Created StateNormalizer to transform runtime state into ObservedState format. - Developed TftDataProvider for fetching and caching TFT data from remote sources. - Implemented services for managing PC logic execution and TFT data retrieval. - Added tests for RuleBasedDecisionEngine and TftDataProvider to ensure functionality. - Updated TypeScript configuration for improved module resolution and strict type checking.
1 parent c182140 commit df31f5f

30 files changed

Lines changed: 2182 additions & 297 deletions

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,15 @@ TFT Hextech Helper 是一款基于 Electron + React + TypeScript 开发的云顶
173173
- **图像识别**: OpenCV.js + Tesseract.js
174174
- **自动化**: nut-js (鼠标键盘控制)
175175

176+
## 迁移开发辅助(US Android / PC Logic)
177+
178+
为双端迁移新增了以下开发脚本(优先服务安卓模拟器与 PC 纯逻辑阶段):
179+
180+
- `npm run data:refresh`:拉取官方 TFT 数据(英雄/装备/羁绊/阵容)并刷新本地快照
181+
- `npm run pc:logic -- <state-json-path>`:对离线局面运行 PC 逻辑引擎,输出动作计划
182+
- `npm run test:unit`:执行迁移新增核心单元测试(决策引擎 + 数据管线)
183+
- `npm run typecheck:migration`:仅检查迁移新增模块的 TypeScript 类型
184+
176185
## 版权说明
177186

178187
本项目采用 **CC BY-NC-ND 4.0** 协议,这意味着:

electron/main.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ import {registerOverlayCallbacks} from "../src-backend/utils/OverlayBridge"; //
8787
// 为了防止在环境检查前加载原生模块导致崩溃,这些模块将在 app.whenReady 中动态导入
8888
// ============================================================================
8989
let hexService: any;
90+
let pcLogicRunner: any;
91+
let tftDataService: any;
9092
let tftOperator: any;
9193
let lineupLoader: any;
9294
let globalHotkeyManager: any;
@@ -489,6 +491,8 @@ app.whenReady().then(async () => {
489491
// 1. 加载 HexService (可能依赖 TftOperator)
490492
const ServicesModule = await import("../src-backend/services");
491493
hexService = ServicesModule.hexService;
494+
pcLogicRunner = ServicesModule.pcLogicRunner;
495+
tftDataService = ServicesModule.tftDataService;
492496

493497
// 2. 加载 TftOperator (依赖 nut.js)
494498
const TftOperatorModule = await import("../src-backend/TftOperator.ts");
@@ -538,6 +542,11 @@ app.whenReady().then(async () => {
538542
// 加载阵容配置
539543
const lineupCount = await lineupLoader.loadAllLineups()
540544
console.log(`📦 [Main] 已加载 ${lineupCount} 个阵容配置`)
545+
546+
// 预热官方 TFT 数据快照(失败时自动回落到本地快照,不阻塞启动)
547+
void tftDataService.refresh(false).catch((error: any) => {
548+
console.warn(`⚠️ [Main] TFT 数据预热失败,将使用本地快照: ${error?.message ?? error}`);
549+
});
541550

542551
// 注册挂机开关快捷键(从设置中读取)
543552
const savedHotkey = settingsStore.get('toggleHotkeyAccelerator');
@@ -703,6 +712,16 @@ function registerHandler() {
703712
}
704713
return cnToEnMap;
705714
})
715+
ipcMain.handle(IpcChannel.TFT_DATA_REFRESH, async () => {
716+
await tftDataService.refresh(true);
717+
return tftDataService.getSnapshot();
718+
})
719+
ipcMain.handle(IpcChannel.TFT_DATA_GET_SNAPSHOT, async () => {
720+
return tftDataService.getSnapshot();
721+
})
722+
ipcMain.handle(IpcChannel.PC_LOGIC_PLAN_ONCE, async (_event, state: any, context?: any) => {
723+
return pcLogicRunner.planOnce(state, context);
724+
})
706725

707726
// TFT 游戏模式相关
708727
ipcMain.handle(IpcChannel.TFT_GET_MODE, async () => settingsStore.get('tftMode'))
@@ -871,4 +890,4 @@ function registerHandler() {
871890
return { error: error.message || '检查更新失败' };
872891
}
873892
})
874-
}
893+
}

electron/protocol.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ export enum IpcChannel {
3535
LINEUP_DELETE = 'lineup-delete', // 删除玩家自建阵容
3636
// 棋子数据相关
3737
TFT_GET_CHAMPION_CN_TO_EN_MAP = 'tft-get-champion-cn-to-en-map', // 获取棋子中英文映射表
38+
TFT_DATA_REFRESH = 'tft-data-refresh', // 强制刷新官方 TFT 数据快照
39+
TFT_DATA_GET_SNAPSHOT = 'tft-data-get-snapshot', // 读取当前 TFT 数据快照
40+
PC_LOGIC_PLAN_ONCE = 'pc-logic-plan-once', // 运行一次 PC 纯逻辑决策(不执行输入)
3841
// 游戏模式相关
3942
TFT_GET_MODE = 'tft-get-mode', // 获取当前 TFT 模式(匹配/排位)
4043
TFT_SET_MODE = 'tft-set-mode', // 设置 TFT 模式
@@ -79,4 +82,4 @@ export enum IpcChannel {
7982
OVERLAY_SHOW = 'overlay-show', // 显示浮窗(传入游戏窗口坐标)
8083
OVERLAY_CLOSE = 'overlay-close', // 关闭浮窗
8184
OVERLAY_UPDATE_PLAYERS = 'overlay-update-players', // 更新玩家列表数据(主进程 -> 浮窗渲染进程)
82-
}
85+
}

0 commit comments

Comments
 (0)