Compare commits
14 Commits
671b33ccca
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
b08e89490f
|
|||
|
02f17f78bf
|
|||
|
f473cc24eb
|
|||
|
ab7694a55b
|
|||
|
ee1ab5a859
|
|||
|
45c3a4ddcb
|
|||
|
baf3a3f8ae
|
|||
|
4552a6f02d
|
|||
|
a067ce52c5
|
|||
|
743663b1a2
|
|||
|
58b2b97fd6
|
|||
|
976498e8be
|
|||
|
b1704dce72
|
|||
|
3418739f91
|
50
Grille.php
50
Grille.php
@@ -103,34 +103,20 @@ class Grille implements ArrayAccess
|
||||
$mots = explode_pos(CASE_NOIRE, $this->get_ligne($y, $this->largeur));
|
||||
$this->definitions["horizontales"][$y] = [];
|
||||
foreach($mots as $mot) {
|
||||
$definitions = $this->dico[$mot["longueur"]][$mot["mot"]];
|
||||
if (count($definitions)) {
|
||||
$definition = $definitions[mt_rand(0, count($definitions) - 1)];
|
||||
if (isset($definition[DEFINITION])) $mot["definition"] = $definition[DEFINITION];
|
||||
if (isset($definition[AUTEUR])) $mot["auteur"] = $definition[AUTEUR];
|
||||
}
|
||||
if (isset($definitions["nb_mots"])) {
|
||||
$mot["nb_mots"] = $definitions["nb_mots"];
|
||||
}
|
||||
unset($mot["mot"]);
|
||||
$this->definitions["horizontales"][$y][] = $mot;
|
||||
$definition = $this->dico[$mot["longueur"]][$mot["mot"]];
|
||||
$definition["debut"] = $mot["debut"];
|
||||
$definition["fin"] = $mot["fin"];
|
||||
$this->definitions["horizontales"][$y][] = $definition;
|
||||
}
|
||||
}
|
||||
for ($x = 0; $x < $this->largeur; $x++) {
|
||||
$mots = explode_pos(CASE_NOIRE, $this->get_colonne($x, $this->hauteur));
|
||||
$this->definitions["verticales"][$x] = [];
|
||||
foreach($mots as $mot) {
|
||||
$definitions = $this->dico[$mot["longueur"]][$mot["mot"]];
|
||||
if (count($definitions)) {
|
||||
$definition = $definitions[mt_rand(0, count($definitions) - 1)];
|
||||
if (isset($definition[DEFINITION])) $mot["definition"] = $definition[DEFINITION];
|
||||
if (isset($definition[AUTEUR])) $mot["auteur"] = $definition[AUTEUR];
|
||||
}
|
||||
if (isset($definitions["nb_mots"])) {
|
||||
$mot["nb_mots"] = $definitions["nb_mots"];
|
||||
}
|
||||
unset($mot["mot"]);
|
||||
$this->definitions["verticales"][$x][] = $mot;
|
||||
$definition = $this->dico[$mot["longueur"]][$mot["mot"]];
|
||||
$definition["debut"] = $mot["debut"];
|
||||
$definition["fin"] = $mot["fin"];
|
||||
$this->definitions["verticales"][$x][] = $definition;
|
||||
}
|
||||
}
|
||||
$this->save($id);
|
||||
@@ -242,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)
|
||||
{
|
||||
if (session_status() === PHP_SESSION_ACTIVE) {
|
||||
@@ -263,7 +237,8 @@ class Grille implements ArrayAccess
|
||||
session_id("$this->largeur,$this->hauteur,$id");
|
||||
session_start(["use_cookies" => false]);
|
||||
|
||||
$_SESSION = serialize($this);
|
||||
$_SESSION["grille"] = $this->grille;
|
||||
$_SESSION["definitions"] = $this->definitions;
|
||||
}
|
||||
|
||||
public function load($id)
|
||||
@@ -271,11 +246,12 @@ class Grille implements ArrayAccess
|
||||
session_id("$this->largeur,$this->hauteur,$id");
|
||||
session_start(["use_cookies" => false]);
|
||||
|
||||
if (!isset($_SESSION["grille"])) {
|
||||
if (!isset($_SESSION)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
unserialize($_SESSION);
|
||||
$this->grille = $_SESSION["grille"];
|
||||
$this->definitions = $_SESSION["definitions"];
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
60
dico.php
60
dico.php
@@ -4,8 +4,6 @@ include_once "Trie.php";
|
||||
|
||||
|
||||
const CASE_NOIRE = " ";
|
||||
const DEFINITION = 0;
|
||||
const AUTEUR = 1;
|
||||
|
||||
|
||||
function dico($longueur_max) {
|
||||
@@ -15,45 +13,47 @@ function dico($longueur_max) {
|
||||
for ($longueur = 0; $longueur <= $longueur_max; $longueur++) {
|
||||
$dico[] = new Trie();
|
||||
}
|
||||
if (($lecteur = fopen("dico.tsv", "r")) !== FALSE) {
|
||||
$entete = fgetcsv($lecteur, 0, "\t");
|
||||
while (($ligne = fgetcsv($lecteur, 0, "\t")) !== FALSE) {
|
||||
if (
|
||||
$ligne[0] == NULL
|
||||
|| substr($ligne[0], 0, 1) == "#"
|
||||
|| strlen($ligne[0]) > $longueur_max
|
||||
) continue;
|
||||
foreach (str_split("ABCDEFGHIJKLMNOPQRSTUVWXYZ") as $lettre) {
|
||||
$dico[1][$lettre] = [];
|
||||
}
|
||||
|
||||
$mot = $ligne[0];
|
||||
$definition = array_slice($ligne, 1);
|
||||
foreach (yaml_parse_file('dico.yaml') as $mot => $definitions) {
|
||||
$mot = str_replace("-", CASE_NOIRE, $mot);
|
||||
$mot = $transliterator->transliterate($mot);
|
||||
if (strpos($mot, CASE_NOIRE) !== false) {
|
||||
$mots = explode(CASE_NOIRE, $mot);
|
||||
$nb_mots = count($mots);
|
||||
$mot = implode("", $mots);
|
||||
} else {
|
||||
$nb_mots = 1;
|
||||
}
|
||||
|
||||
$mot = str_replace("-", CASE_NOIRE, $mot);
|
||||
$mot = $transliterator->transliterate($mot);
|
||||
if (strpos($mot, CASE_NOIRE) !== false) {
|
||||
$mots = explode(CASE_NOIRE, $mot);
|
||||
$nb_mots = count($mots);
|
||||
$mot = implode("", $mots);
|
||||
} else {
|
||||
$nb_mots = 1;
|
||||
}
|
||||
if (strlen($mot) > $longueur_max) continue;
|
||||
|
||||
if (array_key_exists($mot, $dico)) {
|
||||
$dico[strlen($mot)][$mot][] = $definition;
|
||||
} else {
|
||||
$dico[strlen($mot)][$mot] = [$definition];
|
||||
if ($nb_mots > 1) $dico[strlen($mot)][$mot]["nb_mots"] = $nb_mots;
|
||||
$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;
|
||||
}
|
||||
} else if (is_string($definition)) {
|
||||
$dico[strlen($mot)][$mot]["definition"] = $definition;
|
||||
}
|
||||
}
|
||||
fclose($lecteur);
|
||||
if ($nb_mots > 1) $dico[strlen($mot)][$mot]["nb_mots"] = $nb_mots;
|
||||
}
|
||||
|
||||
return $dico;
|
||||
}
|
||||
|
||||
function mots_espaces($longueur_max, $longueur_min=1) {
|
||||
function mots_espaces($longueur_max) {
|
||||
$longueur_min = 1;
|
||||
$dico = dico($longueur_max);
|
||||
for ($longueur = $longueur_max; $longueur >= $longueur_min + 1; $longueur--) {
|
||||
for ($position_espace = $longueur - $longueur_min - 1; $position_espace >= $longueur_min; $position_espace--) {
|
||||
for ($longueur = 3; $longueur <= $longueur_max; $longueur++) {
|
||||
//$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];
|
||||
foreach ($dico[$position_espace] as $premier_mot => $definition) {
|
||||
$premier_mot[] = CASE_NOIRE;
|
||||
|
||||
46
index.php
46
index.php
@@ -170,8 +170,8 @@ function definition_courante($definitions, $position) {
|
||||
?>
|
||||
<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" : "" ?>"
|
||||
data-iddh="<?= isset($definition_horizontale["definition"])? "dh-$y-$iddh" : "" ?>"
|
||||
data-iddv="<?= isset($definition_verticale["definition"])? "dv-$x-$iddv" : "" ?>"
|
||||
/>
|
||||
</td>
|
||||
<?php endif; ?>
|
||||
@@ -188,25 +188,25 @@ function definition_courante($definitions, $position) {
|
||||
return isset($definition["definition"]);
|
||||
});
|
||||
?>
|
||||
<li>
|
||||
<?php if (count($definitions)): ?>
|
||||
<?php if (count($definitions) == 1): ?>
|
||||
<?php foreach ($definitions as $id => $definition): ?>
|
||||
<label id="<?= "dh-$y.$id" ?>" for="case-1<?= $y + 1 ?>">
|
||||
<?= formatter_definition($definition) ?>
|
||||
</label>
|
||||
<li id="<?= "dh-$y-$id" ?>"><label for="case-A<?= $y + 1 ?>"><?= formatter_definition($definition) ?></label></li>
|
||||
<?php endforeach ?>
|
||||
<?php else: ?>
|
||||
<li>
|
||||
<ol>
|
||||
<?php foreach ($definitions as $id => $definition): ?>
|
||||
<label id="<?= "dh-$y.$id" ?>" for="case-<?= chr($definition["debut"] + 0x41) ?><?= $y + 1 ?>">
|
||||
<li><?= formatter_definition($definition) ?></li>
|
||||
</label>
|
||||
<li id="<?= "dh-$y-$id" ?>">
|
||||
<label for="case-<?= chr($definition["debut"] + 0x41) ?><?= $y + 1 ?>"><?= formatter_definition($definition) ?></label>
|
||||
</li>
|
||||
<?php endforeach ?>
|
||||
</ol>
|
||||
<?php endif ?>
|
||||
<?php endif ?>
|
||||
</li>
|
||||
<?php endif ?>
|
||||
<?php else: ?>
|
||||
<li></li>
|
||||
<?php endif ?>
|
||||
<?php endforeach ?>
|
||||
</ol>
|
||||
</div>
|
||||
@@ -218,25 +218,25 @@ function definition_courante($definitions, $position) {
|
||||
return isset($definition["definition"]);
|
||||
});
|
||||
?>
|
||||
<li>
|
||||
<?php if (count($definitions)): ?>
|
||||
<?php if (count($definitions) == 1): ?>
|
||||
<?php foreach ($definitions as $id => $definition): ?>
|
||||
<label id="<?= "dv-$x.$id" ?>" for="case-<?= chr($x + 0x41) ?>1">
|
||||
<?= formatter_definition($definition) ?>
|
||||
</label>
|
||||
<li id="<?= "dv-$x-$id" ?>"><label for="case-<?= chr($x + 0x41) ?>1"><?= formatter_definition($definition) ?></label></li>
|
||||
<?php endforeach ?>
|
||||
<?php else: ?>
|
||||
<li>
|
||||
<ol>
|
||||
<?php foreach ($definitions as $id => $definition): ?>
|
||||
<label id="<?= "dv-$x.$id" ?>" for="case-<?= chr($x + 0x41) ?><?= $definition["debut"] + 1 ?>">
|
||||
<li><?= formatter_definition($definition) ?></li>
|
||||
</label>
|
||||
<li id="<?= "dv-$x-$id" ?>">
|
||||
<label for="case-<?= chr($x + 0x41) ?><?= $definition["debut"] + 1 ?>"><?= formatter_definition($definition) ?></label>
|
||||
</li>
|
||||
<?php endforeach ?>
|
||||
</ol>
|
||||
<?php endif ?>
|
||||
<?php endif ?>
|
||||
</li>
|
||||
<?php endif ?>
|
||||
<?php else: ?>
|
||||
<li></li>
|
||||
<?php endif ?>
|
||||
<?php endforeach ?>
|
||||
</ol>
|
||||
</div>
|
||||
@@ -251,11 +251,9 @@ function definition_courante($definitions, $position) {
|
||||
<img src="favicons/favicon.svg" width="16" height="16">
|
||||
<button type="submit">Nouvelle grille</button>
|
||||
de
|
||||
<input type="number" id="lignes" <?= isset($_GET["lignes"]) ? ' name="lignes"' : "" ?>
|
||||
value="<?= $hauteur ?>" min="<?= HAUTEUR_MIN ?>" max="<?= HAUTEUR_MAX ?>" />
|
||||
<input type="number" id="lignes" <?= isset($_GET["lignes"]) ? ' name="lignes"' : "" ?> value="<?= $hauteur ?>" min="<?= HAUTEUR_MIN ?>" max="<?= HAUTEUR_MAX ?>" />
|
||||
lignes et
|
||||
<input type="number" id="colonnes" <?= isset($_GET["colonnes"]) ? ' name="colonnes"' : "" ?>
|
||||
value="<?= $largeur ?>" min="<?= LARGEUR_MIN ?>" max="<?= LARGEUR_MAX ?>" />
|
||||
<input type="number" id="colonnes" <?= isset($_GET["colonnes"]) ? ' name="colonnes"' : "" ?> value="<?= $largeur ?>" min="<?= LARGEUR_MIN ?>" max="<?= LARGEUR_MAX ?>" />
|
||||
colonnes
|
||||
</div>
|
||||
</form>
|
||||
|
||||
41
script.js
41
script.js
@@ -17,16 +17,31 @@ for (let input of inputs) {
|
||||
|
||||
input.onfocus = function (event) {
|
||||
for (li of document.querySelectorAll(
|
||||
`.definitions.horizontales > ol > li:nth-child(${
|
||||
input.y + 1
|
||||
}), .definitions.verticales > ol > li:nth-child(${input.x + 1})`
|
||||
`.definitions.horizontales > ol > li:nth-child(${input.y + 1})`
|
||||
)) {
|
||||
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(
|
||||
`.definitions.horizontales > ol > li:not(:nth-child(${
|
||||
input.y + 1
|
||||
})), .definitions.verticales > ol > li:not(:nth-child(${input.x + 1}))`
|
||||
`.definitions.verticales > ol > li: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");
|
||||
}
|
||||
@@ -79,21 +94,11 @@ for (let input of inputs) {
|
||||
};
|
||||
|
||||
input.onblur = function (event) {
|
||||
for (li of document.querySelectorAll(
|
||||
`.definitions.horizontales > ol > li:nth-child(${
|
||||
input.y + 1
|
||||
}), .definitions.verticales > ol > li:nth-child(${input.x + 1})`
|
||||
)) {
|
||||
for (li of document.querySelectorAll(".definitions li")) {
|
||||
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");
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
for (let input of grilleForm.querySelectorAll(".nouvelle-grille input")) {
|
||||
|
||||
Reference in New Issue
Block a user