diff options
author | eug-vs <eugene@eug-vs.xyz> | 2022-03-13 13:57:40 +0300 |
---|---|---|
committer | eug-vs <eugene@eug-vs.xyz> | 2022-03-13 13:57:40 +0300 |
commit | 1d6519f9f97e1d6d4046e2caf21b81dfe277992d (patch) | |
tree | 2cf88899cd87efd4045eb0dbbd00c00b669de9f9 /src/Tile/TileOnBoard.ts | |
parent | f74f6478a16564cf48b55ae2968fe44740eb92ab (diff) | |
download | carcassonne-engine-ts-1d6519f9f97e1d6d4046e2caf21b81dfe277992d.tar.gz |
feat: only use clockwise turns for orientation
Diffstat (limited to 'src/Tile/TileOnBoard.ts')
-rw-r--r-- | src/Tile/TileOnBoard.ts | 14 |
1 files changed, 6 insertions, 8 deletions
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 })) |