Fix: calendrier astrologique
Pb de détermination des chiffres astrologiques désormais async
This commit is contained in:
parent
7022c2134e
commit
36b3cbcae7
@ -65,14 +65,15 @@ export class RdDCalendrier extends Application {
|
||||
// nombre astral
|
||||
if (game.user.isGM) {
|
||||
this.listeNombreAstral = this._loadListNombreAstral();
|
||||
this.rebuildListeNombreAstral(); // Ensure always up-to-date
|
||||
await this.rebuildListeNombreAstral(); // Ensure always up-to-date
|
||||
}
|
||||
console.log(this.calendrier, this.calendrierPos, this.listeNombreAstral);
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
_loadListNombreAstral() {
|
||||
return Object.values(game.settings.get("foundryvtt-reve-de-dragon", "liste-nombre-astral"));
|
||||
const listeNombreAstraux = game.settings.get("foundryvtt-reve-de-dragon", "liste-nombre-astral");
|
||||
return Object.values(listeNombreAstraux);
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
@ -96,8 +97,10 @@ export class RdDCalendrier extends Application {
|
||||
getNumericDateFromIndex(index = undefined) {
|
||||
if (!index) index = this.getCurrentDayIndex();
|
||||
let month = Math.floor(index / 28)
|
||||
return { month: heuresList[month],
|
||||
day: (index - (month * 28)) + 1 }
|
||||
return {
|
||||
month: heuresList[month],
|
||||
day: (index - (month * 28)) + 1
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
@ -127,17 +130,18 @@ export class RdDCalendrier extends Application {
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async ajouterNombreAstral(index) {
|
||||
const nombreAstral = await RdDDice.rollTotal("1dh");
|
||||
return {
|
||||
nombreAstral: await RdDDice.rollTotal("1dh"),
|
||||
nombreAstral: nombreAstral,
|
||||
valeursFausses: [],
|
||||
index: index
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
getCurrentNombreAstral() {
|
||||
async getCurrentNombreAstral() {
|
||||
let indexDate = this.getCurrentDayIndex();
|
||||
return this.getNombreAstral(indexDate);
|
||||
return await this.getNombreAstral(indexDate);
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
@ -147,21 +151,24 @@ export class RdDCalendrier extends Application {
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
getNombreAstral(indexDate) {
|
||||
async getNombreAstral(indexDate) {
|
||||
const liste = this.listeNombreAstral ?? this._loadListNombreAstral();
|
||||
let astralData = liste.find((nombreAstral, i) => nombreAstral.index == indexDate);
|
||||
if (!astralData?.nombreAstral) {
|
||||
this.rebuildListeNombreAstral();
|
||||
await this.rebuildListeNombreAstral();
|
||||
astralData = liste.find((nombreAstral, i) => nombreAstral.index == indexDate);
|
||||
}
|
||||
return astralData?.nombreAstral ?? "N/A";
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
rebuildListeNombreAstral() {
|
||||
async rebuildListeNombreAstral() {
|
||||
let jourCourant = this.getCurrentDayIndex();
|
||||
let jourFin = jourCourant + 12;
|
||||
let newList = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11].map(i => this.ajouterNombreAstral(jourCourant + i));
|
||||
let newList = [];
|
||||
for (let i=0; i<12; i++) {
|
||||
newList.push(await this.ajouterNombreAstral(jourCourant + i));
|
||||
}
|
||||
if (this.listeNombreAstral) {
|
||||
for (const na of this.listeNombreAstral) {
|
||||
if (na && na.index >= jourCourant && na.index < jourFin) {
|
||||
@ -173,21 +180,21 @@ export class RdDCalendrier extends Application {
|
||||
game.settings.set("foundryvtt-reve-de-dragon", "liste-nombre-astral", this.listeNombreAstral);
|
||||
}
|
||||
/* -------------------------------------------- */
|
||||
onCalendarButton(ev) {
|
||||
async onCalendarButton(ev) {
|
||||
ev.preventDefault();
|
||||
const calendarAvance = ev.currentTarget.attributes['data-calendar-avance'];
|
||||
const calendarSet = ev.currentTarget.attributes['data-calendar-set'];
|
||||
if (calendarAvance) {
|
||||
this.incrementTime(Number(calendarAvance.value));
|
||||
await this.incrementTime(Number(calendarAvance.value));
|
||||
}
|
||||
else if (calendarSet) {
|
||||
this.positionnerHeure(Number(calendarSet.value));
|
||||
}
|
||||
this.updateDisplay();
|
||||
await this.updateDisplay();
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
incrementTime(minutes = 0) {
|
||||
async incrementTime(minutes = 0) {
|
||||
this.calendrier.minutesRelative += minutes;
|
||||
if (this.calendrier.minutesRelative >= 120) {
|
||||
this.calendrier.minutesRelative -= 120;
|
||||
@ -195,7 +202,7 @@ export class RdDCalendrier extends Application {
|
||||
}
|
||||
if (this.calendrier.heureRdD > 11) {
|
||||
this.calendrier.heureRdD -= 12;
|
||||
this.incrementerJour();
|
||||
await this.incrementerJour();
|
||||
}
|
||||
game.settings.set("foundryvtt-reve-de-dragon", "calendrier", duplicate(this.calendrier));
|
||||
// Notification aux joueurs
|
||||
@ -206,7 +213,7 @@ export class RdDCalendrier extends Application {
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
incrementerJour() {
|
||||
async incrementerJour() {
|
||||
this.calendrier.jour += 1;
|
||||
if (this.calendrier.jour >= RDD_JOUR_PAR_MOIS) {
|
||||
this.calendrier.jour -= RDD_JOUR_PAR_MOIS;
|
||||
@ -215,19 +222,20 @@ export class RdDCalendrier extends Application {
|
||||
this.calendrier.moisRdD += 1;
|
||||
// Reconstruire les nombres astraux
|
||||
}
|
||||
this.rebuildListeNombreAstral();
|
||||
await this.rebuildListeNombreAstral();
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
syncPlayerTime(calendrier) {
|
||||
async syncPlayerTime(calendrier) {
|
||||
this.calendrier = duplicate(calendrier); // Local copy update
|
||||
this.updateDisplay();
|
||||
await this.updateDisplay();
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
positionnerHeure(indexHeure) {
|
||||
if (indexHeure <= this.calendrier.heureRdD)
|
||||
this.incrementerJour();
|
||||
async positionnerHeure(indexHeure) {
|
||||
if (indexHeure <= this.calendrier.heureRdD){
|
||||
await this.incrementerJour();
|
||||
}
|
||||
this.calendrier.heureRdD = indexHeure;
|
||||
this.calendrier.minutesRelative = 0;
|
||||
game.settings.set("foundryvtt-reve-de-dragon", "calendrier", duplicate(this.calendrier));
|
||||
@ -275,7 +283,7 @@ export class RdDCalendrier extends Application {
|
||||
showDice: false
|
||||
};
|
||||
await RdDResolutionTable.rollData(rollData);
|
||||
let nbAstral = this.getNombreAstral(request.date);
|
||||
let nbAstral = await this.getNombreAstral(request.date);
|
||||
request.rolled = rollData.rolled;
|
||||
request.isValid = true;
|
||||
if (!request.rolled.isSuccess) {
|
||||
@ -299,11 +307,11 @@ export class RdDCalendrier extends Application {
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
getAjustementAstrologique(heureNaissance, name = 'inconnu') {
|
||||
async getAjustementAstrologique(heureNaissance, name = 'inconnu') {
|
||||
let heure = Grammar.toLowerCaseNoAccent(heureNaissance);
|
||||
if (heure && heuresDef[heure]) {
|
||||
let hn = heuresDef[heure].heure;
|
||||
let chiffreAstral = this.getCurrentNombreAstral();
|
||||
let chiffreAstral = await this.getCurrentNombreAstral();
|
||||
let heureCourante = this.calendrier.heureRdD;
|
||||
let ecartChance = (hn + chiffreAstral - heureCourante) % 12;
|
||||
switch (ecartChance) {
|
||||
@ -350,12 +358,12 @@ export class RdDCalendrier extends Application {
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
updateDisplay() {
|
||||
async updateDisplay() {
|
||||
let data = this.fillCalendrierData();
|
||||
// Rebuild data
|
||||
let dateHTML = `Jour ${data.jourMois} de ${data.nomMois} (${data.nomSaison})`;
|
||||
if (game.user.isGM) {
|
||||
dateHTML = dateHTML + " - NA: " + this.getCurrentNombreAstral();
|
||||
dateHTML = dateHTML + " - NA: " + await this.getCurrentNombreAstral();
|
||||
}
|
||||
for (let handle of document.getElementsByClassName("calendar-date-rdd")) {
|
||||
handle.innerHTML = dateHTML;
|
||||
@ -372,16 +380,16 @@ export class RdDCalendrier extends Application {
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
saveEditeur(calendrierData) {
|
||||
async saveEditeur(calendrierData) {
|
||||
this.calendrier.minutesRelative = Number(calendrierData.minutesRelative);
|
||||
this.calendrier.jour = Number(calendrierData.jourMois) - 1;
|
||||
this.calendrier.moisRdD = heuresList.findIndex(mois => mois === calendrierData.moisKey);
|
||||
this.calendrier.heureRdD = heuresList.findIndex(heure => heure === calendrierData.heureKey);; // Index dans heuresList
|
||||
game.settings.set("foundryvtt-reve-de-dragon", "calendrier", duplicate(this.calendrier));
|
||||
|
||||
this.rebuildListeNombreAstral();
|
||||
await this.rebuildListeNombreAstral();
|
||||
|
||||
this.updateDisplay();
|
||||
await this.updateDisplay();
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
@ -421,12 +429,12 @@ export class RdDCalendrier extends Application {
|
||||
|
||||
/* -------------------------------------------- */
|
||||
/** @override */
|
||||
activateListeners(html) {
|
||||
async activateListeners(html) {
|
||||
super.activateListeners(html);
|
||||
|
||||
HtmlUtility._showControlWhen($(".gm-only"), game.user.isGM);
|
||||
|
||||
this.updateDisplay();
|
||||
await this.updateDisplay();
|
||||
|
||||
html.find('.calendar-btn').click(ev => this.onCalendarButton(ev));
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user