Removed invalid class when valid

This commit is contained in:
Benjamin Claassen 2025-01-17 01:20:21 +01:00
parent 8e2a4d5095
commit e971684ad8
No known key found for this signature in database
GPG Key ID: C5F495EAE56673BF

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)