From 9f058650c157ada9a3e672b3d6903642267ea494 Mon Sep 17 00:00:00 2001 From: unanmed <1319491857@qq.com> Date: Tue, 15 Sep 2026 20:57:13 +0800 Subject: [PATCH] fix(07-06): #06-08-1 keep backward steps on the same axis MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Special 后退分支基准由 getCurrentDirection() 改为 this.faceDirection,避免被本步写入的反方向改写而在多步之间摆动 - 前进分支保持既有 getCurrentDirection() 语义不变 - 同步 IObjectMover.backward jsdoc 与 getCurrentDirection/prepareStep 注释措辞(D-11) - 取消 mover.test.ts 多步后退用例的 it.skip,断言一字未改(D-10) --- .../data-common/src/common/mover.test.ts | 4 ++-- packages-user/data-common/src/common/mover.ts | 19 ++++++++++++++----- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/packages-user/data-common/src/common/mover.test.ts b/packages-user/data-common/src/common/mover.test.ts index 1c7f07b..491ab11 100644 --- a/packages-user/data-common/src/common/mover.test.ts +++ b/packages-user/data-common/src/common/mover.test.ts @@ -303,8 +303,8 @@ describe('object mover public surface', () => { expect(mover.moveDirection).toBe(FaceDirection.Up); }); - // 疑似 bug:连续后退时上一步会把移动方向翻转为反方向,导致方向来回摆动,详见 06-TEST-FINDINGS.md #06-08-1,修复后取消 skip - it.skip('keeps retreating along the same axis across multiple backward steps', async () => { + // 验证连续后退每一步都以当前朝向为基准,保持同轴后退且朝向不变(#06-08-1) + it('keeps retreating along the same axis across multiple backward steps', async () => { const tile = new TestTile(); const mover = createMover(tile); diff --git a/packages-user/data-common/src/common/mover.ts b/packages-user/data-common/src/common/mover.ts index 43a0ad8..23b2264 100644 --- a/packages-user/data-common/src/common/mover.ts +++ b/packages-user/data-common/src/common/mover.ts @@ -307,7 +307,9 @@ export interface IObjectMover extends IHookable< forward(count?: number): this; /** - * 追加若干个后退步,沿当前移动方向的反方向移动 + * 追加若干个后退步,沿当前朝向的反方向后退 + * + * 每一步都以当前朝向为基准,因此连续后退保持在同一轴线上,朝向不变 * @param count 追加次数,默认 1 */ backward(count?: number): this; @@ -462,7 +464,10 @@ export abstract class ObjectMover } /** - * 获取当前应当作为相对移动基准的方向 + * 获取相对移动(如前进)所使用的基准方向 + * + * 优先取本步之前已确定的移动方向,使多步前进保持同轴;否则回退到当前朝向。 + * 后退不使用此基准,一律以当前朝向为准 */ private getCurrentDirection(): FaceDirection { if (this.moveDirection !== FaceDirection.Unknown) { @@ -474,6 +479,9 @@ export abstract class ObjectMover /** * 根据步骤内容预先同步移动器内部状态 + * + * 前进以已确定的移动方向为基准;后退固定以当前朝向为基准, + * 从而不会因本步写入的反方向而让基准在多步之间摆动 * @param step 当前步骤 */ private prepareStep(step: Readonly): void { @@ -490,12 +498,13 @@ export abstract class ObjectMover this.faceDirection = step.value; break; case ObjectMoveType.Special: { - const dir = this.getCurrentDirection(); if (step.direction === ObjectSpecialStep.Backward) { - const opposite = this.faceHandler.opposite(dir); - this.moveDirection = opposite; + // 后退基准固定为当前朝向,避免被本步写入的反方向改写后摆动 + const dir = this.faceDirection; + this.moveDirection = this.faceHandler.opposite(dir); this.faceDirection = dir; } else { + const dir = this.getCurrentDirection(); this.moveDirection = dir; this.faceDirection = dir; }