show same value even when highlight disabled

This commit is contained in:
Adrien MALINGREY 2020-11-16 03:45:37 +01:00
parent 5836f53a24
commit cd22ded40e
4 changed files with 36 additions and 54 deletions

View File

@ -83,20 +83,6 @@
array_unset_value($box->value, $neighbour->candidates); array_unset_value($box->value, $neighbour->candidates);
} }
} }
function containsDuplicates() {
foreach(array_merge($this->rows, $this->columns, $this->regions) as $area) {
$knownBoxes = array_filter($area, "isKnown");
foreach($knownBoxes as $box1) {
foreach($knownBoxes as $box2) {
if (($box1 != $box2) && ($box1->value == $box2->value)) {
return true;
}
}
}
}
return false;
}
function generate() { function generate() {
// Init with a shuffle row // Init with a shuffle row
@ -139,10 +125,22 @@
} }
} }
} }
function containsDuplicates() {
foreach(array_merge($this->rows, $this->columns, $this->regions) as $area) {
$knownBoxes = array_filter($area, "isKnown");
foreach($knownBoxes as $box1) {
foreach($knownBoxes as $box2) {
if (($box1 != $box2) && ($box1->value == $box2->value)) {
return true;
}
}
}
}
return false;
}
function countSolutions($max=2) { function countSolutions($max=2) {
if ($this->containsDuplicates())
return 0;
$solutions = $this->solutionsGenerator(false); $solutions = $this->solutionsGenerator(false);
$solutionsWithoutDuplicates = array(); $solutionsWithoutDuplicates = array();
$nbSolutions = 0; $nbSolutions = 0;

View File

@ -112,16 +112,16 @@ input[type="number"]::-webkit-calendar-picker-indicator {
.grid input:disabled { .grid input:disabled {
color: white; color: white;
background: #6666ff; background: #6666ff;
}
.grid input:disabled,
.grid input.forbidden {
cursor: not-allowed !important; cursor: not-allowed !important;
} }
.grid input:disabled,
.grid input.forbidden:enabled { .grid input.forbidden:enabled {
background: #ffffaa; background: #ffffaa;
cursor: not-allowed !important;
} }
.grid input.same-value:enabled { .grid input.same-value:enabled {
background: #ffff33; background: #ffff33;
cursor: not-allowed !important;
} }
.grid input.forbidden:disabled { .grid input.forbidden:disabled {
color: #ffffaa; color: #ffffaa;

View File

@ -114,9 +114,8 @@ function onclick() {
if (this.value == "" && this.candidates.size == 1) { if (this.value == "" && this.candidates.size == 1) {
valueToInsert = this.candidates.values().next().value valueToInsert = this.candidates.values().next().value
document.getElementById("insertRadio" + valueToInsert).checked = true document.getElementById("insertRadio" + valueToInsert).checked = true
this.value = valueToInsert }
this.oninput() if (inkPenRadio.checked) {
} else if (inkPenRadio.checked) {
if (valueToInsert) { if (valueToInsert) {
this.value = valueToInsert this.value = valueToInsert
this.oninput() this.oninput()
@ -216,41 +215,26 @@ function refreshUI() {
} }
function highlight() { function highlight() {
if (valueToInsert) { boxes.forEach(box => {
if (highlighterCheckbox.checked) { if (valueToInsert && box.value == valueToInsert) {
boxes.forEach(box => { box.classList.add("same-value")
if (box.value == valueToInsert) { box.tabIndex = -1
box.classList.add("same-value")
box.tabIndex = -1
}
else {
box.classList.remove("same-value")
if (box.candidates.has(valueToInsert) && !box.disabled) {
box.classList.remove("forbidden")
box.tabIndex = 0
} else {
box.classList.add("forbidden")
box.tabIndex = -1
}
}
})
} else { } else {
boxes.forEach(box => { box.classList.remove("same-value")
box.classList.remove("same-value") if (box.disabled) {
if (box.disabled) { box.classList.add("forbidden")
} else {
if (valueToInsert && highlighterCheckbox.checked && !box.candidates.has(valueToInsert)) {
box.classList.add("forbidden") box.classList.add("forbidden")
box.tabIndex = -1
} else { } else {
box.classList.remove("forbidden") box.classList.remove("forbidden")
box.tabIndex = 0
} }
box.tabIndex = 0 }
})
} }
} else { })
boxes.forEach(box => { highlighterCheckbox.nextElementSibling.title = "Surligner les lignes, colonnes et régions contenant déjà " + (valueToInsert? "un " + valueToInsert: "le chiffre sélectionné")
box.classList.remove("same-value", "forbidden")
box.tabIndex = 0
})
}
} }
function onblur() { function onblur() {

View File

@ -97,11 +97,11 @@
</div> </div>
<div> <div>
<input id='highlighterCheckbox' type="checkbox" onclick='highlight()'/> <input id='highlighterCheckbox' type="checkbox" onclick='highlight()'/>
<label for='highlighterCheckbox' title='Surligner les cases interdites'><img src='img/highlighter.svg' alt='Surligneur'></label> <label for='highlighterCheckbox' title='Surligner les lignes, colonnes et régions contenant déjà le chiffre sélectionné'><img src='img/highlighter.svg' alt='Surligneur'></label>
<input type='radio' id='inkPenRadio' name='tool' onclick='grid.style.cursor = "url(img/ink-pen.svg) 2 22, auto"' checked/> <input type='radio' id='inkPenRadio' name='tool' onclick='grid.style.cursor = "url(img/ink-pen.svg) 2 22, auto"' checked/>
<label for='inkPenRadio' title='Écrire au stylo'><img src='img/ink-pen.svg' alt='Stylo indélébile'/></label> <label for='inkPenRadio' title='Écrire un chiffre'><img src='img/ink-pen.svg' alt='Stylo indélébile'/></label>
<input type='radio' id='pencilRadio' name='tool' onclick='grid.style.cursor = "url(img/pencil.svg) 2 22, auto"'/> <input type='radio' id='pencilRadio' name='tool' onclick='grid.style.cursor = "url(img/pencil.svg) 2 22, auto"'/>
<label for='pencilRadio' title='Écrire au crayon'><img src='img/pencil.svg' alt='Crayon'/></label> <label for='pencilRadio' title='Prendre des notes'><img src='img/pencil.svg' alt='Crayon'/></label>
<input type='radio' id='eraserRadio' name='tool' onclick='grid.style.cursor = "url(img/eraser.svg) 2 22, auto"'/> <input type='radio' id='eraserRadio' name='tool' onclick='grid.style.cursor = "url(img/eraser.svg) 2 22, auto"'/>
<label for='eraserRadio' title='Effacer une case'><img src='img/eraser.svg' alt='Gomme'/></label> <label for='eraserRadio' title='Effacer une case'><img src='img/eraser.svg' alt='Gomme'/></label>
<button type='button' class='warning' onclick='restart()' title='Recommencer'> <button type='button' class='warning' onclick='restart()' title='Recommencer'>