Close #22 : Ajout d'un chrono (activable) dans le résumé
This commit is contained in:
parent
56a6c39ba2
commit
5aa7d4d60a
|
@ -107,6 +107,26 @@ export default class ConfigurationPanel {
|
|||
)
|
||||
);
|
||||
|
||||
contenu.appendChild(
|
||||
this.genererConfigItem(
|
||||
"Afficher le temps sur le résumé (à la prochaine partie)",
|
||||
[
|
||||
{ value: false.toString(), label: "Non" },
|
||||
{ value: true.toString(), label: "Oui" },
|
||||
],
|
||||
(config.afficherChrono ?? Configuration.Default.afficherChrono).toString(),
|
||||
(event: Event) => {
|
||||
event.stopPropagation();
|
||||
let afficherChrono = (event.target as HTMLSelectElement).value === true.toString();
|
||||
|
||||
Sauvegardeur.sauvegarderConfig({
|
||||
...(Sauvegardeur.chargerConfig() ?? Configuration.Default),
|
||||
afficherChrono,
|
||||
});
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
this._panelManager.setContenuHtmlElement(titre, contenu);
|
||||
this._panelManager.setClasses(["config-panel"]);
|
||||
this._panelManager.afficherPanel();
|
||||
|
|
|
@ -6,6 +6,7 @@ export default class Configuration {
|
|||
public static Default: Configuration = {
|
||||
hasAudio: false,
|
||||
afficherRegles: true,
|
||||
afficherChrono: false,
|
||||
volumeSon: VolumeSon.Normal,
|
||||
disposition: ClavierDisposition.Azerty,
|
||||
theme: Theme.Sombre,
|
||||
|
@ -13,6 +14,7 @@ export default class Configuration {
|
|||
|
||||
hasAudio: boolean = false;
|
||||
afficherRegles: boolean = true;
|
||||
afficherChrono: boolean = false;
|
||||
volumeSon: VolumeSon = VolumeSon.Normal;
|
||||
disposition: ClavierDisposition = ClavierDisposition.Azerty;
|
||||
theme: Theme = Theme.Sombre;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
export default class PartieEnCours {
|
||||
public propositions: Array<string> | undefined;
|
||||
public datePartie: Date | undefined;
|
||||
public dateFinPartie: Date | undefined;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
export default class SauvegardePartie {
|
||||
propositions: Array<string> = [];
|
||||
datePartie: Date = new Date();
|
||||
dateFinPartie?: Date;
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import Configuration from "./entites/configuration";
|
||||
import LettreResultat from "./entites/lettreResultat";
|
||||
import { LettreStatut } from "./entites/lettreStatut";
|
||||
import InstanceConfiguration from "./instanceConfiguration";
|
||||
|
@ -29,7 +30,7 @@ export default class FinDePartiePanel {
|
|||
);
|
||||
}
|
||||
|
||||
public genererResume(estBonneReponse: boolean, motATrouver: string, resultats: Array<Array<LettreResultat>>): void {
|
||||
public genererResume(estBonneReponse: boolean, motATrouver: string, resultats: Array<Array<LettreResultat>>, dureeMs: number): void {
|
||||
let resultatsEmojis = resultats.map((mot) =>
|
||||
mot
|
||||
.map((resultat) => resultat.statut)
|
||||
|
@ -67,8 +68,38 @@ export default class FinDePartiePanel {
|
|||
|
||||
let numeroGrille = Math.floor((dateGrille - origine) / (24 * 3600 * 1000)) + 1;
|
||||
|
||||
this._resumeTexte = "SUTOM #" + numeroGrille + " " + (estBonneReponse ? resultats.length : "-") + "/6\n\n" + resultatsEmojis.join("\n");
|
||||
this._resumeTexteLegacy = "SUTOM #" + numeroGrille + " " + (estBonneReponse ? resultats.length : "-") + "/6\n\n" + resultatsEmojisLegacy.join("\n");
|
||||
let afficherChrono = (Sauvegardeur.chargerConfig() ?? Configuration.Default).afficherChrono;
|
||||
|
||||
const entete =
|
||||
"SUTOM #" +
|
||||
numeroGrille +
|
||||
" " +
|
||||
(estBonneReponse ? resultats.length : "-") +
|
||||
"/6" +
|
||||
(afficherChrono ? " " + this.genererTempsHumain(dureeMs) : "") +
|
||||
"\n\n";
|
||||
this._resumeTexte = entete + resultatsEmojis.join("\n");
|
||||
this._resumeTexteLegacy = entete + resultatsEmojisLegacy.join("\n");
|
||||
}
|
||||
|
||||
private genererTempsHumain(dureeMs: number): string {
|
||||
// Note : Durée est en millisecondes.
|
||||
let duree = Math.floor(dureeMs / 1000);
|
||||
let retour = "";
|
||||
|
||||
if (duree >= 3600) {
|
||||
retour += Math.floor(duree / 3600) + "h";
|
||||
}
|
||||
|
||||
retour +=
|
||||
Math.floor((duree / 60) % 60)
|
||||
.toString()
|
||||
.padStart(2, "0") + ":";
|
||||
retour += Math.floor(duree / 60)
|
||||
.toString()
|
||||
.padStart(2, "0");
|
||||
|
||||
return retour;
|
||||
}
|
||||
|
||||
private attacherPartage(): void {
|
||||
|
|
|
@ -31,6 +31,7 @@ export default class Gestionnaire {
|
|||
private _compositionMotATrouver: { [lettre: string]: number } = {};
|
||||
private _maxNbPropositions: number = 6;
|
||||
private _datePartieEnCours: Date;
|
||||
private _dateFinPartie: Date | undefined;
|
||||
private _stats: SauvegardeStats = SauvegardeStats.Default;
|
||||
private _config: Configuration = Configuration.Default;
|
||||
|
||||
|
@ -45,6 +46,10 @@ export default class Gestionnaire {
|
|||
this._datePartieEnCours = new Date();
|
||||
}
|
||||
|
||||
if (partieEnCours.dateFinPartie) {
|
||||
this._dateFinPartie = partieEnCours.dateFinPartie;
|
||||
}
|
||||
|
||||
this._propositions = new Array<string>();
|
||||
this._resultats = new Array<Array<LettreResultat>>();
|
||||
this._audioPanel = new AudioPanel(this._config);
|
||||
|
@ -112,7 +117,7 @@ export default class Gestionnaire {
|
|||
}
|
||||
|
||||
private sauvegarderPartieEnCours(): void {
|
||||
Sauvegardeur.sauvegarderPartieEnCours(this._propositions, this._datePartieEnCours);
|
||||
Sauvegardeur.sauvegarderPartieEnCours(this._propositions, this._datePartieEnCours, this._dateFinPartie);
|
||||
}
|
||||
|
||||
private async choisirMot(datePartie: Date): Promise<string> {
|
||||
|
@ -151,7 +156,9 @@ export default class Gestionnaire {
|
|||
this._resultats.push(resultats);
|
||||
|
||||
if (isBonneReponse || this._propositions.length === this._maxNbPropositions) {
|
||||
this._finDePartiePanel.genererResume(isBonneReponse, this._motATrouver, this._resultats);
|
||||
if (!this._dateFinPartie) this._dateFinPartie = new Date();
|
||||
let duree = this._dateFinPartie.getTime() - this._datePartieEnCours.getTime();
|
||||
this._finDePartiePanel.genererResume(isBonneReponse, this._motATrouver, this._resultats, duree);
|
||||
if (!chargementPartie) this.enregistrerPartieDansStats();
|
||||
}
|
||||
|
||||
|
|
|
@ -20,10 +20,11 @@ export default class Sauvegardeur {
|
|||
return stats;
|
||||
}
|
||||
|
||||
public static sauvegarderPartieEnCours(propositions: Array<string>, datePartie: Date): void {
|
||||
public static sauvegarderPartieEnCours(propositions: Array<string>, datePartie: Date, dateFinPartie?: Date): void {
|
||||
let partieEnCours: SauvegardePartie = {
|
||||
propositions: propositions,
|
||||
datePartie,
|
||||
dateFinPartie,
|
||||
};
|
||||
localStorage.setItem(this._clePartieEnCours, JSON.stringify(partieEnCours));
|
||||
}
|
||||
|
@ -43,8 +44,11 @@ export default class Sauvegardeur {
|
|||
localStorage.removeItem(this._clePartieEnCours);
|
||||
return;
|
||||
}
|
||||
let dateFinPartie = partieEnCours.dateFinPartie === undefined ? undefined : new Date(partieEnCours.dateFinPartie);
|
||||
|
||||
return {
|
||||
datePartie: datePartieEnCours,
|
||||
dateFinPartie: dateFinPartie,
|
||||
propositions: partieEnCours.propositions,
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue