From 4bf84cf504158b9c789cef29cee80719f00a8c22 Mon Sep 17 00:00:00 2001 From: thepaperpilot Date: Sun, 11 Feb 2024 14:08:10 -0600 Subject: [PATCH] Minor fixes --- src/data/HexGrid.vue | 27 ++++++++++++++++++++------ src/data/hexutils.ts | 43 ++++++++++++++++++++++++++++++++++++++++++ src/data/projEntry.tsx | 12 ++++++------ 3 files changed, 70 insertions(+), 12 deletions(-) create mode 100644 src/data/hexutils.ts diff --git a/src/data/HexGrid.vue b/src/data/HexGrid.vue index 6791d5d..ea97493 100644 --- a/src/data/HexGrid.vue +++ b/src/data/HexGrid.vue @@ -4,13 +4,12 @@
-
+
-
+
@@ -111,6 +109,7 @@ function resetHoveredCell() { height: 100%; backdrop-filter: blur(3px); clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%); + background-color: var(--color); } .hexagon-overlay { @@ -138,4 +137,20 @@ function resetHoveredCell() { transform: translateY(-7.5px); } } + +.gray { + --color: rgba(64, 64, 64, 0.6); +} + +.red { + --color: rgba(255, 0, 0, 0.86); +} + +.green { + --color: rgba(0, 255, 0, 0.6); +} + +.blue { + --color: rgba(0, 0, 255, 0.6); +} diff --git a/src/data/hexutils.ts b/src/data/hexutils.ts new file mode 100644 index 0000000..9eb4497 --- /dev/null +++ b/src/data/hexutils.ts @@ -0,0 +1,43 @@ +export const hexOffsets = [ + // even rows + [ + [+1, 0], + [+1, -1], + [0, -1], + [-1, 0], + [0, +1], + [+1, +1] + ], + // odd rows + [ + [+1, 0], + [0, -1], + [-1, -1], + [-1, 0], + [-1, +1], + [0, +1] + ] +] as const; + +export function forEachNeighbor( + grid: string[][], + row: number, + col: number, + cb: (cell: string | undefined, row: number, col: number) => void +) { + const parity = row & 1; + for (let i = 0; i < 6; i++) { + const [xOffset, yOffset] = hexOffsets[parity][i]; + const neighborRow = row + yOffset; + const neighborCol = col + xOffset; + const neighborCell = grid[neighborRow]?.[neighborCol]; + cb(neighborCell, neighborRow, neighborCol); + } +} + +export function getNeighbors(grid: string[][], row: number, col: number) { + const parity = row & 1; + return hexOffsets[parity] + .map(([xOffset, yOffset]) => grid[row + yOffset]?.[col + xOffset]) + .filter(cell => cell != null); +} diff --git a/src/data/projEntry.tsx b/src/data/projEntry.tsx index 7d75a4c..9ec9487 100644 --- a/src/data/projEntry.tsx +++ b/src/data/projEntry.tsx @@ -9,10 +9,10 @@ import { persistent } from "game/persistence"; import "./main.css"; const tiles = { - gray: "rgba(64, 64, 64, 0.6)", - red: "rgba(255, 0, 0, 0.86)", - green: "rgba(0, 255, 0, 0.6)", - blue: "rgba(0, 0, 255, 0.6)" + gray: "gray", + red: "red", + green: "green", + blue: "blue" }; /** @@ -21,7 +21,7 @@ const tiles = { export const main = createLayer("main", function (this: BaseLayer) { const grid = persistent([ [tiles.gray, tiles.gray], - [tiles.gray, tiles.gray, tiles.gray], + [tiles.red, tiles.green, tiles.blue], [tiles.gray, tiles.gray] ]); return { @@ -44,7 +44,7 @@ export const main = createLayer("main", function (this: BaseLayer) { */ export const getInitialLayers = ( /* eslint-disable-next-line @typescript-eslint/no-unused-vars */ - player: Partial + player: Partial ): Array => [main]; /**