mirror of
https://framagit.org/JonathanMM/sutom.git
synced 2024-06-05 07:22:38 +02:00
Changement de la méthode de récupération du mot du jour
This commit is contained in:
parent
70bc91d557
commit
e52bd0b021
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,6 +1,7 @@
|
||||||
config/
|
config/
|
||||||
data/
|
data/
|
||||||
js/
|
js/
|
||||||
|
mots/
|
||||||
node_modules/
|
node_modules/
|
||||||
ts/mots/listeMotsATrouver.*.ts
|
ts/mots/listeMotsATrouver.*.ts
|
||||||
cron.prod.sh
|
cron.prod.sh
|
||||||
|
|
2
cron.sh
Normal file → Executable file
2
cron.sh
Normal file → Executable file
|
@ -4,5 +4,3 @@ npm install
|
||||||
node utils/melangerATrouver.js
|
node utils/melangerATrouver.js
|
||||||
node utils/majATrouver.js
|
node utils/majATrouver.js
|
||||||
tsc
|
tsc
|
||||||
cp -r public/* /var/www/sutom/
|
|
||||||
cp -r js/ /var/www/sutom/
|
|
||||||
|
|
|
@ -1,15 +1,14 @@
|
||||||
import ListeMotsProposables from "./mots/listeMotsProposables";
|
import ListeMotsProposables from "./mots/listeMotsProposables";
|
||||||
import ListeMotsATrouver from "./mots/listeMotsATrouver";
|
|
||||||
export default class Dictionnaire {
|
export default class Dictionnaire {
|
||||||
public constructor() {}
|
public constructor() {}
|
||||||
|
|
||||||
public getMot(datePartie: Date): string {
|
public async getMot(datePartie: Date): Promise<string> {
|
||||||
let aujourdhui = datePartie.getTime();
|
let aujourdhui = datePartie.getTime();
|
||||||
let origine = new Date(2022, 0, 8).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 {
|
public estMotValide(mot: string): boolean {
|
||||||
|
|
|
@ -15,8 +15,8 @@ import ConfigurationPanel from "./configurationPanel";
|
||||||
|
|
||||||
export default class Gestionnaire {
|
export default class Gestionnaire {
|
||||||
private readonly _dictionnaire: Dictionnaire;
|
private readonly _dictionnaire: Dictionnaire;
|
||||||
private readonly _grille: Grille;
|
private _grille: Grille | null = null;
|
||||||
private readonly _input: Input;
|
private _input: Input | null = null;
|
||||||
private readonly _reglesPanel: ReglesPanel;
|
private readonly _reglesPanel: ReglesPanel;
|
||||||
private readonly _finDePartiePanel: FinDePartiePanel;
|
private readonly _finDePartiePanel: FinDePartiePanel;
|
||||||
private readonly _configurationPanel: ConfigurationPanel;
|
private readonly _configurationPanel: ConfigurationPanel;
|
||||||
|
@ -24,8 +24,8 @@ export default class Gestionnaire {
|
||||||
private readonly _resultats: Array<Array<LettreResultat>>;
|
private readonly _resultats: Array<Array<LettreResultat>>;
|
||||||
private readonly _panelManager: PanelManager;
|
private readonly _panelManager: PanelManager;
|
||||||
|
|
||||||
private _motATrouver: string;
|
private _motATrouver: string = "";
|
||||||
private _compositionMotATrouver: { [lettre: string]: number };
|
private _compositionMotATrouver: { [lettre: string]: number } = {};
|
||||||
private _maxNbPropositions: number = 6;
|
private _maxNbPropositions: number = 6;
|
||||||
private _datePartieEnCours: Date;
|
private _datePartieEnCours: Date;
|
||||||
private _stats: SauvegardeStats = { partiesJouees: 0, partiesGagnees: 0 };
|
private _stats: SauvegardeStats = { partiesJouees: 0, partiesGagnees: 0 };
|
||||||
|
@ -43,18 +43,20 @@ export default class Gestionnaire {
|
||||||
}
|
}
|
||||||
|
|
||||||
this._dictionnaire = new Dictionnaire();
|
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._propositions = new Array<string>();
|
||||||
this._resultats = new Array<Array<LettreResultat>>();
|
this._resultats = new Array<Array<LettreResultat>>();
|
||||||
this._compositionMotATrouver = this.decompose(this._motATrouver);
|
|
||||||
this._panelManager = new PanelManager();
|
this._panelManager = new PanelManager();
|
||||||
this._reglesPanel = new ReglesPanel(this._panelManager);
|
this._reglesPanel = new ReglesPanel(this._panelManager);
|
||||||
this._finDePartiePanel = new FinDePartiePanel(this._datePartieEnCours, this._panelManager);
|
this._finDePartiePanel = new FinDePartiePanel(this._datePartieEnCours, this._panelManager);
|
||||||
this._configurationPanel = new ConfigurationPanel(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();
|
this.afficherReglesSiNecessaire();
|
||||||
}
|
}
|
||||||
|
@ -87,8 +89,8 @@ export default class Gestionnaire {
|
||||||
Sauvegardeur.sauvegarderPartieEnCours(this._propositions, this._datePartieEnCours);
|
Sauvegardeur.sauvegarderPartieEnCours(this._propositions, this._datePartieEnCours);
|
||||||
}
|
}
|
||||||
|
|
||||||
private choisirMot(datePartie: Date): string {
|
private async choisirMot(datePartie: Date): Promise<string> {
|
||||||
return this._dictionnaire.nettoyerMot(this._dictionnaire.getMot(datePartie));
|
return this._dictionnaire.nettoyerMot(await this._dictionnaire.getMot(datePartie));
|
||||||
}
|
}
|
||||||
|
|
||||||
private decompose(mot: string): { [lettre: string]: number } {
|
private decompose(mot: string): { [lettre: string]: number } {
|
||||||
|
@ -127,19 +129,22 @@ export default class Gestionnaire {
|
||||||
this.enregistrerPartieDansStats();
|
this.enregistrerPartieDansStats();
|
||||||
}
|
}
|
||||||
|
|
||||||
this._grille.validerMot(mot, resultats, isBonneReponse, skipAnimation, () => {
|
if (this._grille)
|
||||||
this._input.updateClavier(resultats);
|
this._grille.validerMot(mot, resultats, isBonneReponse, skipAnimation, () => {
|
||||||
if (isBonneReponse || this._propositions.length === this._maxNbPropositions) {
|
if (this._input) {
|
||||||
this._input.bloquer();
|
this._input.updateClavier(resultats);
|
||||||
this._finDePartiePanel.afficher();
|
if (isBonneReponse || this._propositions.length === this._maxNbPropositions) {
|
||||||
}
|
this._input.bloquer();
|
||||||
});
|
this._finDePartiePanel.afficher();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
this.sauvegarderPartieEnCours();
|
this.sauvegarderPartieEnCours();
|
||||||
}
|
}
|
||||||
|
|
||||||
public actualiserAffichage(mot: string): void {
|
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> {
|
private analyserMot(mot: string): Array<LettreResultat> {
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
export default class ListeMotsATrouver {
|
|
||||||
public static readonly Liste: Array<string> = ["DIFFUSION", "NEGATIVE", "ABSENCE", "LISTES"];
|
|
||||||
}
|
|
16
ts/server.ts
16
ts/server.ts
|
@ -1,5 +1,6 @@
|
||||||
import express from "express";
|
import express from "express";
|
||||||
import http from "http";
|
import http from "http";
|
||||||
|
import fs from "fs";
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
const port = 4000;
|
const port = 4000;
|
||||||
|
@ -7,8 +8,23 @@ const port = 4000;
|
||||||
app.use("/", express.static("public/"));
|
app.use("/", express.static("public/"));
|
||||||
app.use("/js", express.static("js/"));
|
app.use("/js", express.static("js/"));
|
||||||
app.use("/ts", express.static("ts/"));
|
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"));
|
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());
|
app.use(express.json());
|
||||||
const server = http.createServer(app);
|
const server = http.createServer(app);
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,26 @@ fs.readFile("data/motsATrouve.txt", "UTF8", function (erreur, contenu) {
|
||||||
.join("\n");
|
.join("\n");
|
||||||
contenu += "\n ]";
|
contenu += "\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) {
|
fs.writeFile("ts/mots/listeMotsATrouver.ts", contenu, function (err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
|
|
Loading…
Reference in a new issue