|
|
|
@ -10,10 +10,10 @@ import { |
|
|
|
|
getSlotTemplateNames, |
|
|
|
|
} from "../../shared/display.ts"; |
|
|
|
|
import { GameVariantName, gamesRules } from "../../shared/game-variants/index.ts"; |
|
|
|
|
import { ensureColumnsNumber, ensureRowsNumber, ensureSlotTemplate } from "../utils/dom-utils.ts"; |
|
|
|
|
import { replaceLocation } from "../utils/navigation-utils.ts"; |
|
|
|
|
import { TrackingTools } from "../utils/query-tracking-utils.ts"; |
|
|
|
|
import { updateWithQueryParams } from "../utils/url-utils.ts"; |
|
|
|
|
import { ensureColumnsNumber, ensureRowsNumber, ensureSlotTemplate } from "../utils/dom-utils.ts"; |
|
|
|
|
|
|
|
|
|
class BoardGameComponent extends HTMLElement { |
|
|
|
|
private readonly trackingTools = new TrackingTools(this); |
|
|
|
@ -63,19 +63,12 @@ class BoardGameComponent extends HTMLElement { |
|
|
|
|
for (let rowNumber = 0; rowNumber < tbody.rows.length; rowNumber++) { |
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- should not be empty by the definition of rowNumber
|
|
|
|
|
const row = tbody.rows[rowNumber]!; |
|
|
|
|
|
|
|
|
|
ensureColumnsNumber(row, gameState.columns); |
|
|
|
|
|
|
|
|
|
for (let columnNumber = 0; columnNumber < row.cells.length; columnNumber++) { |
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- should not be empty by the definition of columnNumber
|
|
|
|
|
const cell = row.cells[columnNumber]!; |
|
|
|
|
|
|
|
|
|
if (!cell.childNodes.length) { |
|
|
|
|
const button = document.createElement("button"); |
|
|
|
|
button.type = "submit"; |
|
|
|
|
button.name = key; |
|
|
|
|
cell.append(button); |
|
|
|
|
} |
|
|
|
|
ensureSlotTemplate(cell, "game-cell", () => this.querySelector(`template[name="game-cell"]`)); |
|
|
|
|
|
|
|
|
|
const { isDisabled, nextGameState, text, className } = getCellDisplayData({ |
|
|
|
|
gameState, |
|
|
|
@ -85,15 +78,9 @@ class BoardGameComponent extends HTMLElement { |
|
|
|
|
}); |
|
|
|
|
cell.querySelectorAll("button").forEach((button) => { |
|
|
|
|
button.value = nextGameState.serialize(); |
|
|
|
|
if (button.disabled !== isDisabled) { |
|
|
|
|
button.disabled = isDisabled; |
|
|
|
|
} |
|
|
|
|
if (button.innerText !== text) { |
|
|
|
|
button.innerText = text; |
|
|
|
|
} |
|
|
|
|
if (button.className !== className) { |
|
|
|
|
button.className = className; |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|