From 1d6519f9f97e1d6d4046e2caf21b81dfe277992d Mon Sep 17 00:00:00 2001
From: eug-vs <eugene@eug-vs.xyz>
Date: Sun, 13 Mar 2022 13:57:40 +0300
Subject: feat: only use clockwise turns for orientation

---
 src/Tile/TileOnBoard.test.ts | 11 ++++-------
 src/Tile/TileOnBoard.ts      | 14 ++++++--------
 2 files changed, 10 insertions(+), 15 deletions(-)

(limited to 'src/Tile')

diff --git a/src/Tile/TileOnBoard.test.ts b/src/Tile/TileOnBoard.test.ts
index 70fc5a1..de2685d 100644
--- a/src/Tile/TileOnBoard.test.ts
+++ b/src/Tile/TileOnBoard.test.ts
@@ -42,15 +42,12 @@ describe('TileOnBoard', () => {
       const attachTo = new TileOnBoard(Town, [Road, Town, Town, Road])
       const tile = new TileOnBoard(Road, [Grass, Road, Road, Grass])
 
-      tile.print();
-      attachTo.print();
-
       const attachments = attachTo.getAttachments(tile);
       assert.strictEqual(attachments.length, 4);
-      assert.deepStrictEqual(attachments[0], { side: 0, rotation: 0, tile, attachTo });
-      assert.deepStrictEqual(attachments[1], { side: 0, rotation: 1, tile, attachTo });
-      assert.deepStrictEqual(attachments[2], { side: 3, rotation: 0, tile, attachTo });
-      assert.deepStrictEqual(attachments[3], { side: 3, rotation: 3, tile, attachTo });
+      assert.deepStrictEqual(attachments[0], { side: 0, orientation: 0, tile, attachTo });
+      assert.deepStrictEqual(attachments[1], { side: 0, orientation: 1, tile, attachTo });
+      assert.deepStrictEqual(attachments[2], { side: 3, orientation: 0, tile, attachTo });
+      assert.deepStrictEqual(attachments[3], { side: 3, orientation: 3, tile, attachTo });
     });
   });
 });
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