mirror of
https://github.com/motajs/template.git
synced 2026-10-18 21:00:19 +08:00
fix(07-06): #06-08-1 keep backward steps on the same axis
- Special 后退分支基准由 getCurrentDirection() 改为 this.faceDirection,避免被本步写入的反方向改写而在多步之间摆动 - 前进分支保持既有 getCurrentDirection() 语义不变 - 同步 IObjectMover.backward jsdoc 与 getCurrentDirection/prepareStep 注释措辞(D-11) - 取消 mover.test.ts 多步后退用例的 it.skip,断言一字未改(D-10)
This commit is contained in:
parent
fb5589cc02
commit
9f058650c1
@ -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);
|
||||
|
||||
|
||||
@ -307,7 +307,9 @@ export interface IObjectMover<T extends IObjectMovable> extends IHookable<
|
||||
forward(count?: number): this;
|
||||
|
||||
/**
|
||||
* 追加若干个后退步,沿当前移动方向的反方向移动
|
||||
* 追加若干个后退步,沿当前朝向的反方向后退
|
||||
*
|
||||
* 每一步都以当前朝向为基准,因此连续后退保持在同一轴线上,朝向不变
|
||||
* @param count 追加次数,默认 1
|
||||
*/
|
||||
backward(count?: number): this;
|
||||
@ -462,7 +464,10 @@ export abstract class ObjectMover<T extends IObjectMovable>
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前应当作为相对移动基准的方向
|
||||
* 获取相对移动(如前进)所使用的基准方向
|
||||
*
|
||||
* 优先取本步之前已确定的移动方向,使多步前进保持同轴;否则回退到当前朝向。
|
||||
* 后退不使用此基准,一律以当前朝向为准
|
||||
*/
|
||||
private getCurrentDirection(): FaceDirection {
|
||||
if (this.moveDirection !== FaceDirection.Unknown) {
|
||||
@ -474,6 +479,9 @@ export abstract class ObjectMover<T extends IObjectMovable>
|
||||
|
||||
/**
|
||||
* 根据步骤内容预先同步移动器内部状态
|
||||
*
|
||||
* 前进以已确定的移动方向为基准;后退固定以当前朝向为基准,
|
||||
* 从而不会因本步写入的反方向而让基准在多步之间摆动
|
||||
* @param step 当前步骤
|
||||
*/
|
||||
private prepareStep(step: Readonly<ObjectMoveStep>): void {
|
||||
@ -490,12 +498,13 @@ export abstract class ObjectMover<T extends IObjectMovable>
|
||||
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;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user