mirror of
				https://framagit.org/JonathanMM/sutom.git
				synced 2025-10-31 12:48:50 +01:00 
			
		
		
		
	
		
			
				
	
	
		
			76 lines
		
	
	
	
		
			2.9 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			76 lines
		
	
	
	
		
			2.9 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
| import LettreResultat from "./lettreResultat";
 | |
| import { LettreStatut } from "./lettreStatut";
 | |
| import NotificationMessage from "./notificationMessage";
 | |
| 
 | |
| export default class FinDePartiePanel {
 | |
|   private readonly _finDePartiePanel: HTMLElement;
 | |
|   private readonly _victoirePanel: HTMLElement;
 | |
|   private readonly _defaitePanel: HTMLElement;
 | |
|   private readonly _defaitePanelMot: HTMLElement;
 | |
|   private readonly _resume: HTMLPreElement;
 | |
|   private readonly _resumeBouton: HTMLElement;
 | |
|   private readonly _datePartie: Date;
 | |
| 
 | |
|   private _resumeTexte: string = "";
 | |
| 
 | |
|   public constructor(datePartie: Date) {
 | |
|     this._finDePartiePanel = document.getElementById("fin-de-partie-panel") as HTMLElement;
 | |
|     this._victoirePanel = document.getElementById("victoire-panel") as HTMLElement;
 | |
|     this._defaitePanel = document.getElementById("defaite-panel") as HTMLElement;
 | |
|     this._defaitePanelMot = document.getElementById("defaite-panel-mot") as HTMLElement;
 | |
|     this._resume = document.getElementById("fin-de-partie-panel-resume") as HTMLPreElement;
 | |
|     this._resumeBouton = document.getElementById("fin-de-partie-panel-resume-bouton") as HTMLElement;
 | |
| 
 | |
|     this._datePartie = datePartie;
 | |
| 
 | |
|     this._resumeBouton.addEventListener("click", (event) => {
 | |
|       event.stopPropagation();
 | |
|       if (!navigator.clipboard) {
 | |
|         NotificationMessage.ajouterNotification("Votre navigateur n'est pas compatible");
 | |
|       }
 | |
| 
 | |
|       navigator.clipboard
 | |
|         .writeText(this._resumeTexte + "\n\nhttps://sutom.nocle.fr")
 | |
|         .then(() => {
 | |
|           NotificationMessage.ajouterNotification("Résumé copié dans le presse papier");
 | |
|         })
 | |
|         .catch((raison) => {
 | |
|           NotificationMessage.ajouterNotification("Votre navigateur n'est pas compatible");
 | |
|         });
 | |
|     });
 | |
|   }
 | |
| 
 | |
|   public genererResume(estBonneReponse: boolean, resultats: Array<Array<LettreResultat>>): void {
 | |
|     let resultatsEmojis = resultats.map((mot) =>
 | |
|       mot
 | |
|         .map((resultat) => resultat.statut)
 | |
|         .reduce((ligne, statut) => {
 | |
|           switch (statut) {
 | |
|             case LettreStatut.BienPlace:
 | |
|               return ligne + "🟥";
 | |
|             case LettreStatut.MalPlace:
 | |
|               return ligne + "🟡";
 | |
|             default:
 | |
|               return ligne + "🟦";
 | |
|           }
 | |
|         }, "")
 | |
|     );
 | |
|     let dateGrille = this._datePartie.getTime();
 | |
|     let origine = new Date(2022, 0, 8).getTime();
 | |
| 
 | |
|     let numeroGrille = Math.floor((dateGrille - origine) / (24 * 3600 * 1000)) + 1;
 | |
| 
 | |
|     this._resumeTexte = "SUTOM #" + numeroGrille + " " + (estBonneReponse ? resultats.length : "-") + "/6\n\n" + resultatsEmojis.join("\n");
 | |
|     this._resume.innerText = this._resumeTexte;
 | |
|   }
 | |
| 
 | |
|   public afficher(estVictoire: boolean, motATrouver: string): void {
 | |
|     this._finDePartiePanel.style.display = "block";
 | |
| 
 | |
|     if (estVictoire) this._victoirePanel.style.display = "block";
 | |
|     else {
 | |
|       this._defaitePanelMot.innerText = motATrouver;
 | |
|       this._defaitePanel.style.display = "block";
 | |
|     }
 | |
|   }
 | |
| }
 | 
