From 8295fed903c297c797561a430bc4baf8ce3d4cc7 Mon Sep 17 00:00:00 2001 From: adrien Date: Fri, 30 Oct 2020 19:44:22 +0100 Subject: [PATCH] generate favicon --- app.js | 28 +++++++++-- favicon.php | 61 ---------------------- nginx-example.conf | 2 +- style.css | 1 + game.php => sudoku.php | 33 +++++++++--- test.php | 3 ++ thumbnail.php | 112 +++++++++++++++++++++++++++++++++++++++++ 7 files changed, 168 insertions(+), 72 deletions(-) delete mode 100644 favicon.php rename game.php => sudoku.php (64%) create mode 100644 test.php create mode 100644 thumbnail.php diff --git a/app.js b/app.js index 8568dc8..0ca4f32 100644 --- a/app.js +++ b/app.js @@ -34,6 +34,14 @@ window.onload = function() { } rowId++ } + + let savedGame = localStorage[location.href] + if (savedGame) { + boxes.forEach((box, i) => { + if (!box.disabled && savedGame[i] != '.') box.value = savedGame[i] + }) + } + boxes.forEach(box => { box.neighbourhood = new Set(rows[box.rowId].concat(columns[box.columnId]).concat(regions[box.regionId])) box.neighbourhood.delete(box) @@ -59,8 +67,18 @@ window.onload = function() { function searchCandidatesOf(box) { box.candidates = new Set(VALUES) box.neighbourhood.forEach(neighbour => box.candidates.delete(neighbour.value)) - if (!box.disabled) - box.title = box.candidates.size + (box.candidates.size <= 1 ? " possibilité [Clic-droit]" : " possibilités [Clic-droit]") + if (!box.disabled) { + switch (box.candidates.size) { + case 0: + box.title = "Aucune possibilité !" + break + case 1: + box.title = "1 possibilité [Clic-droit]" + break + default: + box.title = box.candidates.size + " possibilités [Clic-droit]" + } + } } function onfocus() { @@ -74,7 +92,7 @@ function onfocus() { } function oninput() { - history.push({box: this, value: this.previousValue, placeholder: this.previousPlaceholder}) + history.push({box: this, value: this.previousValue || "", placeholder: this.previousPlaceholder || ""}) undoButton.disabled = false if (penStyle != "pencil") { refresh(this) @@ -92,6 +110,8 @@ function undo() { } function refresh(box) { + localStorage[location.href] = boxes.map(box => box.value || ".").join("") + box.neighbourhood.concat([box]).forEach(neighbour => { searchCandidatesOf(neighbour) neighbour.setCustomValidity("") @@ -239,7 +259,7 @@ function oncontextmenu(event) { }) } else { li = document.createElement("li") - li.innerText = "Aucun chiffre possible" + li.innerText = "Aucune possibilité !" li.classList.add("error") contextMenu.appendChild(li) } diff --git a/favicon.php b/favicon.php deleted file mode 100644 index 47c5879..0000000 --- a/favicon.php +++ /dev/null @@ -1,61 +0,0 @@ - $value) { - $x++; - if ($i % 3 == 0) $x++; - if ($i % 9 == 0) { - $y++; - $x = 2; - } - if ($i % 27 == 0) $y++; - if ($value == UNKNOWN) $pixelColor = $unknown; - else $pixelColor = $known; - ImageSetPixel($icon, $x, $y, $pixelColor); - } - } else { - $boxSize = floor(($size-5) / 9); - $start = 1; - $end = 9*$boxSize + 2; - for ($y=0; $y < $size; $y += 3*$boxSize + 1) - ImageLine($icon, $start, $y, $end, $y, $gridBorder); - for ($x=0; $x < $size; $x += 3*$boxSize +1) - ImageLine($icon, $x, $start, $x, $end, $gridBorder); - $x = 0; - $y = 0; - $boxSizeMinusOne = $boxSize - 1; - foreach(str_split($gridStr) as $i => $value) { - if ($i % 3 == 0) $x++; - if ($i % 27 == 0) $y++; - if ($value == UNKNOWN) $color = $unknown; - else $color = $known; - imagefilledrectangle($icon, $x, $y, $x+$boxSizeMinusOne, $y+$boxSizeMinusOne, $color); - $x += $boxSize; - if ($i % 9 == 8) { - $y += $boxSize; - $x = 0; - } - } - } - imagepng($icon); -?> diff --git a/nginx-example.conf b/nginx-example.conf index fb12511..b5a5295 100644 --- a/nginx-example.conf +++ b/nginx-example.conf @@ -19,5 +19,5 @@ location @sudoku { include fastcgi_params; fastcgi_param REMOTE_USER $remote_user; fastcgi_param PATH_INFO $fastcgi_path_info; - fastcgi_param SCRIPT_FILENAME sudoku/game.php; + fastcgi_param SCRIPT_FILENAME sudoku/sudoku.php; } diff --git a/style.css b/style.css index 31601c5..5e82add 100644 --- a/style.css +++ b/style.css @@ -78,6 +78,7 @@ section, div, footer { height: 2.5rem; font-size: 1.5rem; border: 0; + border-radius: 0; padding: 0; text-align: center; transition: background 0.5s; diff --git a/game.php b/sudoku.php similarity index 64% rename from game.php rename to sudoku.php index 3e2e95a..73baeea 100644 --- a/game.php +++ b/sudoku.php @@ -6,15 +6,36 @@ if (preg_match("#^[1-9.]{81}$#", $gridStr)) { ?> - + Sudoku - - + + + + + + + + + + + + + + + + "/> + /thumbnail.php?grid=&size=200"/> + + + + + "/>
@@ -94,12 +115,12 @@ generate(); + $grid = new Grid(); + $grid->generate(); header("HTTP/1.0 400 Bad Request", true, 400); - $urlDir = $_SERVER["REQUEST_SCHEME"] . "://" . $_SERVER["HTTP_HOST"] . dirname($_SERVER["DOCUMENT_URI"]); + $urlDir = $_SERVER["REQUEST_SCHEME"] . "://" . $_SERVER["HTTP_HOST"] . dirname($_SERVER["DOCUMENT_URI"]); $urlExample = $urlDir . "/" . $grid->toString(); ?> diff --git a/test.php b/test.php new file mode 100644 index 0000000..12d66ec --- /dev/null +++ b/test.php @@ -0,0 +1,3 @@ + diff --git a/thumbnail.php b/thumbnail.php new file mode 100644 index 0000000..acbebd4 --- /dev/null +++ b/thumbnail.php @@ -0,0 +1,112 @@ + $value) { + if ($i % 3 == 0) $x++; + if ($i % 27 == 0) $y++; + if ($value == UNKNOWN) { + $bgColor = $white; + } else { + $bgColor = $blue; + } + imagefilledrectangle($thumbnail, $x, $y, $x+$boxSizeMinusOne, $y+$boxSizeMinusOne, $bgColor); + $x += $boxSize; + if ($i % 9 == 8) { + $y += $boxSize; + $x = $start; + } + } + } else if ($size < 82) { + $boxSize = floor(($size-1) / 9); + $gridSize = 9*$boxSize + 1; + $start = floor(($size-$gridSize) / 2); + $end = $start + $gridSize; + $lineStart = $start + 1; + $lineEnd = $end - 2; + for ($i = $start + $boxSize; $i < $end - $boxSize; $i += $boxSize) { + ImageLine($thumbnail, $lineStart, $i, $lineEnd, $i, $grey); + ImageLine($thumbnail, $i, $lineStart, $i, $lineEnd, $grey); + } + for ($i = $start; $i < $end; $i += 3*$boxSize) { + ImageLine($thumbnail, $lineStart, $i, $lineEnd, $i, $black); + ImageLine($thumbnail, $i, $lineStart, $i, $lineEnd, $black); + } + $x = $start + 1; + $y = $start + 1; + $boxSizeMinusTwo = $boxSize - 2; + foreach(str_split($gridStr) as $i => $value) { + if ($value == UNKNOWN) { + $bgColor = $white; + } else { + $bgColor = $blue; + } + imagefilledrectangle($thumbnail, $x, $y, $x+$boxSizeMinusTwo, $y+$boxSizeMinusTwo, $bgColor); + $x += $boxSize; + if ($i % 9 == 8) { + $y += $boxSize; + $x = $start + 1; + } + } + } else { + $boxSize = floor(($size-1) / 9); + $gridSize = 9*$boxSize + 1; + $start = floor(($size-$gridSize) / 2); + $end = $start + $gridSize; + $lineStart = $start + 1; + $lineEnd = $end - 2; + $fontSize = floor($boxSize/2) - 4; + $fdx = floor(($boxSize - imagefontwidth($fontSize)) / 2); + $fdy = ceil(($boxSize - imagefontheight($fontSize)) / 2) - 1; + $fontColor = $white; + for ($i = $start + $boxSize; $i < $end - $boxSize; $i += $boxSize) { + ImageLine($thumbnail, $lineStart, $i, $lineEnd, $i, $grey); + ImageLine($thumbnail, $i, $lineStart, $i, $lineEnd, $grey); + } + for ($i = $start; $i < $end; $i += 3*$boxSize) { + ImageLine($thumbnail, $lineStart, $i, $lineEnd, $i, $black); + ImageLine($thumbnail, $i, $lineStart, $i, $lineEnd, $black); + } + $x = $start + 1; + $y = $start + 1; + $boxSizeMinusTwo = $boxSize - 2; + foreach(str_split($gridStr) as $i => $value) { + if ($value == UNKNOWN) { + $bgColor = $white; + } else { + $bgColor = $blue; + } + imagefilledrectangle($thumbnail, $x, $y, $x+$boxSizeMinusTwo, $y+$boxSizeMinusTwo, $bgColor); + if ($value != UNKNOWN) imagestring($thumbnail, $fontSize, $x + $fdx, $y + $fdy, $value, $fontColor); + $x += $boxSize; + if ($i % 9 == 8) { + $y += $boxSize; + $x = $start + 1; + } + } + } + imagepng($thumbnail); +?>