Minor fixes
Some checks failed
Build and Deploy / build-and-deploy (push) Successful in 48s
Run Tests / test (push) Failing after 1m53s

This commit is contained in:
thepaperpilot 2024-02-11 14:08:10 -06:00
parent 3e4eaa8c18
commit 4bf84cf504
3 changed files with 70 additions and 12 deletions

View file

@ -4,13 +4,12 @@
<div <div
v-for="(color, colIndex) in row" v-for="(color, colIndex) in row"
:key="`${rowIndex}-${colIndex}-${color}`" :key="`${rowIndex}-${colIndex}-${color}`"
class="hexagon-wrapper" :class="{ 'hexagon-wrapper': true, [color]: true }"
:style="{ '--color': color }"
@click="updateColor(rowIndex, colIndex)" @click="updateColor(rowIndex, colIndex)"
@mouseover="setHoveredCell(rowIndex, colIndex)" @mouseover="setHoveredCell(rowIndex, colIndex)"
@mouseout="resetHoveredCell" @mouseout="resetHoveredCell"
> >
<div class="hexagon" :style="{ backgroundColor: color }"></div> <div class="hexagon"></div>
<transition name="fade"> <transition name="fade">
<div <div
v-if=" v-if="
@ -18,10 +17,9 @@
hoveredCell?.col === colIndex && hoveredCell?.col === colIndex &&
color !== selectedColor color !== selectedColor
" "
class="hexagon-overlay" :class="{ 'hexagon-overlay': true, [selectedColor]: true }"
:style="{ '--color': selectedColor }"
> >
<div class="hexagon" :style="{ backgroundColor: selectedColor }"></div> <div class="hexagon"></div>
</div> </div>
</transition> </transition>
</div> </div>
@ -111,6 +109,7 @@ function resetHoveredCell() {
height: 100%; height: 100%;
backdrop-filter: blur(3px); backdrop-filter: blur(3px);
clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%); clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
background-color: var(--color);
} }
.hexagon-overlay { .hexagon-overlay {
@ -138,4 +137,20 @@ function resetHoveredCell() {
transform: translateY(-7.5px); 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);
}
</style> </style>

43
src/data/hexutils.ts Normal file
View file

@ -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);
}

View file

@ -9,10 +9,10 @@ import { persistent } from "game/persistence";
import "./main.css"; import "./main.css";
const tiles = { const tiles = {
gray: "rgba(64, 64, 64, 0.6)", gray: "gray",
red: "rgba(255, 0, 0, 0.86)", red: "red",
green: "rgba(0, 255, 0, 0.6)", green: "green",
blue: "rgba(0, 0, 255, 0.6)" blue: "blue"
}; };
/** /**
@ -21,7 +21,7 @@ const tiles = {
export const main = createLayer("main", function (this: BaseLayer) { export const main = createLayer("main", function (this: BaseLayer) {
const grid = persistent([ const grid = persistent([
[tiles.gray, tiles.gray], [tiles.gray, tiles.gray],
[tiles.gray, tiles.gray, tiles.gray], [tiles.red, tiles.green, tiles.blue],
[tiles.gray, tiles.gray] [tiles.gray, tiles.gray]
]); ]);
return { return {
@ -44,7 +44,7 @@ export const main = createLayer("main", function (this: BaseLayer) {
*/ */
export const getInitialLayers = ( export const getInitialLayers = (
/* eslint-disable-next-line @typescript-eslint/no-unused-vars */ /* eslint-disable-next-line @typescript-eslint/no-unused-vars */
player: Partial<PlayerData> player: Partial<Player>
): Array<GenericLayer> => [main]; ): Array<GenericLayer> => [main];
/** /**