mirror of
https://framagit.org/JonathanMM/sutom.git
synced 2025-04-16 14:45:13 +02:00
Ajout de la possibilité de charger une partie dans l'URL
This commit is contained in:
parent
8958752adf
commit
7db79125f0
2 changed files with 39 additions and 13 deletions
|
@ -1,4 +1,3 @@
|
|||
import InstanceConfiguration from "./instanceConfiguration";
|
||||
import ListeMotsProposables from "./mots/listeMotsProposables";
|
||||
export default class Dictionnaire {
|
||||
public constructor() {}
|
||||
|
@ -6,7 +5,14 @@ export default class Dictionnaire {
|
|||
public static async getMot(idPartie: string, datePartie: Date): Promise<string> {
|
||||
return await this.getNomFichier(idPartie, datePartie)
|
||||
.then((nom) => fetch("mots/" + nom + ".txt"))
|
||||
.then((resultat) => resultat.text());
|
||||
.then(
|
||||
(resultat) =>
|
||||
new Promise((resolve, reject) => {
|
||||
if (!resultat.ok) return reject("Mot non trouvé");
|
||||
|
||||
return resolve(resultat.text());
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
private static async getNomFichier(idPartie: string, datePartie: Date): Promise<string> {
|
||||
|
|
|
@ -42,14 +42,18 @@ export default class Gestionnaire {
|
|||
|
||||
let partieEnCours = this.chargerPartieEnCours();
|
||||
|
||||
this._idPartieEnCours = this.getIdPartie(partieEnCours);
|
||||
|
||||
if (this._idPartieEnCours !== partieEnCours.idPartie) {
|
||||
partieEnCours = new PartieEnCours();
|
||||
}
|
||||
|
||||
if (partieEnCours.datePartie) {
|
||||
this._datePartieEnCours = partieEnCours.datePartie;
|
||||
} else {
|
||||
this._datePartieEnCours = new Date();
|
||||
}
|
||||
|
||||
this._idPartieEnCours = this.getIdPartie(partieEnCours);
|
||||
|
||||
if (partieEnCours.dateFinPartie) {
|
||||
this._dateFinPartie = partieEnCours.dateFinPartie;
|
||||
}
|
||||
|
@ -63,19 +67,35 @@ export default class Gestionnaire {
|
|||
this._finDePartiePanel = new FinDePartiePanel(this._datePartieEnCours, this._panelManager);
|
||||
this._configurationPanel = new ConfigurationPanel(this._panelManager, this._audioPanel, this._themeManager);
|
||||
|
||||
this.choisirMot(this._idPartieEnCours, this._datePartieEnCours).then((mot) => {
|
||||
this._motATrouver = mot;
|
||||
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._compositionMotATrouver = this.decompose(this._motATrouver);
|
||||
this.chargerPropositions(partieEnCours.propositions);
|
||||
});
|
||||
this.choisirMot(this._idPartieEnCours, this._datePartieEnCours)
|
||||
.then((mot) => {
|
||||
this._motATrouver = mot;
|
||||
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._compositionMotATrouver = this.decompose(this._motATrouver);
|
||||
this.chargerPropositions(partieEnCours.propositions);
|
||||
})
|
||||
.catch((raison) => NotificationMessage.ajouterNotification("Aucun mot n'a été trouvé pour aujourd'hui"));
|
||||
|
||||
this.afficherReglesSiNecessaire();
|
||||
}
|
||||
|
||||
private getIdPartie(partieEnCours: PartieEnCours) {
|
||||
if (window.location.hash !== "" && window.location.hash !== "#") {
|
||||
let hashPart = atob(window.location.hash.substring(1)).split("/");
|
||||
for (let infoPos in hashPart) {
|
||||
let info = hashPart[infoPos];
|
||||
if (!info.includes("=")) continue;
|
||||
let infoPart = info.split("=");
|
||||
let infoKey = infoPart[0];
|
||||
|
||||
if (infoKey !== "p") continue;
|
||||
|
||||
return infoPart[1];
|
||||
}
|
||||
}
|
||||
|
||||
if (partieEnCours.idPartie !== undefined) return partieEnCours.idPartie;
|
||||
|
||||
return InstanceConfiguration.idPartieParDefaut;
|
||||
|
@ -131,7 +151,7 @@ export default class Gestionnaire {
|
|||
}
|
||||
|
||||
private async choisirMot(idPartie: string, datePartie: Date): Promise<string> {
|
||||
return Dictionnaire.nettoyerMot(await Dictionnaire.getMot(idPartie, datePartie));
|
||||
return Dictionnaire.getMot(idPartie, datePartie).then((mot) => Dictionnaire.nettoyerMot(mot));
|
||||
}
|
||||
|
||||
private decompose(mot: string): { [lettre: string]: number } {
|
||||
|
|
Loading…
Add table
Reference in a new issue