Changement de la méthode de récupération du mot du jour

This commit is contained in:
JonathanMM 2022-01-30 10:24:39 +01:00
parent 70bc91d557
commit e52bd0b021
7 changed files with 64 additions and 28 deletions

1
.gitignore vendored
View file

@ -1,6 +1,7 @@
config/
data/
js/
mots/
node_modules/
ts/mots/listeMotsATrouver.*.ts
cron.prod.sh

2
cron.sh Normal file → Executable file
View file

@ -4,5 +4,3 @@ npm install
node utils/melangerATrouver.js
node utils/majATrouver.js
tsc
cp -r public/* /var/www/sutom/
cp -r js/ /var/www/sutom/

View file

@ -1,15 +1,14 @@
import ListeMotsProposables from "./mots/listeMotsProposables";
import ListeMotsATrouver from "./mots/listeMotsATrouver";
export default class Dictionnaire {
public constructor() {}
public getMot(datePartie: Date): string {
public async getMot(datePartie: Date): Promise<string> {
let aujourdhui = datePartie.getTime();
let origine = new Date(2022, 0, 8).getTime();
let numeroGrille = Math.floor((aujourdhui - origine) / (24 * 3600 * 1000));
let numeroGrille = Math.floor((aujourdhui - origine) / (24 * 3600 * 1000)) + 1;
return ListeMotsATrouver.Liste[numeroGrille % ListeMotsATrouver.Liste.length];
return await fetch("mots/" + numeroGrille + ".txt").then((resultat) => resultat.text());
}
public estMotValide(mot: string): boolean {

View file

@ -15,8 +15,8 @@ import ConfigurationPanel from "./configurationPanel";
export default class Gestionnaire {
private readonly _dictionnaire: Dictionnaire;
private readonly _grille: Grille;
private readonly _input: Input;
private _grille: Grille | null = null;
private _input: Input | null = null;
private readonly _reglesPanel: ReglesPanel;
private readonly _finDePartiePanel: FinDePartiePanel;
private readonly _configurationPanel: ConfigurationPanel;
@ -24,8 +24,8 @@ export default class Gestionnaire {
private readonly _resultats: Array<Array<LettreResultat>>;
private readonly _panelManager: PanelManager;
private _motATrouver: string;
private _compositionMotATrouver: { [lettre: string]: number };
private _motATrouver: string = "";
private _compositionMotATrouver: { [lettre: string]: number } = {};
private _maxNbPropositions: number = 6;
private _datePartieEnCours: Date;
private _stats: SauvegardeStats = { partiesJouees: 0, partiesGagnees: 0 };
@ -43,18 +43,20 @@ export default class Gestionnaire {
}
this._dictionnaire = new Dictionnaire();
this._motATrouver = this.choisirMot(this._datePartieEnCours);
this._grille = new Grille(this._motATrouver.length, this._maxNbPropositions, this._motATrouver[0], this._config);
this._input = new Input(this, this._motATrouver.length, this._motATrouver[0]);
this._propositions = new Array<string>();
this._resultats = new Array<Array<LettreResultat>>();
this._compositionMotATrouver = this.decompose(this._motATrouver);
this._panelManager = new PanelManager();
this._reglesPanel = new ReglesPanel(this._panelManager);
this._finDePartiePanel = new FinDePartiePanel(this._datePartieEnCours, this._panelManager);
this._configurationPanel = new ConfigurationPanel(this._panelManager);
this.chargerPropositions(partieEnCours.propositions);
this.choisirMot(this._datePartieEnCours).then((mot) => {
this._motATrouver = mot;
this._grille = new Grille(this._motATrouver.length, this._maxNbPropositions, this._motATrouver[0], this._config);
this._input = new Input(this, this._motATrouver.length, this._motATrouver[0]);
this._compositionMotATrouver = this.decompose(this._motATrouver);
this.chargerPropositions(partieEnCours.propositions);
});
this.afficherReglesSiNecessaire();
}
@ -87,8 +89,8 @@ export default class Gestionnaire {
Sauvegardeur.sauvegarderPartieEnCours(this._propositions, this._datePartieEnCours);
}
private choisirMot(datePartie: Date): string {
return this._dictionnaire.nettoyerMot(this._dictionnaire.getMot(datePartie));
private async choisirMot(datePartie: Date): Promise<string> {
return this._dictionnaire.nettoyerMot(await this._dictionnaire.getMot(datePartie));
}
private decompose(mot: string): { [lettre: string]: number } {
@ -127,19 +129,22 @@ export default class Gestionnaire {
this.enregistrerPartieDansStats();
}
this._grille.validerMot(mot, resultats, isBonneReponse, skipAnimation, () => {
this._input.updateClavier(resultats);
if (isBonneReponse || this._propositions.length === this._maxNbPropositions) {
this._input.bloquer();
this._finDePartiePanel.afficher();
}
});
if (this._grille)
this._grille.validerMot(mot, resultats, isBonneReponse, skipAnimation, () => {
if (this._input) {
this._input.updateClavier(resultats);
if (isBonneReponse || this._propositions.length === this._maxNbPropositions) {
this._input.bloquer();
this._finDePartiePanel.afficher();
}
}
});
this.sauvegarderPartieEnCours();
}
public actualiserAffichage(mot: string): void {
this._grille.actualiserAffichage(this._dictionnaire.nettoyerMot(mot));
if (this._grille) this._grille.actualiserAffichage(this._dictionnaire.nettoyerMot(mot));
}
private analyserMot(mot: string): Array<LettreResultat> {

View file

@ -1,3 +0,0 @@
export default class ListeMotsATrouver {
public static readonly Liste: Array<string> = ["DIFFUSION", "NEGATIVE", "ABSENCE", "LISTES"];
}

View file

@ -1,5 +1,6 @@
import express from "express";
import http from "http";
import fs from "fs";
const app = express();
const port = 4000;
@ -7,8 +8,23 @@ const port = 4000;
app.use("/", express.static("public/"));
app.use("/js", express.static("js/"));
app.use("/ts", express.static("ts/"));
app.use("/mots", express.static("mots/"));
app.use("/node_modules/requirejs/require.js", express.static("node_modules/requirejs/require.js"));
// Vu que le serveur node est prévu pour du test, on va créer un mot du jour s'il n'existe pas
let aujourdhui = new Date().getTime();
let origine = new Date(2022, 0, 8).getTime();
let numeroGrille = Math.floor((aujourdhui - origine) / (24 * 3600 * 1000)) + 1;
fs.access("mots/" + numeroGrille + ".txt", fs.constants.F_OK, (err) => {
if (err) {
fs.writeFile("mots/" + numeroGrille + ".txt", "DIFFUSION", (err) => {
if (err) console.error(err);
});
}
});
app.use(express.json());
const server = http.createServer(app);

View file

@ -31,6 +31,26 @@ fs.readFile("data/motsATrouve.txt", "UTF8", function (erreur, contenu) {
.join("\n");
contenu += "\n ]";
contenu += "\n}";
motsFiges
.map((mot) =>
mot
.normalize("NFD")
.replace(/\p{Diacritic}/gu, "")
.toUpperCase()
.trim()
.replace(/^\s+|\s+$/g, "")
)
.forEach((mot, numeroMot) =>
fs.access("mots/" + (numeroMot + 1) + ".txt", fs.constants.F_OK, (err) => {
if (err) {
// Dans ce cas, le fichier n'existe pas
fs.writeFile("mots/" + (numeroMot + 1) + ".txt", mot, (err) => {
if (err) console.error(err);
});
}
})
);
fs.writeFile("ts/mots/listeMotsATrouver.ts", contenu, function (err) {
if (err) {
console.error(err);