diff --git a/src/components/Bar.tsx b/src/components/Bar.tsx
new file mode 100644
index 0000000..8f11156
--- /dev/null
+++ b/src/components/Bar.tsx
@@ -0,0 +1,40 @@
+import { useDimensions, useGameState, useTheme } from "../providers";
+import { Checker } from "./Checker";
+import { PipCounter } from "./PipCounter";
+
+export const Bar = () => {
+ const dimensions = useDimensions();
+ const colours = useTheme();
+ const gameState = useGameState();
+
+ const { barWidth, panelWidth, borderWidth, boardHeight } = dimensions;
+ const barPositions = (gameState?.positions ?? []).filter(
+ (p) => p.position === "bar",
+ );
+
+ return (
+ <>
+
+ {barPositions.map(({ playerType, numberOfCheckers = 1 }) =>
+ [...new Array(numberOfCheckers)].map((_, i) => (
+
+ )),
+ )}
+
+
+ >
+ );
+};
diff --git a/src/components/Board.tsx b/src/components/Board.tsx
index 6b45f33..4d8806c 100644
--- a/src/components/Board.tsx
+++ b/src/components/Board.tsx
@@ -3,8 +3,8 @@ import { useDimensions, useGameState, useTheme } from "../providers";
import { Checker } from "./Checker";
import { Point } from "./Point";
import { Sidebar } from "./Sidebar";
-import { PipCounter } from "./PipCounter";
import { Dice } from "./Dice";
+import { Bar } from "./Bar";
export const Board: React.FC = () => {
const dimensions = useDimensions();
@@ -15,7 +15,6 @@ export const Board: React.FC = () => {
const {
boardWidth,
barWidth,
- panelWidth,
borderWidth,
pointWidth,
boardHeight,
@@ -154,7 +153,8 @@ export const Board: React.FC = () => {
{positions &&
positions.map(({ position, numberOfCheckers = 1, playerType }) => {
const checkers = [...new Array(numberOfCheckers)].map((_, i) => {
- if (position === 0 || position === 25) return null;
+ if (position === 0 || position === 25 || position === "bar")
+ return null;
return (
{
);
})}
{/* Middle bar */}
-
-
-
+
diff --git a/src/components/Checker.tsx b/src/components/Checker.tsx
index 6c15ff2..f468686 100644
--- a/src/components/Checker.tsx
+++ b/src/components/Checker.tsx
@@ -2,7 +2,33 @@ import { useDimensions, usePosition, useTheme } from "../providers";
import { PlayerType } from "../types";
type CheckerProps = {
- x: number;
+ x:
+ | 0
+ | 1
+ | 2
+ | 3
+ | 4
+ | 5
+ | 6
+ | 7
+ | 8
+ | 9
+ | 10
+ | 11
+ | 12
+ | 13
+ | 14
+ | 15
+ | 16
+ | 17
+ | 18
+ | 19
+ | 20
+ | 21
+ | 22
+ | 23
+ | 24
+ | "bar";
y: number;
playerType: PlayerType;
totalOnPoint: number;
@@ -28,10 +54,14 @@ export const Checker: React.FC = ({
: opponentCheckerBorderColor;
const pos = usePosition();
const { checkerWidth, checkerStroke } = useDimensions();
- const bottomModifier = x > 12 ? 1 : -1;
+ const bottomModifier =
+ x === "bar" ? (playerType === "opponent" ? 1 : -1) : x > 12 ? 1 : -1;
const baseYOffset = checkerWidth * bottomModifier;
+ const barInitialOffset =
+ x === "bar" ? (checkerWidth / 1.8) * bottomModifier : 0;
const yOffset =
+ barInitialOffset +
(y - 1) * baseYOffset * (totalOnPoint > 5 ? 4 / (totalOnPoint - 1) : 1);
return (
= ({ value = 2, colorSchema }) => {
);
break;
}
- console.log(value);
return (
= ({ playerType }) => {
const pip = positions?.reduce((acc, current) => {
const isPlayer = current.playerType === playerType;
const normalisedPosition =
- current.playerType === "player"
- ? current.position
- : 25 - current.position;
+ current.position === "bar"
+ ? 25
+ : current.playerType === "player"
+ ? current.position
+ : 25 - current.position;
return isPlayer ? acc + current.numberOfCheckers * normalisedPosition : acc;
}, 0);
diff --git a/src/components/Point.tsx b/src/components/Point.tsx
index 08dd1e8..aa7e4d4 100644
--- a/src/components/Point.tsx
+++ b/src/components/Point.tsx
@@ -17,7 +17,7 @@ export const Point: React.FC = ({
}) => {
const { pointWidth, pointHeight, borderWidth } = useDimensions();
- const { pointNumberColor, pointColor } = useTheme();
+ const { pointNumberColor, pointColor, altPointColor } = useTheme();
const transform = bottom ? `scale(1 -1) translate(0, ${borderWidth})` : "";
@@ -38,7 +38,7 @@ export const Point: React.FC = ({
;
diff --git a/src/helpers/calculate-base-points.ts b/src/helpers/calculate-base-points.ts
index 37e81e0..ba20f09 100644
--- a/src/helpers/calculate-base-points.ts
+++ b/src/helpers/calculate-base-points.ts
@@ -10,8 +10,13 @@ export const calculateBasePoints = (
checkerWidth,
boardHeight,
checkerStroke,
+ boardWidth,
} = dimensions;
return {
+ bar: {
+ x: boardWidth / 2,
+ y: boardHeight / 2,
+ },
24: {
x: borderWidth + pointWidth / 2,
y: borderWidth + checkerWidth / 2 + checkerStroke,
diff --git a/src/helpers/presets.ts b/src/helpers/presets.ts
index 0523f9a..b3007c5 100644
--- a/src/helpers/presets.ts
+++ b/src/helpers/presets.ts
@@ -4,7 +4,7 @@ export const presets = {
borderColor: "#ff7f50",
pointColor: "#008080",
pointNumberColor: "#000",
- altPointColor: "#ffd700",
+ altPointColor: "#00d4d4",
playerCheckerColor: "#fff",
playerCheckerBorderColor: "#000",
opponentCheckerColor: "#000",
diff --git a/src/providers/PositionProvider.tsx b/src/providers/PositionProvider.tsx
index d545128..01d1dcb 100644
--- a/src/providers/PositionProvider.tsx
+++ b/src/providers/PositionProvider.tsx
@@ -2,9 +2,9 @@ import React, { createContext, useContext } from "react";
import { calculateBasePoints } from "../helpers/calculate-base-points";
import { useDimensions } from "./DimensionProvider";
-const PositionContext = createContext>(
- {},
-);
+const PositionContext = createContext<
+ Record
+>({ bar: { x: 0, y: 0 } });
export const usePosition = () => useContext(PositionContext);
diff --git a/src/types.ts b/src/types.ts
index bda1ccb..a4b8ee7 100644
--- a/src/types.ts
+++ b/src/types.ts
@@ -32,7 +32,8 @@ type Position = {
| 22
| 23
| 24
- | 25;
+ | 25
+ | "bar";
numberOfCheckers:
| 1
| 2
diff --git a/test-harness/tests/__screenshots__/tests.spec.ts/chromium/overload-1.png b/test-harness/tests/__screenshots__/tests.spec.ts/chromium/overload-1.png
index 163f844..4e7419d 100644
Binary files a/test-harness/tests/__screenshots__/tests.spec.ts/chromium/overload-1.png and b/test-harness/tests/__screenshots__/tests.spec.ts/chromium/overload-1.png differ
diff --git a/test-harness/tests/__screenshots__/tests.spec.ts/firefox/overload-1.png b/test-harness/tests/__screenshots__/tests.spec.ts/firefox/overload-1.png
index 5927b16..b6161d4 100644
Binary files a/test-harness/tests/__screenshots__/tests.spec.ts/firefox/overload-1.png and b/test-harness/tests/__screenshots__/tests.spec.ts/firefox/overload-1.png differ
diff --git a/test-harness/tests/__screenshots__/tests.spec.ts/mobile-chrome/overload-1.png b/test-harness/tests/__screenshots__/tests.spec.ts/mobile-chrome/overload-1.png
index db2690b..d19ad78 100644
Binary files a/test-harness/tests/__screenshots__/tests.spec.ts/mobile-chrome/overload-1.png and b/test-harness/tests/__screenshots__/tests.spec.ts/mobile-chrome/overload-1.png differ
diff --git a/test-harness/tests/__screenshots__/tests.spec.ts/mobile-safari/overload-1.png b/test-harness/tests/__screenshots__/tests.spec.ts/mobile-safari/overload-1.png
index 9fd58d1..f9198e7 100644
Binary files a/test-harness/tests/__screenshots__/tests.spec.ts/mobile-safari/overload-1.png and b/test-harness/tests/__screenshots__/tests.spec.ts/mobile-safari/overload-1.png differ
diff --git a/test-harness/tests/__screenshots__/tests.spec.ts/webkit/overload-1.png b/test-harness/tests/__screenshots__/tests.spec.ts/webkit/overload-1.png
index e2c587d..9d21dd8 100644
Binary files a/test-harness/tests/__screenshots__/tests.spec.ts/webkit/overload-1.png and b/test-harness/tests/__screenshots__/tests.spec.ts/webkit/overload-1.png differ
diff --git a/test-harness/tests/presets.ts b/test-harness/tests/presets.ts
index 739ca79..a0ee1a5 100644
--- a/test-harness/tests/presets.ts
+++ b/test-harness/tests/presets.ts
@@ -89,6 +89,8 @@ export const positionsPresets: Record = {
{ position: 23, playerType: "opponent", numberOfCheckers: 15 },
{ position: 24, playerType: "opponent", numberOfCheckers: 15 },
{ position: 25, playerType: "opponent", numberOfCheckers: 15 },
+ { position: "bar", playerType: "opponent", numberOfCheckers: 15 },
+ { position: "bar", playerType: "player", numberOfCheckers: 15 },
],
random: randomPositions(),
};