From 1d6519f9f97e1d6d4046e2caf21b81dfe277992d Mon Sep 17 00:00:00 2001 From: eug-vs Date: Sun, 13 Mar 2022 13:57:40 +0300 Subject: feat: only use clockwise turns for orientation --- src/Tile/TileOnBoard.ts | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'src/Tile/TileOnBoard.ts') diff --git a/src/Tile/TileOnBoard.ts b/src/Tile/TileOnBoard.ts index bc1e66d..0fa8005 100644 --- a/src/Tile/TileOnBoard.ts +++ b/src/Tile/TileOnBoard.ts @@ -9,7 +9,7 @@ export interface Attachment { } export default class TileOnBoard extends Tile { - orientation: number; // amount of 90-degree counter-clockwise rotations from original orientation + orientation: number; // amount of 90-degree clockwise rotations from original orientation position: { x: number; y: number; @@ -28,23 +28,21 @@ export default class TileOnBoard extends Tile { } getSide(direction: Direction) { - return super.getSide(direction + this.orientation); + return super.getSide(direction - this.orientation); } rotate(rotation = 1) { - // We want to rotate clockwise, but orientation stores counter-clockwise rotations, - // therefore use the difference, not sum. - this.orientation = this.orientation - rotation; + this.orientation += rotation; } getAttachments(tile: Tile): Attachment[] { return _.flatten([0, 1, 2, 3].map(side => { const item = this.getSide(side); return [0, 1, 2, 3] - .filter(rotation => tile.getSide(side - rotation + 2) === item) - .map(rotation => ({ + .filter(orientation => tile.getSide(side - orientation + 2) === item) + .map(orientation => ({ tile, - rotation, + orientation, side, attachTo: this as Tile })) -- cgit v1.2.3