mirror of
https://framagit.org/JonathanMM/sutom.git
synced 2024-05-02 06:02:58 +02:00
Ajout de la possibilité de jouer à la partie de la veille
This commit is contained in:
parent
b9b83c9b79
commit
e6c67a52f0
|
@ -101,6 +101,11 @@
|
|||
d="M216 960q-29.7 0-50.85-21.15Q144 917.7 144 888V336h72v552h456v72H216Zm144-144q-29.7 0-50.85-21.15Q288 773.7 288 744V264q0-29.7 21.15-50.85Q330.3 192 360 192h384q29.7 0 50.85 21.15Q816 234.3 816 264v480q0 29.7-21.15 50.85Q773.7 816 744 816H360Zm0-72h384V264H360v480Zm0 0V264v480Z"
|
||||
/>
|
||||
</symbol>
|
||||
<symbol id="icone-restaure" height="20" viewBox="0 96 960 960" width="20">
|
||||
<path
|
||||
d="M479.788 648Q450 648 429 626.788q-21-21.213-21-51Q408 546 429.212 525q21.213-21 51-21Q510 504 531 525.212q21 21.213 21 51Q552 606 530.788 627q-21.213 21-51 21ZM480 912q-140 0-238.5-98T144 576h72q2 110 78.5 187T480 840q110.314 0 187.157-76.778Q744 686.443 744 576.222 744 466 667.157 389 590.314 312 480 312q-59 0-111.5 25.5T277 408h107v72H144V240h72v130q47.909-62.09 116.955-96.045Q402 240 480 240q70 0 131.133 26.6 61.134 26.6 106.4 71.867 45.267 45.266 71.867 106.4Q816 506 816 576t-26.6 131.133q-26.6 61.134-71.867 106.4-45.266 45.267-106.4 71.867Q550 912 480 912Z"
|
||||
/>
|
||||
</symbol>
|
||||
</svg>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -435,7 +435,7 @@ h1 {
|
|||
}
|
||||
|
||||
.stats-numerique-case-valeur {
|
||||
font-size: 28px;
|
||||
font-size: 24px;
|
||||
}
|
||||
|
||||
.stats-numerique-case-secondaire {
|
||||
|
@ -477,16 +477,26 @@ h1 {
|
|||
text-align: start;
|
||||
}
|
||||
|
||||
#fin-de-partie-panel-partie-veille-area {
|
||||
text-align: start;
|
||||
}
|
||||
|
||||
#fin-de-partie-panel-resume-bouton,
|
||||
#fin-de-partie-panel-stats-bouton,
|
||||
#fin-de-partie-panel-reset-bouton {
|
||||
font-size: 1rem;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
#fin-de-partie-panel-resume-bouton,
|
||||
#fin-de-partie-panel-stats-bouton {
|
||||
font-size: 1rem;
|
||||
margin-left: 1rem;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.bouton-partage-texte {
|
||||
bottom: 4px;
|
||||
position: absolute;
|
||||
width: max-content;
|
||||
}
|
||||
|
||||
#config-sauvegarde-area {
|
||||
|
|
|
@ -29,6 +29,10 @@ export default class CopieHelper {
|
|||
}
|
||||
|
||||
public static creerBoutonPartage(idBouton: string, label?: string): HTMLElement {
|
||||
return this.creerBoutonAvecIcone(idBouton, "#icone-copie", label);
|
||||
}
|
||||
|
||||
public static creerBoutonAvecIcone(idBouton: string, icone: string, label?: string): HTMLElement {
|
||||
const lien = document.createElement("a");
|
||||
lien.id = idBouton;
|
||||
lien.className = "bouton-partage";
|
||||
|
@ -36,7 +40,7 @@ export default class CopieHelper {
|
|||
|
||||
const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
||||
const useSvg = document.createElementNS("http://www.w3.org/2000/svg", "use") as SVGUseElement;
|
||||
useSvg.setAttribute("href", "#icone-copie");
|
||||
useSvg.setAttribute("href", icone);
|
||||
useSvg.setAttribute("stroke", "var(--couleur-icone)");
|
||||
useSvg.setAttribute("fill", "var(--couleur-icone)");
|
||||
svg.appendChild(useSvg);
|
||||
|
|
|
@ -3,6 +3,7 @@ import Configuration from "./entites/configuration";
|
|||
import LettreResultat from "./entites/lettreResultat";
|
||||
import { LettreStatut } from "./entites/lettreStatut";
|
||||
import SauvegardeStats from "./entites/sauvegardeStats";
|
||||
import Gestionnaire from "./gestionnaire";
|
||||
import InstanceConfiguration from "./instanceConfiguration";
|
||||
import PanelManager from "./panelManager";
|
||||
import Sauvegardeur from "./sauvegardeur";
|
||||
|
@ -12,6 +13,7 @@ export default class FinDePartiePanel {
|
|||
private readonly _datePartie: Date;
|
||||
private readonly _panelManager: PanelManager;
|
||||
private readonly _statsButton: HTMLElement;
|
||||
private readonly _gestionnaire: Gestionnaire;
|
||||
|
||||
private _resumeTexte: string = "";
|
||||
private _resumeTexteLegacy: string = "";
|
||||
|
@ -19,11 +21,12 @@ export default class FinDePartiePanel {
|
|||
private _estVictoire: boolean = false;
|
||||
private _partieEstFinie: boolean = false;
|
||||
|
||||
public constructor(datePartie: Date, panelManager: PanelManager) {
|
||||
public constructor(datePartie: Date, panelManager: PanelManager, gestionnaire: Gestionnaire) {
|
||||
this._datePartie = new Date(datePartie);
|
||||
this._datePartie.setHours(0, 0, 0);
|
||||
this._panelManager = panelManager;
|
||||
this._statsButton = document.getElementById("configuration-stats-bouton") as HTMLElement;
|
||||
this._gestionnaire = gestionnaire;
|
||||
|
||||
this._statsButton.addEventListener(
|
||||
"click",
|
||||
|
@ -132,6 +135,19 @@ export default class FinDePartiePanel {
|
|||
</p>";
|
||||
}
|
||||
contenu += StatistiquesDisplayer.genererResumeTexte(this._resumeTexteLegacy).outerHTML;
|
||||
|
||||
if (Sauvegardeur.hasPartieVeilleNonTerminee()) {
|
||||
const partieVeilleArea = document.createElement("div");
|
||||
partieVeilleArea.id = "fin-de-partie-panel-partie-veille-area";
|
||||
|
||||
const partieVeilleLabel = document.createElement("div");
|
||||
partieVeilleLabel.innerText = "Il semblerait que vous n'avez pas terminé votre partie d'hier…";
|
||||
partieVeilleArea.appendChild(partieVeilleLabel);
|
||||
|
||||
partieVeilleArea.appendChild(CopieHelper.creerBoutonAvecIcone("fin-de-partie-panel-reset-bouton", "#icone-restaure", "Terminer la partie"));
|
||||
|
||||
contenu += partieVeilleArea.outerHTML;
|
||||
}
|
||||
}
|
||||
|
||||
let stats = Sauvegardeur.chargerSauvegardeStats();
|
||||
|
@ -143,6 +159,19 @@ export default class FinDePartiePanel {
|
|||
this._panelManager.setClasses(["fin-de-partie-panel"]);
|
||||
if (this._partieEstFinie) this.attacherPartage();
|
||||
if (stats) this.attacherPartageStats(stats);
|
||||
|
||||
const resetButton = document.getElementById("fin-de-partie-panel-reset-bouton") as HTMLElement;
|
||||
if (resetButton) {
|
||||
const veille = new Date();
|
||||
veille.setDate(veille.getDate() - 1);
|
||||
resetButton.addEventListener(
|
||||
"click",
|
||||
(() => {
|
||||
this._gestionnaire.chargerPartieAncienne(veille, Sauvegardeur.chargerPartieVeille());
|
||||
this._panelManager.cacherPanel();
|
||||
}).bind(this)
|
||||
);
|
||||
}
|
||||
this._panelManager.afficherPanel();
|
||||
}
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ export default class Gestionnaire {
|
|||
private _grille: Grille | null = null;
|
||||
private _input: Input | null = null;
|
||||
private readonly _reglesPanel: ReglesPanel;
|
||||
private readonly _finDePartiePanel: FinDePartiePanel;
|
||||
private _finDePartiePanel: FinDePartiePanel;
|
||||
private readonly _configurationPanel: ConfigurationPanel;
|
||||
private readonly _propositions: Array<string>;
|
||||
private readonly _resultats: Array<Array<LettreResultat>>;
|
||||
|
@ -65,7 +65,7 @@ export default class Gestionnaire {
|
|||
this._panelManager = new PanelManager();
|
||||
this._themeManager = new ThemeManager(this._config);
|
||||
this._reglesPanel = new ReglesPanel(this._panelManager);
|
||||
this._finDePartiePanel = new FinDePartiePanel(this._datePartieEnCours, this._panelManager);
|
||||
this._finDePartiePanel = new FinDePartiePanel(this._datePartieEnCours, this._panelManager, this);
|
||||
this._configurationPanel = new ConfigurationPanel(this._panelManager, this._audioPanel, this._themeManager);
|
||||
|
||||
this.choisirMot(this._idPartieEnCours, this._datePartieEnCours)
|
||||
|
@ -269,4 +269,37 @@ export default class Gestionnaire {
|
|||
|
||||
this._reglesPanel.afficher();
|
||||
}
|
||||
|
||||
public chargerPartieAncienne(datePartie: Date, etatPartie: PartieEnCours): void {
|
||||
let partieEnCours = etatPartie;
|
||||
|
||||
this._idPartieEnCours = this.getIdPartie(partieEnCours);
|
||||
|
||||
if (this._idPartieEnCours !== partieEnCours.idPartie && partieEnCours.idPartie !== undefined) {
|
||||
partieEnCours = new PartieEnCours();
|
||||
}
|
||||
|
||||
if (partieEnCours.datePartie) {
|
||||
this._datePartieEnCours = partieEnCours.datePartie;
|
||||
} else {
|
||||
this._datePartieEnCours = datePartie;
|
||||
}
|
||||
this._dateFinPartie = undefined;
|
||||
|
||||
this._propositions.splice(0);
|
||||
this._resultats.splice(0);
|
||||
this._finDePartiePanel = new FinDePartiePanel(this._datePartieEnCours, this._panelManager, this);
|
||||
|
||||
this.choisirMot(this._idPartieEnCours, this._datePartieEnCours)
|
||||
.then(async (mot) => {
|
||||
this._motATrouver = mot;
|
||||
this._input = new Input(this, this._config, this._motATrouver.length, this._motATrouver[0]);
|
||||
this._panelManager.setInput(this._input);
|
||||
this._grille = new Grille(this._motATrouver.length, this._maxNbPropositions, this._motATrouver[0], this._audioPanel);
|
||||
this._configurationPanel.setInput(this._input);
|
||||
this._compositionMotATrouver = this.decompose(this._motATrouver);
|
||||
await this.chargerPropositions(partieEnCours.propositions);
|
||||
})
|
||||
.catch((raison) => NotificationMessage.ajouterNotification("Aucun mot n'a été trouvé pour aujourd'hui"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import NotificationMessage from "./notificationMessage";
|
|||
export default class Sauvegardeur {
|
||||
private static readonly _cleStats = "statistiques";
|
||||
private static readonly _clePartieEnCours = "partieEnCours";
|
||||
private static readonly _clePartieVeille = "partieVeille";
|
||||
private static readonly _cleConfiguration = "configuration";
|
||||
|
||||
public static sauvegarderStats(stats: SauvegardeStats): void {
|
||||
|
@ -48,19 +49,54 @@ export default class Sauvegardeur {
|
|||
}
|
||||
|
||||
public static chargerSauvegardePartieEnCours(): PartieEnCours | undefined {
|
||||
let dataPartieEnCours = localStorage.getItem(this._clePartieEnCours);
|
||||
if (!dataPartieEnCours) return;
|
||||
|
||||
let partieEnCours = JSON.parse(dataPartieEnCours) as SauvegardePartie;
|
||||
let aujourdhui = new Date();
|
||||
let datePartieEnCours = new Date(partieEnCours.datePartie);
|
||||
if (
|
||||
aujourdhui.getDate() !== datePartieEnCours.getDate() ||
|
||||
aujourdhui.getMonth() !== datePartieEnCours.getMonth() ||
|
||||
aujourdhui.getFullYear() !== datePartieEnCours.getFullYear()
|
||||
) {
|
||||
localStorage.removeItem(this._clePartieEnCours);
|
||||
return;
|
||||
let partieEnCours: SauvegardePartie;
|
||||
let datePartieEnCours: Date;
|
||||
|
||||
let dataPartieEnCours = localStorage.getItem(this._clePartieEnCours);
|
||||
if (!dataPartieEnCours) {
|
||||
// On regarde si par hasard, on n'a pas la partie du jour dans les infos de la veille
|
||||
const partieVeille = this.getInfoVeille();
|
||||
|
||||
if (
|
||||
partieVeille &&
|
||||
aujourdhui.getDate() === partieVeille.datePartie.getDate() &&
|
||||
aujourdhui.getMonth() === partieVeille.datePartie.getMonth() &&
|
||||
aujourdhui.getFullYear() === partieVeille.datePartie.getFullYear()
|
||||
) {
|
||||
partieEnCours = partieVeille;
|
||||
datePartieEnCours = partieVeille.datePartie;
|
||||
localStorage.removeItem(this._clePartieVeille);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
partieEnCours = JSON.parse(dataPartieEnCours) as SauvegardePartie;
|
||||
datePartieEnCours = new Date(partieEnCours.datePartie);
|
||||
if (
|
||||
aujourdhui.getDate() !== datePartieEnCours.getDate() ||
|
||||
aujourdhui.getMonth() !== datePartieEnCours.getMonth() ||
|
||||
aujourdhui.getFullYear() !== datePartieEnCours.getFullYear()
|
||||
) {
|
||||
// On regarde si par hasard, on n'a pas la partie du jour dans les infos de la veille
|
||||
const partieVeille = this.getInfoVeille();
|
||||
|
||||
if (
|
||||
partieVeille &&
|
||||
aujourdhui.getDate() === partieVeille.datePartie.getDate() &&
|
||||
aujourdhui.getMonth() === partieVeille.datePartie.getMonth() &&
|
||||
aujourdhui.getFullYear() === partieVeille.datePartie.getFullYear()
|
||||
) {
|
||||
partieEnCours = partieVeille;
|
||||
datePartieEnCours = partieVeille.datePartie;
|
||||
// Et on inverse les données
|
||||
localStorage.setItem(this._clePartieVeille, dataPartieEnCours);
|
||||
} else {
|
||||
localStorage.setItem(this._clePartieVeille, dataPartieEnCours);
|
||||
localStorage.removeItem(this._clePartieEnCours);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
let dateFinPartie = partieEnCours.dateFinPartie === undefined ? undefined : new Date(partieEnCours.dateFinPartie);
|
||||
|
||||
|
@ -72,6 +108,66 @@ export default class Sauvegardeur {
|
|||
};
|
||||
}
|
||||
|
||||
private static getInfoVeille(): SauvegardePartie | undefined {
|
||||
const dataPartieVeille = localStorage.getItem(this._clePartieVeille);
|
||||
if (!dataPartieVeille) return undefined;
|
||||
|
||||
const veille = new Date();
|
||||
veille.setDate(veille.getDate() - 1);
|
||||
|
||||
let partieVeille = JSON.parse(dataPartieVeille) as SauvegardePartie;
|
||||
if (partieVeille.datePartie) partieVeille.datePartie = new Date(partieVeille.datePartie);
|
||||
if (partieVeille.dateFinPartie) partieVeille.dateFinPartie = new Date(partieVeille.dateFinPartie);
|
||||
return partieVeille;
|
||||
}
|
||||
|
||||
public static hasPartieVeilleNonTerminee(): boolean {
|
||||
const partieVeille = this.getInfoVeille();
|
||||
if (!partieVeille) return true;
|
||||
|
||||
const veille = new Date();
|
||||
veille.setDate(veille.getDate() - 1);
|
||||
|
||||
return (
|
||||
veille.getDate() === partieVeille.datePartie.getDate() &&
|
||||
veille.getMonth() === partieVeille.datePartie.getMonth() &&
|
||||
veille.getFullYear() === partieVeille.datePartie.getFullYear() &&
|
||||
!partieVeille.dateFinPartie
|
||||
);
|
||||
}
|
||||
|
||||
public static chargerPartieVeille(): PartieEnCours {
|
||||
const veille = new Date();
|
||||
veille.setDate(veille.getDate() - 1);
|
||||
const partieVeille = this.getInfosPartieVeille(veille);
|
||||
let dateFinPartie = partieVeille.dateFinPartie === undefined ? undefined : new Date(partieVeille.dateFinPartie);
|
||||
|
||||
// On va sauvegarder la partie en cours dans la veille pour ne pas la perde
|
||||
const partieEnCours = localStorage.getItem(this._clePartieEnCours);
|
||||
if (partieEnCours) {
|
||||
localStorage.setItem(this._clePartieVeille, partieEnCours);
|
||||
localStorage.removeItem(this._clePartieEnCours);
|
||||
}
|
||||
|
||||
return {
|
||||
datePartie: new Date(partieVeille.datePartie),
|
||||
dateFinPartie: dateFinPartie,
|
||||
propositions: partieVeille.propositions,
|
||||
idPartie: partieVeille.idPartie,
|
||||
};
|
||||
}
|
||||
|
||||
private static getInfosPartieVeille(veille: Date): SauvegardePartie {
|
||||
const dataPartieVeille = localStorage.getItem(this._clePartieVeille);
|
||||
if (!dataPartieVeille) {
|
||||
const dataPartie = new SauvegardePartie();
|
||||
dataPartie.datePartie = veille;
|
||||
return dataPartie;
|
||||
}
|
||||
|
||||
return JSON.parse(dataPartieVeille) as SauvegardePartie;
|
||||
}
|
||||
|
||||
public static sauvegarderConfig(config: Configuration): void {
|
||||
localStorage.setItem(this._cleConfiguration, JSON.stringify(config));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue