mirror of
https://framagit.org/JonathanMM/sutom.git
synced 2024-05-03 14:33:20 +02:00
Ajout de la possibilité de charger une partie dans l'URL
This commit is contained in:
parent
8958752adf
commit
7db79125f0
|
@ -1,4 +1,3 @@
|
||||||
import InstanceConfiguration from "./instanceConfiguration";
|
|
||||||
import ListeMotsProposables from "./mots/listeMotsProposables";
|
import ListeMotsProposables from "./mots/listeMotsProposables";
|
||||||
export default class Dictionnaire {
|
export default class Dictionnaire {
|
||||||
public constructor() {}
|
public constructor() {}
|
||||||
|
@ -6,7 +5,14 @@ export default class Dictionnaire {
|
||||||
public static async getMot(idPartie: string, datePartie: Date): Promise<string> {
|
public static async getMot(idPartie: string, datePartie: Date): Promise<string> {
|
||||||
return await this.getNomFichier(idPartie, datePartie)
|
return await this.getNomFichier(idPartie, datePartie)
|
||||||
.then((nom) => fetch("mots/" + nom + ".txt"))
|
.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> {
|
private static async getNomFichier(idPartie: string, datePartie: Date): Promise<string> {
|
||||||
|
|
|
@ -42,14 +42,18 @@ export default class Gestionnaire {
|
||||||
|
|
||||||
let partieEnCours = this.chargerPartieEnCours();
|
let partieEnCours = this.chargerPartieEnCours();
|
||||||
|
|
||||||
|
this._idPartieEnCours = this.getIdPartie(partieEnCours);
|
||||||
|
|
||||||
|
if (this._idPartieEnCours !== partieEnCours.idPartie) {
|
||||||
|
partieEnCours = new PartieEnCours();
|
||||||
|
}
|
||||||
|
|
||||||
if (partieEnCours.datePartie) {
|
if (partieEnCours.datePartie) {
|
||||||
this._datePartieEnCours = partieEnCours.datePartie;
|
this._datePartieEnCours = partieEnCours.datePartie;
|
||||||
} else {
|
} else {
|
||||||
this._datePartieEnCours = new Date();
|
this._datePartieEnCours = new Date();
|
||||||
}
|
}
|
||||||
|
|
||||||
this._idPartieEnCours = this.getIdPartie(partieEnCours);
|
|
||||||
|
|
||||||
if (partieEnCours.dateFinPartie) {
|
if (partieEnCours.dateFinPartie) {
|
||||||
this._dateFinPartie = partieEnCours.dateFinPartie;
|
this._dateFinPartie = partieEnCours.dateFinPartie;
|
||||||
}
|
}
|
||||||
|
@ -63,19 +67,35 @@ export default class Gestionnaire {
|
||||||
this._finDePartiePanel = new FinDePartiePanel(this._datePartieEnCours, this._panelManager);
|
this._finDePartiePanel = new FinDePartiePanel(this._datePartieEnCours, this._panelManager);
|
||||||
this._configurationPanel = new ConfigurationPanel(this._panelManager, this._audioPanel, this._themeManager);
|
this._configurationPanel = new ConfigurationPanel(this._panelManager, this._audioPanel, this._themeManager);
|
||||||
|
|
||||||
this.choisirMot(this._idPartieEnCours, this._datePartieEnCours).then((mot) => {
|
this.choisirMot(this._idPartieEnCours, this._datePartieEnCours)
|
||||||
this._motATrouver = mot;
|
.then((mot) => {
|
||||||
this._input = new Input(this, this._config, this._motATrouver.length, this._motATrouver[0]);
|
this._motATrouver = mot;
|
||||||
this._grille = new Grille(this._motATrouver.length, this._maxNbPropositions, this._motATrouver[0], this._audioPanel);
|
this._input = new Input(this, this._config, this._motATrouver.length, this._motATrouver[0]);
|
||||||
this._configurationPanel.setInput(this._input);
|
this._grille = new Grille(this._motATrouver.length, this._maxNbPropositions, this._motATrouver[0], this._audioPanel);
|
||||||
this._compositionMotATrouver = this.decompose(this._motATrouver);
|
this._configurationPanel.setInput(this._input);
|
||||||
this.chargerPropositions(partieEnCours.propositions);
|
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();
|
this.afficherReglesSiNecessaire();
|
||||||
}
|
}
|
||||||
|
|
||||||
private getIdPartie(partieEnCours: PartieEnCours) {
|
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;
|
if (partieEnCours.idPartie !== undefined) return partieEnCours.idPartie;
|
||||||
|
|
||||||
return InstanceConfiguration.idPartieParDefaut;
|
return InstanceConfiguration.idPartieParDefaut;
|
||||||
|
@ -131,7 +151,7 @@ export default class Gestionnaire {
|
||||||
}
|
}
|
||||||
|
|
||||||
private async choisirMot(idPartie: string, datePartie: Date): Promise<string> {
|
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 } {
|
private decompose(mot: string): { [lettre: string]: number } {
|
||||||
|
|
Loading…
Reference in a new issue