mirror of
https://framagit.org/JonathanMM/sutom.git
synced 2024-06-10 09:52:13 +02:00
Fix #51 : Blocage du clavier en fin de partie même si on ferme le panel
This commit is contained in:
parent
8c347a8553
commit
2149d9dbe3
|
@ -1,6 +1,6 @@
|
||||||
import Dictionnaire from "./dictionnaire";
|
import Dictionnaire from "./dictionnaire";
|
||||||
import Grille from "./grille";
|
import Grille from "./grille";
|
||||||
import Input from "./input";
|
import Input, { ContexteBloquage } from "./input";
|
||||||
import LettreResultat from "./entites/lettreResultat";
|
import LettreResultat from "./entites/lettreResultat";
|
||||||
import { LettreStatut } from "./entites/lettreStatut";
|
import { LettreStatut } from "./entites/lettreStatut";
|
||||||
import FinDePartiePanel from "./finDePartiePanel";
|
import FinDePartiePanel from "./finDePartiePanel";
|
||||||
|
@ -194,15 +194,15 @@ export default class Gestionnaire {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this._grille) {
|
if (this._grille) {
|
||||||
if (this._input) this._input.bloquer();
|
if (this._input) this._input.bloquer(ContexteBloquage.ValidationMot);
|
||||||
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(ContexteBloquage.ValidationMot);
|
||||||
this._finDePartiePanel.afficher();
|
this._finDePartiePanel.afficher();
|
||||||
} else {
|
} else {
|
||||||
this._input.debloquer();
|
this._input.debloquer(ContexteBloquage.ValidationMot);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
27
ts/input.ts
27
ts/input.ts
|
@ -5,6 +5,11 @@ import { ClavierDisposition } from "./entites/clavierDisposition";
|
||||||
import Configuration from "./entites/configuration";
|
import Configuration from "./entites/configuration";
|
||||||
import Dictionnaire from "./dictionnaire";
|
import Dictionnaire from "./dictionnaire";
|
||||||
|
|
||||||
|
export enum ContexteBloquage {
|
||||||
|
ValidationMot,
|
||||||
|
Panel,
|
||||||
|
}
|
||||||
|
|
||||||
export default class Input {
|
export default class Input {
|
||||||
private readonly _grille: HTMLElement;
|
private readonly _grille: HTMLElement;
|
||||||
private readonly _inputArea: HTMLElement;
|
private readonly _inputArea: HTMLElement;
|
||||||
|
@ -13,7 +18,7 @@ export default class Input {
|
||||||
|
|
||||||
private _longueurMot: number;
|
private _longueurMot: number;
|
||||||
private _motSaisi: string;
|
private _motSaisi: string;
|
||||||
private _estBloque: boolean;
|
private _estBloque: Array<ContexteBloquage>; // TODO : Faire un dictionnaire pour savoir qui bloque, pour que si c'est bloqué par finDePartie, et que la fermeture de panel essaye de débloquer, ça ne fasse rien
|
||||||
private _resultats: Array<Array<LettreResultat>>;
|
private _resultats: Array<Array<LettreResultat>>;
|
||||||
|
|
||||||
public constructor(gestionnaire: Gestionnaire, configuration: Configuration, longueurMot: number, premiereLettre: string) {
|
public constructor(gestionnaire: Gestionnaire, configuration: Configuration, longueurMot: number, premiereLettre: string) {
|
||||||
|
@ -23,7 +28,7 @@ export default class Input {
|
||||||
this._longueurMot = longueurMot;
|
this._longueurMot = longueurMot;
|
||||||
this._gestionnaire = gestionnaire;
|
this._gestionnaire = gestionnaire;
|
||||||
this._motSaisi = "";
|
this._motSaisi = "";
|
||||||
this._estBloque = false;
|
this._estBloque = new Array<ContexteBloquage>();
|
||||||
this._resultats = new Array<Array<LettreResultat>>();
|
this._resultats = new Array<Array<LettreResultat>>();
|
||||||
|
|
||||||
this.ajouterEvenementClavierPhysique();
|
this.ajouterEvenementClavierPhysique();
|
||||||
|
@ -151,7 +156,7 @@ export default class Input {
|
||||||
}
|
}
|
||||||
|
|
||||||
private effacerLettre(): void {
|
private effacerLettre(): void {
|
||||||
if (this._estBloque) return;
|
if (this.estBloque()) return;
|
||||||
if (this._motSaisi.length !== 0) {
|
if (this._motSaisi.length !== 0) {
|
||||||
this._motSaisi = this._motSaisi.substring(0, this._motSaisi.length - 1);
|
this._motSaisi = this._motSaisi.substring(0, this._motSaisi.length - 1);
|
||||||
}
|
}
|
||||||
|
@ -159,26 +164,30 @@ export default class Input {
|
||||||
}
|
}
|
||||||
|
|
||||||
private async validerMot(): Promise<void> {
|
private async validerMot(): Promise<void> {
|
||||||
if (this._estBloque) return;
|
if (this.estBloque()) return;
|
||||||
let mot = this._motSaisi;
|
let mot = this._motSaisi;
|
||||||
let isMotValide = await this._gestionnaire.verifierMot(mot);
|
let isMotValide = await this._gestionnaire.verifierMot(mot);
|
||||||
if (isMotValide) this._motSaisi = "";
|
if (isMotValide) this._motSaisi = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
private saisirLettre(lettre: string): void {
|
private saisirLettre(lettre: string): void {
|
||||||
if (this._estBloque) return;
|
if (this.estBloque()) return;
|
||||||
if (this._motSaisi.length >= this._longueurMot) return;
|
if (this._motSaisi.length >= this._longueurMot) return;
|
||||||
if (this._motSaisi.length === 0 && lettre.toUpperCase() !== this._premiereLettre) this._motSaisi += this._premiereLettre;
|
if (this._motSaisi.length === 0 && lettre.toUpperCase() !== this._premiereLettre) this._motSaisi += this._premiereLettre;
|
||||||
this._motSaisi += lettre;
|
this._motSaisi += lettre;
|
||||||
this._gestionnaire.actualiserAffichage(this._motSaisi);
|
this._gestionnaire.actualiserAffichage(this._motSaisi);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bloquer(): void {
|
public bloquer(contexte: ContexteBloquage): void {
|
||||||
this._estBloque = true;
|
if (!this._estBloque.includes(contexte)) this._estBloque.push(contexte);
|
||||||
}
|
}
|
||||||
|
|
||||||
public debloquer(): void {
|
public debloquer(contexte: ContexteBloquage): void {
|
||||||
this._estBloque = false;
|
if (this._estBloque.includes(contexte)) this._estBloque.splice(this._estBloque.indexOf(contexte), 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
private estBloque(): boolean {
|
||||||
|
return this._estBloque.length > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public updateClavier(resultats: Array<LettreResultat>): void {
|
public updateClavier(resultats: Array<LettreResultat>): void {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import Input from "./input";
|
import Input, { ContexteBloquage } from "./input";
|
||||||
|
|
||||||
export default class PanelManager {
|
export default class PanelManager {
|
||||||
private readonly _panelArea: HTMLElement;
|
private readonly _panelArea: HTMLElement;
|
||||||
|
@ -46,12 +46,12 @@ export default class PanelManager {
|
||||||
|
|
||||||
public afficherPanel(): void {
|
public afficherPanel(): void {
|
||||||
this._panelArea.style.display = "block";
|
this._panelArea.style.display = "block";
|
||||||
if (this._input) this._input.bloquer();
|
if (this._input) this._input.bloquer(ContexteBloquage.Panel);
|
||||||
}
|
}
|
||||||
|
|
||||||
public cacherPanel(): void {
|
public cacherPanel(): void {
|
||||||
this._panelArea.style.display = "none";
|
this._panelArea.style.display = "none";
|
||||||
if (this._input) this._input.debloquer();
|
if (this._input) this._input.debloquer(ContexteBloquage.Panel);
|
||||||
}
|
}
|
||||||
|
|
||||||
public setContenu(titre: string, contenu: string): void {
|
public setContenu(titre: string, contenu: string): void {
|
||||||
|
|
Loading…
Reference in a new issue