Changement du nom du fichier contenant le mot du jour
This commit is contained in:
parent
5aa7d4d60a
commit
8958752adf
|
@ -3,13 +3,21 @@ import ListeMotsProposables from "./mots/listeMotsProposables";
|
|||
export default class Dictionnaire {
|
||||
public constructor() {}
|
||||
|
||||
public static async getMot(datePartie: Date): Promise<string> {
|
||||
let aujourdhui = datePartie.getTime();
|
||||
let origine = InstanceConfiguration.dateOrigine.getTime();
|
||||
public static async getMot(idPartie: string, datePartie: Date): Promise<string> {
|
||||
return await this.getNomFichier(idPartie, datePartie)
|
||||
.then((nom) => fetch("mots/" + nom + ".txt"))
|
||||
.then((resultat) => resultat.text());
|
||||
}
|
||||
|
||||
let numeroGrille = Math.floor((aujourdhui - origine) / (24 * 3600 * 1000)) + 1;
|
||||
private static async getNomFichier(idPartie: string, datePartie: Date): Promise<string> {
|
||||
let datePartieStr =
|
||||
datePartie.getFullYear().toString() +
|
||||
"-" +
|
||||
(datePartie.getMonth() + 1).toString().padStart(2, "0") +
|
||||
"-" +
|
||||
datePartie.getDate().toString().padStart(2, "0");
|
||||
|
||||
return await fetch("mots/" + numeroGrille + ".txt").then((resultat) => resultat.text());
|
||||
return btoa(idPartie + "-" + datePartieStr);
|
||||
}
|
||||
|
||||
public static estMotValide(mot: string): boolean {
|
||||
|
|
|
@ -2,4 +2,5 @@ export default class PartieEnCours {
|
|||
public propositions: Array<string> | undefined;
|
||||
public datePartie: Date | undefined;
|
||||
public dateFinPartie: Date | undefined;
|
||||
public idPartie: string | undefined;
|
||||
}
|
||||
|
|
|
@ -2,4 +2,5 @@ export default class SauvegardePartie {
|
|||
propositions: Array<string> = [];
|
||||
datePartie: Date = new Date();
|
||||
dateFinPartie?: Date;
|
||||
idPartie?: string;
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ import ReglesPanel from "./reglesPanel";
|
|||
import ConfigurationPanel from "./configurationPanel";
|
||||
import AudioPanel from "./audioPanel";
|
||||
import ThemeManager from "./themeManager";
|
||||
import InstanceConfiguration from "./instanceConfiguration";
|
||||
|
||||
export default class Gestionnaire {
|
||||
private _grille: Grille | null = null;
|
||||
|
@ -31,6 +32,7 @@ export default class Gestionnaire {
|
|||
private _compositionMotATrouver: { [lettre: string]: number } = {};
|
||||
private _maxNbPropositions: number = 6;
|
||||
private _datePartieEnCours: Date;
|
||||
private _idPartieEnCours: string;
|
||||
private _dateFinPartie: Date | undefined;
|
||||
private _stats: SauvegardeStats = SauvegardeStats.Default;
|
||||
private _config: Configuration = Configuration.Default;
|
||||
|
@ -46,6 +48,8 @@ export default class Gestionnaire {
|
|||
this._datePartieEnCours = new Date();
|
||||
}
|
||||
|
||||
this._idPartieEnCours = this.getIdPartie(partieEnCours);
|
||||
|
||||
if (partieEnCours.dateFinPartie) {
|
||||
this._dateFinPartie = partieEnCours.dateFinPartie;
|
||||
}
|
||||
|
@ -59,7 +63,7 @@ export default class Gestionnaire {
|
|||
this._finDePartiePanel = new FinDePartiePanel(this._datePartieEnCours, this._panelManager);
|
||||
this._configurationPanel = new ConfigurationPanel(this._panelManager, this._audioPanel, this._themeManager);
|
||||
|
||||
this.choisirMot(this._datePartieEnCours).then((mot) => {
|
||||
this.choisirMot(this._idPartieEnCours, this._datePartieEnCours).then((mot) => {
|
||||
this._motATrouver = mot;
|
||||
this._input = new Input(this, this._config, this._motATrouver.length, this._motATrouver[0]);
|
||||
this._grille = new Grille(this._motATrouver.length, this._maxNbPropositions, this._motATrouver[0], this._audioPanel);
|
||||
|
@ -71,6 +75,12 @@ export default class Gestionnaire {
|
|||
this.afficherReglesSiNecessaire();
|
||||
}
|
||||
|
||||
private getIdPartie(partieEnCours: PartieEnCours) {
|
||||
if (partieEnCours.idPartie !== undefined) return partieEnCours.idPartie;
|
||||
|
||||
return InstanceConfiguration.idPartieParDefaut;
|
||||
}
|
||||
|
||||
private chargerPartieEnCours(): PartieEnCours {
|
||||
this._stats = Sauvegardeur.chargerSauvegardeStats() ?? SauvegardeStats.Default;
|
||||
|
||||
|
@ -117,11 +127,11 @@ export default class Gestionnaire {
|
|||
}
|
||||
|
||||
private sauvegarderPartieEnCours(): void {
|
||||
Sauvegardeur.sauvegarderPartieEnCours(this._propositions, this._datePartieEnCours, this._dateFinPartie);
|
||||
Sauvegardeur.sauvegarderPartieEnCours(this._idPartieEnCours, this._datePartieEnCours, this._propositions, this._dateFinPartie);
|
||||
}
|
||||
|
||||
private async choisirMot(datePartie: Date): Promise<string> {
|
||||
return Dictionnaire.nettoyerMot(await Dictionnaire.getMot(datePartie));
|
||||
private async choisirMot(idPartie: string, datePartie: Date): Promise<string> {
|
||||
return Dictionnaire.nettoyerMot(await Dictionnaire.getMot(idPartie, datePartie));
|
||||
}
|
||||
|
||||
private decompose(mot: string): { [lettre: string]: number } {
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
export default class InstanceConfiguration {
|
||||
public static readonly dateOrigine = new Date(2022, 0, 8);
|
||||
public static readonly idPartieParDefaut = "34ccc522-c264-4e51-b293-fd5bd60ef7aa";
|
||||
}
|
||||
|
|
|
@ -20,11 +20,12 @@ export default class Sauvegardeur {
|
|||
return stats;
|
||||
}
|
||||
|
||||
public static sauvegarderPartieEnCours(propositions: Array<string>, datePartie: Date, dateFinPartie?: Date): void {
|
||||
public static sauvegarderPartieEnCours(idPartie: string, datePartie: Date, propositions: Array<string>, dateFinPartie?: Date): void {
|
||||
let partieEnCours: SauvegardePartie = {
|
||||
propositions: propositions,
|
||||
datePartie,
|
||||
dateFinPartie,
|
||||
idPartie,
|
||||
};
|
||||
localStorage.setItem(this._clePartieEnCours, JSON.stringify(partieEnCours));
|
||||
}
|
||||
|
@ -50,6 +51,7 @@ export default class Sauvegardeur {
|
|||
datePartie: datePartieEnCours,
|
||||
dateFinPartie: dateFinPartie,
|
||||
propositions: partieEnCours.propositions,
|
||||
idPartie: partieEnCours.idPartie,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
16
ts/server.ts
16
ts/server.ts
|
@ -14,14 +14,20 @@ const port = parseInt(String(process.env.SUTOM_PORT), 10) || 4000;
|
|||
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 = InstanceConfiguration.dateOrigine.getTime();
|
||||
let datePartie = new Date();
|
||||
let datePartieStr =
|
||||
datePartie.getFullYear().toString() +
|
||||
"-" +
|
||||
(datePartie.getMonth() + 1).toString().padStart(2, "0") +
|
||||
"-" +
|
||||
datePartie.getDate().toString().padStart(2, "0");
|
||||
|
||||
let numeroGrille = Math.floor((aujourdhui - origine) / (24 * 3600 * 1000)) + 1;
|
||||
let nomFichier = Buffer.from(InstanceConfiguration.idPartieParDefaut + "-" + datePartieStr, "utf-8").toString("base64");
|
||||
|
||||
fs.access("mots/" + numeroGrille + ".txt", fs.constants.F_OK, (err) => {
|
||||
const adresseFichierMot = "mots/" + nomFichier + ".txt";
|
||||
fs.access(adresseFichierMot, fs.constants.F_OK, (err) => {
|
||||
if (err) {
|
||||
fs.writeFile("mots/" + numeroGrille + ".txt", "DIFFUSION", (err) => {
|
||||
fs.writeFile(adresseFichierMot, "DIFFUSION", (err) => {
|
||||
if (err) console.error(err);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -43,14 +43,28 @@ fs.readFile("data/motsATrouve.txt", "UTF8", function (erreur, contenu) {
|
|||
.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);
|
||||
});
|
||||
}
|
||||
})
|
||||
new Promise((resolve, reject) => {
|
||||
let datePartie = new Date(instanceConfiguration.default.dateOrigine);
|
||||
datePartie.setDate(datePartie.getDate() + (numeroMot + 1));
|
||||
|
||||
let datePartieStr =
|
||||
datePartie.getFullYear().toString() +
|
||||
"-" +
|
||||
(datePartie.getMonth() + 1).toString().padStart(2, "0") +
|
||||
"-" +
|
||||
datePartie.getDate().toString().padStart(2, "0");
|
||||
|
||||
return resolve(Buffer.from(instanceConfiguration.default.idPartieParDefaut + "-" + datePartieStr, "utf-8").toString("base64"));
|
||||
}).then((nomFichier) =>
|
||||
fs.access("mots/" + nomFichier + ".txt", fs.constants.F_OK, (err) => {
|
||||
if (err) {
|
||||
// Dans ce cas, le fichier n'existe pas
|
||||
fs.writeFile("mots/" + nomFichier + ".txt", mot, (err) => {
|
||||
if (err) console.error(err);
|
||||
});
|
||||
}
|
||||
})
|
||||
)
|
||||
);
|
||||
fs.writeFile("ts/mots/listeMotsATrouver.ts", contenu, function (err) {
|
||||
if (err) {
|
||||
|
|
Loading…
Reference in New Issue