1
0
mirror of https://github.com/thib8956/tic-tac-toe-ws.git synced 2025-02-22 16:58:14 +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 { interface Shape {
kind: "o" | "x"; kind: "o" | "x";
pos: Point;
hue: number; hue: number;
time: number | null; time: number | null;
} }
@ -135,7 +134,7 @@ function updateGridState(ctx: CanvasRenderingContext2D, time: number, gridOrigin
shape.time = time; shape.time = time;
} }
const p = gridIndexToCoords(gridOrigin, shape.pos.x, shape.pos.y); const p = gridIndexToCoords(gridOrigin, x, y);
const dt = time - shape.time; const dt = time - shape.time;
switch (shape.kind) { switch (shape.kind) {
@ -214,7 +213,6 @@ function init() {
if (sym === undefined) continue; if (sym === undefined) continue;
grid[index] = { grid[index] = {
kind: sym, kind: sym,
pos: { x: index % 3, y: Math.floor(index / 3) } as Point,
hue: Math.floor(Math.random() * 255), hue: Math.floor(Math.random() * 255),
time: null, time: null,
} as Shape; } as Shape;
@ -226,7 +224,6 @@ function init() {
const { x, y } = res.last; const { x, y } = res.last;
const shape: Shape = { const shape: Shape = {
kind: res.last.symbol, kind: res.last.symbol,
pos: { x, y },
hue: Math.floor(Math.random() * 255), hue: Math.floor(Math.random() * 255),
time: null, time: null,
}; };