1
0
mirror of https://github.com/thib8956/tic-tac-toe-ws.git synced 2025-02-22 00:38:16 +00:00

refactor: remove pos from shape, only use the grid index

This commit is contained in:
Thibaud Gasser 2025-01-30 09:50:34 +01:00
parent 2aea53ce63
commit f35a75b593

View File

@ -22,7 +22,6 @@ type Cell = Empty | Shape;
interface Shape {
kind: "o" | "x";
pos: Point;
hue: number;
time: number | null;
}
@ -135,7 +134,7 @@ function updateGridState(ctx: CanvasRenderingContext2D, time: number, gridOrigin
shape.time = time;
}
const p = gridIndexToCoords(gridOrigin, shape.pos.x, shape.pos.y);
const p = gridIndexToCoords(gridOrigin, x, y);
const dt = time - shape.time;
switch (shape.kind) {
@ -214,7 +213,6 @@ function init() {
if (sym === undefined) continue;
grid[index] = {
kind: sym,
pos: { x: index % 3, y: Math.floor(index / 3) } as Point,
hue: Math.floor(Math.random() * 255),
time: null,
} as Shape;
@ -226,7 +224,6 @@ function init() {
const { x, y } = res.last;
const shape: Shape = {
kind: res.last.symbol,
pos: { x, y },
hue: Math.floor(Math.random() * 255),
time: null,
};