Correction des ajustements astrologiques
ne pas avoir d'async pour déterminer l'ajustement astrologique. Si on n'a pas de chiffre astral du jour (ie: n'arrivera pas, on calcule à l'init), on utilise 0 et on lance le calcul async pour la prochaine fois..
This commit is contained in:
parent
22f12b8f06
commit
5aa0f62b83
@ -37,17 +37,23 @@ const MAX_NOMBRE_ASTRAL = 12;
|
||||
/* -------------------------------------------- */
|
||||
export class RdDCalendrier extends Application {
|
||||
|
||||
getCalendrier(index) {
|
||||
let calendrier = {
|
||||
heureRdD: 0, // Index dans heuresList
|
||||
minutesRelative: 0,
|
||||
moisRdD: Math.floor(index / 28) % 12,
|
||||
jour: (index - (month * 28)) + 1
|
||||
}
|
||||
return calendrier;
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async initCalendrier() {
|
||||
// Calendrier
|
||||
this.calendrier = duplicate(game.settings.get("foundryvtt-reve-de-dragon", "calendrier"));
|
||||
//console.log("CALENDRIER", this.calendrier);
|
||||
if (this.calendrier == undefined || this.calendrier.moisRdD == undefined) {
|
||||
this.calendrier = {};
|
||||
this.calendrier.heureRdD = 0; // Index dans heuresList
|
||||
this.calendrier.minutesRelative = 0;
|
||||
this.calendrier.moisRdD = 0; // Index dans heuresList
|
||||
this.calendrier.jour = 0;
|
||||
this.calendrier = this.getCalendrier(0);
|
||||
if (game.user.isGM) { // Uniquement si GM
|
||||
game.settings.set("foundryvtt-reve-de-dragon", "calendrier", this.calendrier);
|
||||
}
|
||||
@ -86,8 +92,8 @@ export class RdDCalendrier extends Application {
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
getDateFromIndex(index = undefined) {
|
||||
if (!index) index = this.getCurrentDayIndex();
|
||||
getDateFromIndex(index) {
|
||||
index = index ?? this.getCurrentDayIndex();
|
||||
let month = Math.floor(index / 28);
|
||||
let day = (index - (month * 28)) + 1;
|
||||
return day + " " + heuresList[month];
|
||||
@ -131,6 +137,11 @@ export class RdDCalendrier extends Application {
|
||||
/* -------------------------------------------- */
|
||||
async ajouterNombreAstral(index) {
|
||||
const nombreAstral = await RdDDice.rollTotal("1dh", { showDice: true, rollMode: "selfroll" });
|
||||
const dateFuture = this.getDateFromIndex(index);
|
||||
ChatMessage.create({
|
||||
whisper: ChatMessage.getWhisperRecipients("GM"),
|
||||
content: `Le chiffre astrologique du ${dateFuture} sera le ${nombreAstral}`
|
||||
});
|
||||
return {
|
||||
nombreAstral: nombreAstral,
|
||||
valeursFausses: [],
|
||||
@ -139,9 +150,9 @@ export class RdDCalendrier extends Application {
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async getCurrentNombreAstral() {
|
||||
getCurrentNombreAstral() {
|
||||
let indexDate = this.getCurrentDayIndex();
|
||||
return await this.getNombreAstral(indexDate);
|
||||
return this.getNombreAstral(indexDate);
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
@ -151,14 +162,13 @@ export class RdDCalendrier extends Application {
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async getNombreAstral(indexDate) {
|
||||
getNombreAstral(indexDate) {
|
||||
const liste = this.listeNombreAstral ?? this._loadListNombreAstral();
|
||||
let astralData = liste.find((nombreAstral, i) => nombreAstral.index == indexDate);
|
||||
if (!astralData?.nombreAstral) {
|
||||
await this.rebuildListeNombreAstral();
|
||||
astralData = liste.find((nombreAstral, i) => nombreAstral.index == indexDate);
|
||||
this.rebuildListeNombreAstral();
|
||||
}
|
||||
return astralData?.nombreAstral ?? "N/A";
|
||||
return astralData?.nombreAstral;
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
@ -217,7 +227,7 @@ export class RdDCalendrier extends Application {
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async incrementerJour() {
|
||||
incrementerJour() {
|
||||
this.calendrier.jour += 1;
|
||||
if (this.calendrier.jour >= RDD_JOUR_PAR_MOIS) {
|
||||
this.calendrier.jour -= RDD_JOUR_PAR_MOIS;
|
||||
@ -226,13 +236,13 @@ export class RdDCalendrier extends Application {
|
||||
this.calendrier.moisRdD += 1;
|
||||
// Reconstruire les nombres astraux
|
||||
}
|
||||
await this.rebuildListeNombreAstral();
|
||||
this.rebuildListeNombreAstral();
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async syncPlayerTime(calendrier) {
|
||||
syncPlayerTime(calendrier) {
|
||||
this.calendrier = duplicate(calendrier); // Local copy update
|
||||
await this.updateDisplay();
|
||||
this.updateDisplay();
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
@ -287,7 +297,7 @@ export class RdDCalendrier extends Application {
|
||||
showDice: false
|
||||
};
|
||||
await RdDResolutionTable.rollData(rollData);
|
||||
let nbAstral = await this.getNombreAstral(request.date);
|
||||
let nbAstral = this.getNombreAstral(request.date);
|
||||
request.rolled = rollData.rolled;
|
||||
request.isValid = true;
|
||||
if (!request.rolled.isSuccess) {
|
||||
@ -311,11 +321,11 @@ export class RdDCalendrier extends Application {
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async getAjustementAstrologique(heureNaissance, name = 'inconnu') {
|
||||
getAjustementAstrologique(heureNaissance, name = 'inconnu') {
|
||||
let heure = Grammar.toLowerCaseNoAccent(heureNaissance);
|
||||
if (heure && heuresDef[heure]) {
|
||||
let hn = heuresDef[heure].heure;
|
||||
let chiffreAstral = await this.getCurrentNombreAstral();
|
||||
let chiffreAstral = this.getCurrentNombreAstral() ?? 0;
|
||||
let heureCourante = this.calendrier.heureRdD;
|
||||
let ecartChance = (hn + chiffreAstral - heureCourante) % 12;
|
||||
switch (ecartChance) {
|
||||
@ -362,12 +372,12 @@ export class RdDCalendrier extends Application {
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async updateDisplay() {
|
||||
updateDisplay() {
|
||||
let data = this.fillCalendrierData();
|
||||
// Rebuild data
|
||||
let dateHTML = `Jour ${data.jourMois} de ${data.nomMois} (${data.nomSaison})`;
|
||||
let dateHTML = `Jour ${data.jourMois} de ${data.nomMois} (${data.nomSaison})`
|
||||
if (game.user.isGM) {
|
||||
dateHTML = dateHTML + " - NA: " + await this.getCurrentNombreAstral();
|
||||
dateHTML = dateHTML + " - NA: " + (this.getCurrentNombreAstral() ?? "indéterminé");
|
||||
}
|
||||
for (let handle of document.getElementsByClassName("calendar-date-rdd")) {
|
||||
handle.innerHTML = dateHTML;
|
||||
@ -393,7 +403,7 @@ export class RdDCalendrier extends Application {
|
||||
|
||||
await this.rebuildListeNombreAstral();
|
||||
|
||||
await this.updateDisplay();
|
||||
this.updateDisplay();
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
|
Loading…
Reference in New Issue
Block a user