From e199d99d19e67182fd29ec4b24ea91eca39658c9 Mon Sep 17 00:00:00 2001 From: unanmed <1319491857@qq.com> Date: Wed, 9 Sep 2026 17:32:28 +0800 Subject: [PATCH] refactor(02-02): declare graph builder and test mover interfaces per updated class rule --- packages-user/data-system/src/path/graph.ts | 59 ++++++++++++------- .../data-system/src/path/system.test.ts | 5 +- 2 files changed, 41 insertions(+), 23 deletions(-) diff --git a/packages-user/data-system/src/path/graph.ts b/packages-user/data-system/src/path/graph.ts index 955f486..ed5021c 100644 --- a/packages-user/data-system/src/path/graph.ts +++ b/packages-user/data-system/src/path/graph.ts @@ -73,12 +73,48 @@ function directionOf(x: number, y: number): FaceDirection { //#region 有向图构建 +/** + * 寻路有向图构建器接口,声明图构建的绑定槽位与构建入口 + */ +export interface IPathfindingGraphBuilder { + /** + * 绑定地图状态对象,用于解析图层所属楼层 id + * @param maps 地图状态对象,传入 `null` 解绑 + */ + useMapState(maps: IMapState | null): void; + + /** + * 绑定构建有向图所用的地图图层 + * @param layer 地图图层对象,传入 `null` 解绑 + */ + useMapLayer(layer: IMapLayer | null): void; + + /** + * 注入判定边可行性的通行性谓词 + * @param predicate 通行性谓词,传入 `null` 解绑 + */ + usePassPredicate(predicate: IPassPredicate | null): void; + + /** + * 设置邻域使用的方向组 + * @param group 朝向组 + */ + useDirGroup(group: number): void; + + /** + * 构建有向图。图层未绑定时告警并返回空图, + * 不包含任何节点与边 + * @returns 构建的有向图 + */ + build(): IPathGraph; +} + /** * 寻路有向图构建器,将地图图层转换为以通行性谓词判定边的有向图。 * 邻域方向由注入的方向组决定,默认仅包含四正交方向; * 谓词未注入时所有边均不可通行 */ -export class PathfindingGraphBuilder { +export class PathfindingGraphBuilder implements IPathfindingGraphBuilder { /** 绑定的地图状态对象,用于解析图层所属楼层 id */ private maps: IMapState | null = null; /** 绑定的地图图层,图节点来源 */ @@ -91,43 +127,22 @@ export class PathfindingGraphBuilder { /** 方向组解析对象 */ private readonly mapper: IDirectionMapper = new DirectionMapper(); - /** - * 绑定地图状态对象,用于解析楼层 id - * @param maps 地图状态对象,传入 `null` 解绑 - */ useMapState(maps: IMapState | null): void { this.maps = maps; } - /** - * 绑定构建有向图所用的地图图层 - * @param layer 地图图层对象,传入 `null` 解绑 - */ useMapLayer(layer: IMapLayer | null): void { this.layer = layer; } - /** - * 注入判定边可行性的通行性谓词 - * @param predicate 通行性谓词,传入 `null` 解绑 - */ usePassPredicate(predicate: IPassPredicate | null): void { this.predicate = predicate; } - /** - * 设置邻域使用的方向组 - * @param group 朝向组 - */ useDirGroup(group: number): void { this.group = group; } - /** - * 构建有向图。图层未绑定时告警并返回空图, - * 不包含任何节点与边 - * @returns 构建的有向图 - */ build(): IPathGraph { const layer = this.layer; if (isNil(layer)) { diff --git a/packages-user/data-system/src/path/system.test.ts b/packages-user/data-system/src/path/system.test.ts index ae1f643..ae86d33 100644 --- a/packages-user/data-system/src/path/system.test.ts +++ b/packages-user/data-system/src/path/system.test.ts @@ -218,7 +218,10 @@ interface SystemFixture { * 创建测试用移动对象,移动器由工厂注入 */ function createTestTile(): TestTile { - class TestMover extends modules.ObjectMover { + class TestMover + extends modules.ObjectMover + implements IObjectMover + { readonly tile: TestTile; constructor(tile: TestTile) {