Sudoku review #1

Open
BordedDev wants to merge 19 commits from BordedDev/sudoku:main into main
Showing only changes of commit 7ebcbcff41 - Show all commits

View File

@ -310,6 +310,28 @@ class SudokuHost extends HTMLElement {
constructor() {
super()
this.#generateKeyProcessors()
}
syncCellsToSudoku() {
const puzzleGrid = this.#activePuzzle.grid
const baseGrid = this.#activePuzzle.baseState
for (let i = 0; i < SUDOKU_GRID_SIZE; i++) {
this.#cellGrid[i].innerHTML = puzzleGrid[i] ?? ""
if (baseGrid[i] != null) {
this.#cellGrid[i].classList.add("initial")
} else if (puzzleGrid[i] != null) {
if (this.#activePuzzle.isValueValidForSlot(puzzleGrid[i], i)) {
this.#cellGrid[i].classList.remove("invalid")
} else {
this.#cellGrid[i].classList.add("invalid")
}
}
}
}
#generateKeyProcessors() {
const cellValueProcessor = (event) => {
if (this.#selectedCells.size === 0) return
@ -379,22 +401,6 @@ class SudokuHost extends HTMLElement {
})
}
syncCellsToSudoku() {
const puzzleGrid = this.#activePuzzle.grid
const baseGrid = this.#activePuzzle.baseState
for (let i = 0; i < SUDOKU_GRID_SIZE; i++) {
this.#cellGrid[i].innerHTML = puzzleGrid[i] ?? ""
if (baseGrid[i] != null) {
this.#cellGrid[i].classList.add("initial")
} else if (puzzleGrid[i] != null) {
if (!this.#activePuzzle.isValueValidForSlot(puzzleGrid[i], i)) {
this.#cellGrid[i].classList.add("invalid")
}
}
}
}
#selectCell(i, cell) {
if (this.hasAttribute("readonly") || !this.isActive) return
this.#selectedCells.set(i, cell)