mirror of
https://framagit.org/JonathanMM/sutom.git
synced 2024-06-08 00:42:19 +02:00
parent
bab13f2fdc
commit
115f28c45f
|
@ -3,7 +3,7 @@ import ListeMotsProposables from "./mots/listeMotsProposables";
|
||||||
export default class Dictionnaire {
|
export default class Dictionnaire {
|
||||||
public constructor() {}
|
public constructor() {}
|
||||||
|
|
||||||
public async getMot(datePartie: Date): Promise<string> {
|
public static async getMot(datePartie: Date): Promise<string> {
|
||||||
let aujourdhui = datePartie.getTime();
|
let aujourdhui = datePartie.getTime();
|
||||||
let origine = InstanceConfiguration.dateOrigine.getTime();
|
let origine = InstanceConfiguration.dateOrigine.getTime();
|
||||||
|
|
||||||
|
@ -12,12 +12,12 @@ export default class Dictionnaire {
|
||||||
return await fetch("mots/" + numeroGrille + ".txt").then((resultat) => resultat.text());
|
return await fetch("mots/" + numeroGrille + ".txt").then((resultat) => resultat.text());
|
||||||
}
|
}
|
||||||
|
|
||||||
public estMotValide(mot: string): boolean {
|
public static estMotValide(mot: string): boolean {
|
||||||
mot = this.nettoyerMot(mot);
|
mot = this.nettoyerMot(mot);
|
||||||
return mot.length >= 6 && mot.length <= 9 && ListeMotsProposables.Dictionnaire.includes(mot);
|
return mot.length >= 6 && mot.length <= 9 && ListeMotsProposables.Dictionnaire.includes(mot);
|
||||||
}
|
}
|
||||||
|
|
||||||
public nettoyerMot(mot: string): string {
|
public static nettoyerMot(mot: string): string {
|
||||||
return mot
|
return mot
|
||||||
.normalize("NFD")
|
.normalize("NFD")
|
||||||
.replace(/[\u0300-\u036f]/g, "")
|
.replace(/[\u0300-\u036f]/g, "")
|
||||||
|
|
|
@ -16,7 +16,6 @@ import AudioPanel from "./audioPanel";
|
||||||
import ThemeManager from "./themeManager";
|
import ThemeManager from "./themeManager";
|
||||||
|
|
||||||
export default class Gestionnaire {
|
export default class Gestionnaire {
|
||||||
private readonly _dictionnaire: Dictionnaire;
|
|
||||||
private _grille: Grille | null = null;
|
private _grille: Grille | null = null;
|
||||||
private _input: Input | null = null;
|
private _input: Input | null = null;
|
||||||
private readonly _reglesPanel: ReglesPanel;
|
private readonly _reglesPanel: ReglesPanel;
|
||||||
|
@ -46,7 +45,6 @@ export default class Gestionnaire {
|
||||||
this._datePartieEnCours = new Date();
|
this._datePartieEnCours = new Date();
|
||||||
}
|
}
|
||||||
|
|
||||||
this._dictionnaire = new Dictionnaire();
|
|
||||||
this._propositions = new Array<string>();
|
this._propositions = new Array<string>();
|
||||||
this._resultats = new Array<Array<LettreResultat>>();
|
this._resultats = new Array<Array<LettreResultat>>();
|
||||||
this._audioPanel = new AudioPanel(this._config);
|
this._audioPanel = new AudioPanel(this._config);
|
||||||
|
@ -58,8 +56,8 @@ export default class Gestionnaire {
|
||||||
|
|
||||||
this.choisirMot(this._datePartieEnCours).then((mot) => {
|
this.choisirMot(this._datePartieEnCours).then((mot) => {
|
||||||
this._motATrouver = mot;
|
this._motATrouver = mot;
|
||||||
this._grille = new Grille(this._motATrouver.length, this._maxNbPropositions, this._motATrouver[0], this._audioPanel);
|
|
||||||
this._input = new Input(this, this._config, this._motATrouver.length, this._motATrouver[0]);
|
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);
|
||||||
this._configurationPanel.setInput(this._input);
|
this._configurationPanel.setInput(this._input);
|
||||||
this._compositionMotATrouver = this.decompose(this._motATrouver);
|
this._compositionMotATrouver = this.decompose(this._motATrouver);
|
||||||
this.chargerPropositions(partieEnCours.propositions);
|
this.chargerPropositions(partieEnCours.propositions);
|
||||||
|
@ -118,7 +116,7 @@ export default class Gestionnaire {
|
||||||
}
|
}
|
||||||
|
|
||||||
private async choisirMot(datePartie: Date): Promise<string> {
|
private async choisirMot(datePartie: Date): Promise<string> {
|
||||||
return this._dictionnaire.nettoyerMot(await this._dictionnaire.getMot(datePartie));
|
return Dictionnaire.nettoyerMot(await Dictionnaire.getMot(datePartie));
|
||||||
}
|
}
|
||||||
|
|
||||||
private decompose(mot: string): { [lettre: string]: number } {
|
private decompose(mot: string): { [lettre: string]: number } {
|
||||||
|
@ -132,8 +130,8 @@ export default class Gestionnaire {
|
||||||
}
|
}
|
||||||
|
|
||||||
public verifierMot(mot: string, chargementPartie: boolean = false): void {
|
public verifierMot(mot: string, chargementPartie: boolean = false): void {
|
||||||
mot = this._dictionnaire.nettoyerMot(mot);
|
mot = Dictionnaire.nettoyerMot(mot);
|
||||||
//console.debug(mot + " => " + (this._dictionnaire.estMotValide(mot) ? "Oui" : "non"));
|
//console.debug(mot + " => " + (Dictionnaire.estMotValide(mot) ? "Oui" : "non"));
|
||||||
if (mot.length !== this._motATrouver.length) {
|
if (mot.length !== this._motATrouver.length) {
|
||||||
NotificationMessage.ajouterNotification("Le mot proposé est trop court");
|
NotificationMessage.ajouterNotification("Le mot proposé est trop court");
|
||||||
return;
|
return;
|
||||||
|
@ -142,7 +140,7 @@ export default class Gestionnaire {
|
||||||
NotificationMessage.ajouterNotification("Le mot proposé doit commencer par la même lettre que le mot recherché");
|
NotificationMessage.ajouterNotification("Le mot proposé doit commencer par la même lettre que le mot recherché");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!this._dictionnaire.estMotValide(mot)) {
|
if (!Dictionnaire.estMotValide(mot)) {
|
||||||
NotificationMessage.ajouterNotification("Ce mot n'est pas dans notre dictionnaire");
|
NotificationMessage.ajouterNotification("Ce mot n'est pas dans notre dictionnaire");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -157,22 +155,26 @@ export default class Gestionnaire {
|
||||||
if (!chargementPartie) this.enregistrerPartieDansStats();
|
if (!chargementPartie) this.enregistrerPartieDansStats();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this._grille)
|
if (this._grille) {
|
||||||
|
if (this._input) this._input.bloquer();
|
||||||
this._grille.validerMot(mot, resultats, isBonneReponse, chargementPartie, () => {
|
this._grille.validerMot(mot, resultats, isBonneReponse, chargementPartie, () => {
|
||||||
if (this._input) {
|
if (this._input) {
|
||||||
this._input.updateClavier(resultats);
|
this._input.updateClavier(resultats);
|
||||||
if (isBonneReponse || this._propositions.length === this._maxNbPropositions) {
|
if (isBonneReponse || this._propositions.length === this._maxNbPropositions) {
|
||||||
this._input.bloquer();
|
this._input.bloquer();
|
||||||
this._finDePartiePanel.afficher();
|
this._finDePartiePanel.afficher();
|
||||||
|
} else {
|
||||||
|
this._input.debloquer();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
this.sauvegarderPartieEnCours();
|
this.sauvegarderPartieEnCours();
|
||||||
}
|
}
|
||||||
|
|
||||||
public actualiserAffichage(mot: string): void {
|
public actualiserAffichage(mot: string): void {
|
||||||
if (this._grille) this._grille.actualiserAffichage(this._dictionnaire.nettoyerMot(mot));
|
if (this._grille) this._grille.actualiserAffichage(Dictionnaire.nettoyerMot(mot));
|
||||||
}
|
}
|
||||||
|
|
||||||
private analyserMot(mot: string): Array<LettreResultat> {
|
private analyserMot(mot: string): Array<LettreResultat> {
|
||||||
|
|
|
@ -3,6 +3,7 @@ import LettreResultat from "./entites/lettreResultat";
|
||||||
import { LettreStatut } from "./entites/lettreStatut";
|
import { LettreStatut } from "./entites/lettreStatut";
|
||||||
import { ClavierDisposition } from "./entites/clavierDisposition";
|
import { ClavierDisposition } from "./entites/clavierDisposition";
|
||||||
import Configuration from "./entites/configuration";
|
import Configuration from "./entites/configuration";
|
||||||
|
import Dictionnaire from "./dictionnaire";
|
||||||
|
|
||||||
export default class Input {
|
export default class Input {
|
||||||
private readonly _grille: HTMLElement;
|
private readonly _grille: HTMLElement;
|
||||||
|
@ -128,7 +129,7 @@ export default class Input {
|
||||||
|
|
||||||
if (touche === "Enter") {
|
if (touche === "Enter") {
|
||||||
this.validerMot();
|
this.validerMot();
|
||||||
} else if (touche !== "Backspace") {
|
} else if (/^[A-Z]+$/.test(Dictionnaire.nettoyerMot(touche))) {
|
||||||
this.saisirLettre(touche);
|
this.saisirLettre(touche);
|
||||||
}
|
}
|
||||||
}).bind(this)
|
}).bind(this)
|
||||||
|
@ -177,6 +178,10 @@ export default class Input {
|
||||||
this._estBloque = true;
|
this._estBloque = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public debloquer(): void {
|
||||||
|
this._estBloque = false;
|
||||||
|
}
|
||||||
|
|
||||||
public updateClavier(resultats: Array<LettreResultat>): void {
|
public updateClavier(resultats: Array<LettreResultat>): void {
|
||||||
this._resultats = resultats; // On sauvegarde au cas où on doit redessiner tout le clavier
|
this._resultats = resultats; // On sauvegarde au cas où on doit redessiner tout le clavier
|
||||||
let statutLettres: { [lettre: string]: LettreStatut } = {};
|
let statutLettres: { [lettre: string]: LettreStatut } = {};
|
||||||
|
|
Loading…
Reference in a new issue