Compare commits

..

30 Commits

Author SHA1 Message Date
b08e89490f truc 2026-01-10 22:11:50 +01:00
02f17f78bf ruc 2026-01-10 21:53:14 +01:00
f473cc24eb dictionnaire au formal YAML 2026-01-10 20:05:12 +01:00
ab7694a55b nettoyage 2026-01-10 18:36:27 +01:00
ee1ab5a859 nettoyage 2026-01-10 15:54:50 +01:00
45c3a4ddcb nettoyage 2026-01-10 15:45:04 +01:00
baf3a3f8ae ajout de 2 définitions 2026-01-10 14:32:58 +01:00
4552a6f02d peaufinage 2025-12-08 11:03:38 +01:00
a067ce52c5 suppression 2025-12-08 10:49:12 +01:00
743663b1a2 sélection de l'algo de sélection 2025-12-08 10:09:37 +01:00
58b2b97fd6 correction liste définition en cas de ligne sans définition 2025-12-07 14:48:14 +01:00
976498e8be afficher la définition du mot courant 2025-12-06 16:51:38 +01:00
b1704dce72 correction de la session 2025-12-06 15:25:07 +01:00
3418739f91 correction de la session 2025-12-06 15:01:43 +01:00
671b33ccca référencement des labels 2025-12-05 21:24:33 +01:00
cd3946aeeb référenement des labels 2025-12-05 21:22:52 +01:00
459c0e9ed2 chaque définition pointe vers le début du mot 2025-12-05 17:40:16 +01:00
8f1e323c8a les définitions sont des labels ! 2025-12-05 16:50:23 +01:00
d20e5b1559 pas de liste à puce quand il n'y a qu'une définition 2025-12-05 16:22:23 +01:00
0881d9de06 foreach inutile 2025-12-05 10:25:24 +01:00
aeb1d28672 pas d'infobulle sur les mots d'une lettre 2025-12-05 09:11:20 +01:00
27b6033625 pas d'infobulle sur les mots d'une lettre 2025-12-05 09:10:41 +01:00
4a51ed72eb n'afficher que le mot courant dans l'infobulle 2025-12-04 18:09:01 +01:00
329d207930 petits changements 2025-12-04 15:32:59 +01:00
cac6b19ed9 Nettoyage du dictionnaire 2025-12-03 18:41:03 +01:00
5148e5f2d2 espace insécable pour les doubles ponctuations 2025-12-03 18:18:57 +01:00
1b95ef9cee moins de cases noires ? 2025-12-03 18:11:45 +01:00
9587f1e57f supression du debug 2025-12-03 17:26:59 +01:00
563ba7ed0a rechangement de format du dictionnaire 2025-12-03 17:26:36 +01:00
974e2c203c truc inutile 2025-12-03 11:26:55 +01:00
8 changed files with 7120 additions and 3053 deletions

View File

@@ -2,7 +2,7 @@
include_once "dico.php"; include_once "dico.php";
const ECART_TYPE = 5; const ECART_TYPE = 5.0;
$randmax = mt_getrandmax() + 1; $randmax = mt_getrandmax() + 1;
@@ -16,6 +16,27 @@ function gaussienne($moyenne = 0, $ecartType = 1.0): float {
return $z * $ecartType + $moyenne; return $z * $ecartType + $moyenne;
} }
function explode_pos(string $separator, string $string): array {
$mots = [];
$mot = "";
$longueur = strlen($string);
$debut = 0;
for ($i = 0; $i < $longueur; $i++) {
$lettre = $string[$i];
if ($lettre == $separator) {
$mots[] = ["mot" => $mot, "debut" => $debut, "fin" => $i - 1, "longueur" => $i - $debut];
$mot = "";
$debut = $i + 1;
} else {
$mot .= $lettre;
}
}
$mots[] = ["mot" => $mot, "debut" => $debut, "fin" => $longueur - 1, "longueur" => $longueur - $debut];
return $mots;
}
class Grille implements ArrayAccess class Grille implements ArrayAccess
{ {
@@ -78,22 +99,24 @@ class Grille implements ArrayAccess
"horizontales" => [], "horizontales" => [],
"verticales" => [] "verticales" => []
]; ];
foreach($this->lignes as $y => $mots) { for ($y = 0; $y < $this->hauteur; $y++) {
$mots = explode_pos(CASE_NOIRE, $this->get_ligne($y, $this->largeur));
$this->definitions["horizontales"][$y] = []; $this->definitions["horizontales"][$y] = [];
foreach($mots as $mot) { foreach($mots as $mot) {
$definitions = $this->dico[strlen($mot)][$mot]; $definition = $this->dico[$mot["longueur"]][$mot["mot"]];
if (count($definitions)) { $definition["debut"] = $mot["debut"];
$this->definitions["horizontales"][$y][] = $definitions[mt_rand(0, count($definitions) - 1)]; $definition["fin"] = $mot["fin"];
$this->definitions["horizontales"][$y][] = $definition;
} }
} }
} for ($x = 0; $x < $this->largeur; $x++) {
foreach($this->colonnes as $x => $mots) { $mots = explode_pos(CASE_NOIRE, $this->get_colonne($x, $this->hauteur));
$this->definitions["verticales"][$x] = []; $this->definitions["verticales"][$x] = [];
foreach($mots as $mot) { foreach($mots as $mot) {
$definitions = $this->dico[strlen($mot)][$mot]; $definition = $this->dico[$mot["longueur"]][$mot["mot"]];
if (count($definitions)) { $definition["debut"] = $mot["debut"];
$this->definitions["verticales"][$x][] = $definitions[mt_rand(0, count($definitions) - 1)]; $definition["fin"] = $mot["fin"];
} $this->definitions["verticales"][$x][] = $definition;
} }
} }
$this->save($id); $this->save($id);
@@ -122,13 +145,17 @@ class Grille implements ArrayAccess
$lettres_ligne->branches, $lettres_ligne->branches,
$lettres_colonne->branches $lettres_colonne->branches
); );
// Sélection des candidats les plus fertiles
foreach ($lettres_communes as $lettre => $_) { foreach ($lettres_communes as $lettre => $_) {
$lettres_communes[$lettre] = count($lettres_ligne->branches[$lettre]) * count($lettres_colonne->branches[$lettre]) * gaussienne(1, ECART_TYPE); $lettres_communes[$lettre] = log(count($lettres_ligne->branches[$lettre])) * count($lettres_colonne->branches[$lettre]) * gaussienne(ECART_TYPE, ECART_TYPE);
} }
uksort($lettres_communes, function($a, $b) use ($lettres_communes) { uksort($lettres_communes, function($a, $b) use ($lettres_communes) {
return $lettres_communes[$b] <=> $lettres_communes[$a]; return $lettres_communes[$b] <=> $lettres_communes[$a];
}); });
$lettres_communes = array_slice($lettres_communes, 0, 3); uksort($lettres_communes, function($a, $b) {
return ($a == CASE_NOIRE)? 1 : -1;
});
$lettres_communes = array_slice($lettres_communes, 0, 2);
foreach ($lettres_communes as $lettre => $_) { foreach ($lettres_communes as $lettre => $_) {
$this->grille[$y][$x] = $lettre; $this->grille[$y][$x] = $lettre;
@@ -201,18 +228,6 @@ class Grille implements ArrayAccess
); );
} }
public function __serialize(): array {
return [
"grille" => $this->grille,
"definitions" => $this->definitions
];
}
public function __unserialize(array $data): void {
$this->grille = $data["grille"];
$this->definitions = $data["definitions"];
}
public function save($id) public function save($id)
{ {
if (session_status() === PHP_SESSION_ACTIVE) { if (session_status() === PHP_SESSION_ACTIVE) {
@@ -222,7 +237,8 @@ class Grille implements ArrayAccess
session_id("$this->largeur,$this->hauteur,$id"); session_id("$this->largeur,$this->hauteur,$id");
session_start(["use_cookies" => false]); session_start(["use_cookies" => false]);
$_SESSION = serialize($this); $_SESSION["grille"] = $this->grille;
$_SESSION["definitions"] = $this->definitions;
} }
public function load($id) public function load($id)
@@ -230,11 +246,12 @@ class Grille implements ArrayAccess
session_id("$this->largeur,$this->hauteur,$id"); session_id("$this->largeur,$this->hauteur,$id");
session_start(["use_cookies" => false]); session_start(["use_cookies" => false]);
if (!isset($_SESSION["grille"])) { if (!isset($_SESSION)) {
return false; return false;
} }
unserialize($_SESSION); $this->grille = $_SESSION["grille"];
$this->definitions = $_SESSION["definitions"];
return true; return true;
} }

View File

@@ -1,23 +1,27 @@
<?php <?php
class Trie implements ArrayAccess, IteratorAggregate, Countable { class Trie implements ArrayAccess, IteratorAggregate, Countable
{
public array $branches = []; public array $branches = [];
private $nb_branches = 0; private $nb_branches = 0;
public function arraySet($cles, $valeur) { public function arraySet($cles, $valeur)
{
$cle = $cles[0]; $cle = $cles[0];
$this->nb_branches++; $this->nb_branches++;
$cles = array_slice($cles, 1); $cles = array_slice($cles, 1);
if ($cles == []) { if ($cles == []) {
$this->branches[$cle] = $valeur; $this->branches[$cle] = $valeur;
} else { } else {
if (!isset($this->branches[$cle])) $this->branches[$cle] = new Trie(); if (!isset($this->branches[$cle]))
$this->branches[$cle] = new Trie();
$this->branches[$cle]->arraySet($cles, $valeur); $this->branches[$cle]->arraySet($cles, $valeur);
} }
} }
public function arrayExists($cles) { public function arrayExists($cles)
{
$cle = $cles[0]; $cle = $cles[0];
$cles = array_slice($cles, 1); $cles = array_slice($cles, 1);
if ($cles == []) { if ($cles == []) {
@@ -27,7 +31,8 @@ class Trie implements ArrayAccess, IteratorAggregate, Countable {
} }
} }
public function &arrayGet($cles) { public function &arrayGet($cles)
{
$cle = $cles[0]; $cle = $cles[0];
$cles = array_slice($cles, 1); $cles = array_slice($cles, 1);
if ($cles == []) { if ($cles == []) {
@@ -37,7 +42,8 @@ class Trie implements ArrayAccess, IteratorAggregate, Countable {
} }
} }
public function arrayUnset($cles) { public function arrayUnset($cles)
{
$cle = $cles[0]; $cle = $cles[0];
$cles = array_slice($cles, 1); $cles = array_slice($cles, 1);
if ($cles == []) { if ($cles == []) {
@@ -53,28 +59,32 @@ class Trie implements ArrayAccess, IteratorAggregate, Countable {
} }
// ArrayAccess // ArrayAccess
public function offsetSet($array, $valeur): void { public function offsetSet($array, $valeur): void
{
if (is_string($array)) { if (is_string($array)) {
$array = str_split($array); $array = str_split($array);
} }
$this->arraySet($array, $valeur); $this->arraySet($array, $valeur);
} }
public function offsetExists($array): bool { public function offsetExists($array): bool
{
if (is_string($array)) { if (is_string($array)) {
$array = str_split($array); $array = str_split($array);
} }
return $this->arrayExists($array); return $this->arrayExists($array);
} }
public function &offsetGet($array): mixed { public function &offsetGet($array): mixed
{
if (is_string($array)) { if (is_string($array)) {
$array = str_split($array); $array = str_split($array);
} }
return $this->arrayGet($array); return $this->arrayGet($array);
} }
public function offsetUnset($array): void { public function offsetUnset($array): void
{
if (is_string($array)) { if (is_string($array)) {
$array = str_split($array); $array = str_split($array);
} }
@@ -82,7 +92,8 @@ class Trie implements ArrayAccess, IteratorAggregate, Countable {
} }
// IteratorAggregate // IteratorAggregate
public function getIterator(): Traversable { public function getIterator(): Traversable
{
foreach ($this->branches as $cle => $branche) { foreach ($this->branches as $cle => $branche) {
if ($branche instanceof Trie) { if ($branche instanceof Trie) {
foreach ($branche->getIterator() as $sous_cles => $feuille) { foreach ($branche->getIterator() as $sous_cles => $feuille) {
@@ -95,7 +106,8 @@ class Trie implements ArrayAccess, IteratorAggregate, Countable {
} }
// Countable // Countable
public function count(): int { public function count(): int
{
return $this->nb_branches; return $this->nb_branches;
} }
} }

2839
dico.csv

File diff suppressed because it is too large Load Diff

View File

@@ -9,45 +9,51 @@ const CASE_NOIRE = " ";
function dico($longueur_max) { function dico($longueur_max) {
$transliterator = Transliterator::createFromRules(':: Any-Latin; :: Latin-ASCII; :: NFD; :: [:Nonspacing Mark:] Remove; :: Upper(); :: NFC;', Transliterator::FORWARD); $transliterator = Transliterator::createFromRules(':: Any-Latin; :: Latin-ASCII; :: NFD; :: [:Nonspacing Mark:] Remove; :: Upper(); :: NFC;', Transliterator::FORWARD);
$dico = [[new Trie()]]; $dico = [];
for ($longueur = 0; $longueur <= $longueur_max; $longueur++) { for ($longueur = 0; $longueur <= $longueur_max; $longueur++) {
$dico[] = new Trie(); $dico[] = new Trie();
} }
if (($lecteur = fopen("dico.csv", "r")) !== FALSE) { foreach (str_split("ABCDEFGHIJKLMNOPQRSTUVWXYZ") as $lettre) {
$entete = fgetcsv($lecteur, 0, "\t"); $dico[1][$lettre] = [];
while (($ligne = fgetcsv($lecteur, 0, "\t")) !== FALSE) { }
if (
$ligne[0] == NULL
|| substr($ligne[0], 0, 1) == "#"
|| strlen($ligne[0]) > $longueur_max
) continue;
$mot = $ligne[0];
$definitions = array_slice($ligne, 1);
foreach (yaml_parse_file('dico.yaml') as $mot => $definitions) {
$mot = str_replace("-", CASE_NOIRE, $mot); $mot = str_replace("-", CASE_NOIRE, $mot);
$mot = $transliterator->transliterate($mot); $mot = $transliterator->transliterate($mot);
if (strpos($mot, CASE_NOIRE) !== false) { if (strpos($mot, CASE_NOIRE) !== false) {
$mots = explode(CASE_NOIRE, $mot); $mots = explode(CASE_NOIRE, $mot);
$nb_mots = count($mots); $nb_mots = count($mots);
$mot = implode("", $mots); $mot = implode("", $mots);
foreach($definitions as $i => $definition) { } else {
$definitions[$i] = "$definition#$nb_mots"; $nb_mots = 1;
}
} }
$dico[strlen($mot)][$mot] = $definitions; if (strlen($mot) > $longueur_max) continue;
$dico[strlen($mot)][$mot] = [];
if (count($definitions)) {
$definition = $definitions[mt_rand(0, count($definitions) - 1)];
if (is_array($definition)) {
foreach ($definition as $auteur => $def) {
$dico[strlen($mot)][$mot]["definition"] = $def;
$dico[strlen($mot)][$mot]["auteur"] = $auteur;
} }
fclose($lecteur); } else if (is_string($definition)) {
$dico[strlen($mot)][$mot]["definition"] = $definition;
}
}
if ($nb_mots > 1) $dico[strlen($mot)][$mot]["nb_mots"] = $nb_mots;
} }
return $dico; return $dico;
} }
function mots_espaces($longueur_max) { function mots_espaces($longueur_max) {
$longueur_min = 1;
$dico = dico($longueur_max); $dico = dico($longueur_max);
for ($longueur = $longueur_max; $longueur >= 2; $longueur--) { for ($longueur = 3; $longueur <= $longueur_max; $longueur++) {
for ($position_espace = $longueur - 2; $position_espace >= 1; $position_espace--) { //$longueur_min = $longueur == $longueur_max ? 1 : 2;
for ($position_espace = $longueur - 2; $position_espace >= $longueur_min; $position_espace--) {
$mots_suivants = $dico[$longueur - $position_espace - 1]; $mots_suivants = $dico[$longueur - $position_espace - 1];
foreach ($dico[$position_espace] as $premier_mot => $definition) { foreach ($dico[$position_espace] as $premier_mot => $definition) {
$premier_mot[] = CASE_NOIRE; $premier_mot[] = CASE_NOIRE;

6806
dico.yaml Normal file

File diff suppressed because it is too large Load Diff

114
index.php
View File

@@ -1,5 +1,7 @@
<?php <?php
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
error_reporting(E_ALL);
include_once "Grille.php"; include_once "Grille.php";
@@ -44,19 +46,27 @@ if (!isset($_GET["grille"]) || $_GET["grille"] == "") {
} }
function formatter_definition($definition) { function formatter_definition($definition) {
if (strpos($definition, "#") !== false) { if (isset($definition["nb_mots"]) && $definition["nb_mots"] > 1) {
[$definition, $nb_mots] = explode("#", $definition); $nb_mots = $definition["nb_mots"];
$nb_mots = " <small>($nb_mots mots)</small>"; $nb_mots = " <small>($nb_mots mots)</small>";
} else { } else {
$nb_mots = ""; $nb_mots = "";
} }
if (strpos($definition, "@") !== false) { if (isset($definition["auteur"])) {
[$definition, $auteur] = explode("@", $definition); $auteur = $definition["auteur"];
$auteur = " <small><em>$auteur</em></small>"; $auteur = " <small><em>$auteur</em></small>";
} else { } else {
$auteur = ""; $auteur = "";
} }
return $definition . $nb_mots . $auteur; return ucfirst($definition["definition"]) . $nb_mots . $auteur;
}
function definition_courante($definitions, $position) {
foreach ($definitions as $id => $definition) {
if ($position <= $definition["fin"])
return [$id, $definition];
}
return [];
} }
?> ?>
<!DOCTYPE HTML> <!DOCTYPE HTML>
@@ -68,15 +78,18 @@ function formatter_definition($definition) {
<link rel="stylesheet" href="style.css"> <link rel="stylesheet" href="style.css">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="shortcut icon" href="favicon.ico" /> <link rel="shortcut icon" href="favicon.ico" />
<link rel="icon" type="image/svg+xml" href="apercu.svg.php?grille=<?=$id?>&lignes=<?=$hauteur?>&colonnes=<?=$largeur?>"> <link rel="icon" type="image/svg+xml"
<link rel="icon" type="image/png" sizes="96x96" href="apercu.png.php?grille=<?=$id?>&lignes=<?=$hauteur?>&colonnes=<?=$largeur?>&largeur=96&hauteur=96" /> href="apercu.svg.php?grille=<?= $id ?>&lignes=<?= $hauteur ?>&colonnes=<?= $largeur ?>">
<link rel="icon" type="image/png" sizes="96x96"
href="apercu.png.php?grille=<?= $id ?>&lignes=<?= $hauteur ?>&colonnes=<?= $largeur ?>&largeur=96&hauteur=96" />
<link rel="apple-touch-icon" sizes="180x180" href="favicons/apple-touch-icon.png" /> <link rel="apple-touch-icon" sizes="180x180" href="favicons/apple-touch-icon.png" />
<meta name="apple-mobile-web-app-title" content="🄼🄾🅃🅂 🄲🅁🄾🄸🅂🄴🅂" /> <meta name="apple-mobile-web-app-title" content="🄼🄾🅃🅂 🄲🅁🄾🄸🅂🄴🅂" />
<link rel="manifest" href="site.webmanifest" /> <link rel="manifest" href="site.webmanifest" />
<meta property="og:title" content="🄼🄾🅃🅂▣🄲🅁🄾🄸🅂🄴🅂" /> <meta property="og:title" content="🄼🄾🅃🅂▣🄲🅁🄾🄸🅂🄴🅂" />
<meta property="og:type" content="game" /> <meta property="og:type" content="game" />
<meta property="og:url" content="<?= $basedir ?>" /> <meta property="og:url" content="<?= $basedir ?>" />
<meta property="og:image" content="<?=$basedir?>/apercu.png.php?grille=<?=$id?>&lignes=<?=$hauteur?>&colonnes=<?=$largeur?>&largeur=1200&hauteur=630"/> <meta property="og:image"
content="<?= $basedir ?>/apercu.png.php?grille=<?= $id ?>&lignes=<?= $hauteur ?>&colonnes=<?= $largeur ?>&largeur=1200&hauteur=630" />
<meta property="og:image:width" content="1200" /> <meta property="og:image:width" content="1200" />
<meta property="og:image:height" content="630" /> <meta property="og:image:height" content="630" />
<meta property="og:locale" content="fr_FR" /> <meta property="og:locale" content="fr_FR" />
@@ -132,12 +145,34 @@ function formatter_definition($definition) {
<?php for ($x = 0; $x < $largeur; $x++): ?> <?php for ($x = 0; $x < $largeur; $x++): ?>
<?php if ($grille[$y][$x] == CASE_NOIRE): ?> <?php if ($grille[$y][$x] == CASE_NOIRE): ?>
<td class="case noire"> <td class="case noire">
<input id="<?= chr($x + 65) . ($y + 1) ?>" type="text" maxlength="1" size="1" value="<?= CASE_NOIRE ?>" disabled /> <input id="<?= chr($x + 65) . ($y + 1) ?>" type="text" maxlength="1" size="1"
value="<?= CASE_NOIRE ?>" disabled />
</td> </td>
<?php else: ?> <?php else: ?>
<td class="case blanche"> <td class="case blanche">
<input id="<?= chr($x + 65) . ($y + 1) ?>" type="text" maxlength="1" size="1" pattern="[A-Z]" <?php
title="<?= strip_tags("→ " . implode("\n→ ", array_map("formatter_definition", $grille->definitions["horizontales"][$y] ?? [])) . "\n↓ " . implode("\n↓ ", array_map("formatter_definition", $grille->definitions["verticales"][$x] ?? []))) ?>" /> $title = [];
[$iddh, $definition_horizontale] = definition_courante($grille->definitions["horizontales"][$y], $x);
[$iddv, $definition_verticale] = definition_courante($grille->definitions["verticales"][$x], $y);
if (isset($definition_horizontale["definition"]))
$title[0] = "→ " . $definition_horizontale["definition"];
if (isset($definition_horizontale["nb_mots"]))
$title[0] .= " (" . $definition_horizontale["nb_mots"] . ")";
if (isset($definition_horizontale["auteur"]))
$title[0] .= " (" . $definition_horizontale["auteur"] . ")";
if (isset($definition_verticale["definition"]))
$title[1] = "↓ " . $definition_verticale["definition"];
if (isset($definition_verticale["nb_mots"]))
$title[0] .= " (" . $definition_verticale["nb_mots"] . ")";
if (isset($definition_verticale["auteur"]))
$title[1] .= " (" . $definition_verticale["auteur"] . ")";
$title = htmlspecialchars(implode("\n", $title));
?>
<input id="case-<?= chr($x + 65) . ($y + 1) ?>" type="text" maxlength="1" size="1"
pattern="[A-Z]" title="<?= $title ?>"
data-iddh="<?= isset($definition_horizontale["definition"])? "dh-$y-$iddh" : "" ?>"
data-iddv="<?= isset($definition_verticale["definition"])? "dv-$x-$iddv" : "" ?>"
/>
</td> </td>
<?php endif; ?> <?php endif; ?>
<?php endfor; ?> <?php endfor; ?>
@@ -148,45 +183,66 @@ function formatter_definition($definition) {
<div class="definitions horizontales"> <div class="definitions horizontales">
<h2>Horizontalement</h2> <h2>Horizontalement</h2>
<ol type="1"> <ol type="1">
<?php foreach ($grille->definitions["horizontales"] as $y => $definitions): ?> <?php foreach ($grille->definitions["horizontales"] as $y => $definitions):
<li> $definitions = array_filter($definitions, function($definition) {
return isset($definition["definition"]);
});
?>
<?php if (count($definitions)): ?> <?php if (count($definitions)): ?>
<?php if (count($definitions) == 1): ?> <?php if (count($definitions) == 1): ?>
<?= formatter_definition($definitions[0]) ?> <?php foreach ($definitions as $id => $definition): ?>
<li id="<?= "dh-$y-$id" ?>"><label for="case-A<?= $y + 1 ?>"><?= formatter_definition($definition) ?></label></li>
<?php endforeach ?>
<?php else: ?> <?php else: ?>
<li>
<ol> <ol>
<?php foreach ($definitions as $definition) : ?> <?php foreach ($definitions as $id => $definition): ?>
<li><?= formatter_definition($definition) ?></li> <li id="<?= "dh-$y-$id" ?>">
<label for="case-<?= chr($definition["debut"] + 0x41) ?><?= $y + 1 ?>"><?= formatter_definition($definition) ?></label>
</li>
<?php endforeach ?> <?php endforeach ?>
</ol> </ol>
<?php endif ?>
<?php endif ?>
</li> </li>
<?php endforeach; ?> <?php endif ?>
<?php else: ?>
<li></li>
<?php endif ?>
<?php endforeach ?>
</ol> </ol>
</div> </div>
<div class="definitions verticales"> <div class="definitions verticales">
<h2>Verticalement</h2> <h2>Verticalement</h2>
<ol type="A"> <ol type="A">
<?php foreach ($grille->definitions["verticales"] as $x => $definitions): ?> <?php foreach ($grille->definitions["verticales"] as $x => $definitions):
<li> $definitions = array_filter($definitions, function($definition) {
return isset($definition["definition"]);
});
?>
<?php if (count($definitions)): ?> <?php if (count($definitions)): ?>
<?php if (count($definitions) == 1): ?> <?php if (count($definitions) == 1): ?>
<?= formatter_definition($definitions[0]) ?> <?php foreach ($definitions as $id => $definition): ?>
<li id="<?= "dv-$x-$id" ?>"><label for="case-<?= chr($x + 0x41) ?>1"><?= formatter_definition($definition) ?></label></li>
<?php endforeach ?>
<?php else: ?> <?php else: ?>
<li>
<ol> <ol>
<?php foreach ($definitions as $definition) : ?> <?php foreach ($definitions as $id => $definition): ?>
<li><?= formatter_definition($definition) ?></li> <li id="<?= "dv-$x-$id" ?>">
<label for="case-<?= chr($x + 0x41) ?><?= $definition["debut"] + 1 ?>"><?= formatter_definition($definition) ?></label>
</li>
<?php endforeach ?> <?php endforeach ?>
</ol> </ol>
<?php endif ?>
<?php endif ?>
</li> </li>
<?php endforeach; ?> <?php endif ?>
<?php else: ?>
<li></li>
<?php endif ?>
<?php endforeach ?>
</ol> </ol>
</div> </div>
<input type="hidden" id="solution_hashee" value="<?= $grille->hash() ?>" /> <input type="hidden" id="solution_hashee" value="<?= $grille->hash() ?>" />
<?php else: http_response_code(500); ?> <?php else:
http_response_code(500); ?>
<h3 class="erreur">Erreur de génération de la grille</h3> <h3 class="erreur">Erreur de génération de la grille</h3>
<?php endif ?> <?php endif ?>
</div> </div>

View File

@@ -17,16 +17,31 @@ for (let input of inputs) {
input.onfocus = function (event) { input.onfocus = function (event) {
for (li of document.querySelectorAll( for (li of document.querySelectorAll(
`.definitions.horizontales > ol > li:nth-child(${ `.definitions.horizontales > ol > li:nth-child(${input.y + 1})`
input.y + 1
}), .definitions.verticales > ol > li:nth-child(${input.x + 1})`
)) { )) {
li.classList.add("selectionee"); li.classList.add("selectionee");
for (liEnfant of li.querySelectorAll("li")) {
if (liEnfant.id == input.dataset.iddh) {
liEnfant.classList.add("selectionee");
} else {
liEnfant.classList.add("non-selectionee");
}
}
} }
for (li of document.querySelectorAll( for (li of document.querySelectorAll(
`.definitions.horizontales > ol > li:not(:nth-child(${ `.definitions.verticales > ol > li:nth-child(${input.x + 1})`
input.y + 1 )) {
})), .definitions.verticales > ol > li:not(:nth-child(${input.x + 1}))` li.classList.add("selectionee");
for (liEnfant of li.querySelectorAll("li")) {
if (liEnfant.id == input.dataset.iddv) {
liEnfant.classList.add("selectionee");
} else {
liEnfant.classList.add("non-selectionee");
}
}
}
for (li of document.querySelectorAll(
`.definitions.horizontales > ol > li:not(:nth-child(${input.y + 1})), .definitions.verticales > ol > li:not(:nth-child(${input.x + 1}))`
)) { )) {
li.classList.add("non-selectionee"); li.classList.add("non-selectionee");
} }
@@ -79,21 +94,11 @@ for (let input of inputs) {
}; };
input.onblur = function (event) { input.onblur = function (event) {
for (li of document.querySelectorAll( for (li of document.querySelectorAll(".definitions li")) {
`.definitions.horizontales > ol > li:nth-child(${
input.y + 1
}), .definitions.verticales > ol > li:nth-child(${input.x + 1})`
)) {
li.classList.remove("selectionee"); li.classList.remove("selectionee");
}
for (li of document.querySelectorAll(
`.definitions.horizontales > ol > li:not(:nth-child(${
input.y + 1
})), .definitions.verticales > ol > li:not(:nth-child(${input.x + 1}))`
)) {
li.classList.remove("non-selectionee"); li.classList.remove("non-selectionee");
} }
}; }
} }
for (let input of grilleForm.querySelectorAll(".nouvelle-grille input")) { for (let input of grilleForm.querySelectorAll(".nouvelle-grille input")) {

View File

@@ -177,6 +177,10 @@ h2 {
opacity: 30%; opacity: 30%;
} }
.definitions label {
cursor: pointer;
}
.erreur { .erreur {
text-align: center; text-align: center;
} }