Fix: calendrier astrologique
Pb de détermination des chiffres astrologiques désormais async
This commit is contained in:
parent
7022c2134e
commit
36b3cbcae7
@ -6,7 +6,7 @@ import { RdDResolutionTable } from "./rdd-resolution-table.js";
|
|||||||
import { RdDUtility } from "./rdd-utility.js";
|
import { RdDUtility } from "./rdd-utility.js";
|
||||||
import { Grammar } from "./grammar.js";
|
import { Grammar } from "./grammar.js";
|
||||||
import { Misc } from "./misc.js";
|
import { Misc } from "./misc.js";
|
||||||
import {RdDDice } from "./rdd-dice.js";
|
import { RdDDice } from "./rdd-dice.js";
|
||||||
|
|
||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
const dossierIconesHeures = 'systems/foundryvtt-reve-de-dragon/icons/heures/'
|
const dossierIconesHeures = 'systems/foundryvtt-reve-de-dragon/icons/heures/'
|
||||||
@ -65,14 +65,15 @@ export class RdDCalendrier extends Application {
|
|||||||
// nombre astral
|
// nombre astral
|
||||||
if (game.user.isGM) {
|
if (game.user.isGM) {
|
||||||
this.listeNombreAstral = this._loadListNombreAstral();
|
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);
|
console.log(this.calendrier, this.calendrierPos, this.listeNombreAstral);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
_loadListNombreAstral() {
|
_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) {
|
getNumericDateFromIndex(index = undefined) {
|
||||||
if (!index) index = this.getCurrentDayIndex();
|
if (!index) index = this.getCurrentDayIndex();
|
||||||
let month = Math.floor(index / 28)
|
let month = Math.floor(index / 28)
|
||||||
return { month: heuresList[month],
|
return {
|
||||||
day: (index - (month * 28)) + 1 }
|
month: heuresList[month],
|
||||||
|
day: (index - (month * 28)) + 1
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
@ -112,7 +115,7 @@ export class RdDCalendrier extends Application {
|
|||||||
|
|
||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
getIndexFromDate(jour, mois) {
|
getIndexFromDate(jour, mois) {
|
||||||
return (heuresDef[mois].heure * 28) + (jour-1);
|
return (heuresDef[mois].heure * 28) + (jour - 1);
|
||||||
}
|
}
|
||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
getJoursSuivants(num) {
|
getJoursSuivants(num) {
|
||||||
@ -127,41 +130,45 @@ export class RdDCalendrier extends Application {
|
|||||||
|
|
||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
async ajouterNombreAstral(index) {
|
async ajouterNombreAstral(index) {
|
||||||
|
const nombreAstral = await RdDDice.rollTotal("1dh");
|
||||||
return {
|
return {
|
||||||
nombreAstral: await RdDDice.rollTotal("1dh"),
|
nombreAstral: nombreAstral,
|
||||||
valeursFausses: [],
|
valeursFausses: [],
|
||||||
index: index
|
index: index
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
getCurrentNombreAstral() {
|
async getCurrentNombreAstral() {
|
||||||
let indexDate = this.getCurrentDayIndex();
|
let indexDate = this.getCurrentDayIndex();
|
||||||
return this.getNombreAstral(indexDate);
|
return await this.getNombreAstral(indexDate);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
resetNombreAstral( ) {
|
resetNombreAstral() {
|
||||||
this.listeNombreAstral = [];
|
this.listeNombreAstral = [];
|
||||||
game.settings.set("foundryvtt-reve-de-dragon", "liste-nombre-astral", this.listeNombreAstral);
|
game.settings.set("foundryvtt-reve-de-dragon", "liste-nombre-astral", this.listeNombreAstral);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
getNombreAstral(indexDate) {
|
async getNombreAstral(indexDate) {
|
||||||
const liste = this.listeNombreAstral ?? this._loadListNombreAstral();
|
const liste = this.listeNombreAstral ?? this._loadListNombreAstral();
|
||||||
let astralData = liste.find((nombreAstral, i) => nombreAstral.index == indexDate);
|
let astralData = liste.find((nombreAstral, i) => nombreAstral.index == indexDate);
|
||||||
if (!astralData?.nombreAstral) {
|
if (!astralData?.nombreAstral) {
|
||||||
this.rebuildListeNombreAstral();
|
await this.rebuildListeNombreAstral();
|
||||||
astralData = liste.find((nombreAstral, i) => nombreAstral.index == indexDate);
|
astralData = liste.find((nombreAstral, i) => nombreAstral.index == indexDate);
|
||||||
}
|
}
|
||||||
return astralData?.nombreAstral ?? "N/A";
|
return astralData?.nombreAstral ?? "N/A";
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
rebuildListeNombreAstral() {
|
async rebuildListeNombreAstral() {
|
||||||
let jourCourant = this.getCurrentDayIndex();
|
let jourCourant = this.getCurrentDayIndex();
|
||||||
let jourFin = jourCourant + 12;
|
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) {
|
if (this.listeNombreAstral) {
|
||||||
for (const na of this.listeNombreAstral) {
|
for (const na of this.listeNombreAstral) {
|
||||||
if (na && na.index >= jourCourant && na.index < jourFin) {
|
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);
|
game.settings.set("foundryvtt-reve-de-dragon", "liste-nombre-astral", this.listeNombreAstral);
|
||||||
}
|
}
|
||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
onCalendarButton(ev) {
|
async onCalendarButton(ev) {
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
const calendarAvance = ev.currentTarget.attributes['data-calendar-avance'];
|
const calendarAvance = ev.currentTarget.attributes['data-calendar-avance'];
|
||||||
const calendarSet = ev.currentTarget.attributes['data-calendar-set'];
|
const calendarSet = ev.currentTarget.attributes['data-calendar-set'];
|
||||||
if (calendarAvance) {
|
if (calendarAvance) {
|
||||||
this.incrementTime(Number(calendarAvance.value));
|
await this.incrementTime(Number(calendarAvance.value));
|
||||||
}
|
}
|
||||||
else if (calendarSet) {
|
else if (calendarSet) {
|
||||||
this.positionnerHeure(Number(calendarSet.value));
|
this.positionnerHeure(Number(calendarSet.value));
|
||||||
}
|
}
|
||||||
this.updateDisplay();
|
await this.updateDisplay();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
incrementTime(minutes = 0) {
|
async incrementTime(minutes = 0) {
|
||||||
this.calendrier.minutesRelative += minutes;
|
this.calendrier.minutesRelative += minutes;
|
||||||
if (this.calendrier.minutesRelative >= 120) {
|
if (this.calendrier.minutesRelative >= 120) {
|
||||||
this.calendrier.minutesRelative -= 120;
|
this.calendrier.minutesRelative -= 120;
|
||||||
@ -195,7 +202,7 @@ export class RdDCalendrier extends Application {
|
|||||||
}
|
}
|
||||||
if (this.calendrier.heureRdD > 11) {
|
if (this.calendrier.heureRdD > 11) {
|
||||||
this.calendrier.heureRdD -= 12;
|
this.calendrier.heureRdD -= 12;
|
||||||
this.incrementerJour();
|
await this.incrementerJour();
|
||||||
}
|
}
|
||||||
game.settings.set("foundryvtt-reve-de-dragon", "calendrier", duplicate(this.calendrier));
|
game.settings.set("foundryvtt-reve-de-dragon", "calendrier", duplicate(this.calendrier));
|
||||||
// Notification aux joueurs
|
// Notification aux joueurs
|
||||||
@ -206,7 +213,7 @@ export class RdDCalendrier extends Application {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
incrementerJour() {
|
async incrementerJour() {
|
||||||
this.calendrier.jour += 1;
|
this.calendrier.jour += 1;
|
||||||
if (this.calendrier.jour >= RDD_JOUR_PAR_MOIS) {
|
if (this.calendrier.jour >= RDD_JOUR_PAR_MOIS) {
|
||||||
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;
|
this.calendrier.moisRdD += 1;
|
||||||
// Reconstruire les nombres astraux
|
// Reconstruire les nombres astraux
|
||||||
}
|
}
|
||||||
this.rebuildListeNombreAstral();
|
await this.rebuildListeNombreAstral();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
syncPlayerTime(calendrier) {
|
async syncPlayerTime(calendrier) {
|
||||||
this.calendrier = duplicate(calendrier); // Local copy update
|
this.calendrier = duplicate(calendrier); // Local copy update
|
||||||
this.updateDisplay();
|
await this.updateDisplay();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
positionnerHeure(indexHeure) {
|
async positionnerHeure(indexHeure) {
|
||||||
if (indexHeure <= this.calendrier.heureRdD)
|
if (indexHeure <= this.calendrier.heureRdD){
|
||||||
this.incrementerJour();
|
await this.incrementerJour();
|
||||||
|
}
|
||||||
this.calendrier.heureRdD = indexHeure;
|
this.calendrier.heureRdD = indexHeure;
|
||||||
this.calendrier.minutesRelative = 0;
|
this.calendrier.minutesRelative = 0;
|
||||||
game.settings.set("foundryvtt-reve-de-dragon", "calendrier", duplicate(this.calendrier));
|
game.settings.set("foundryvtt-reve-de-dragon", "calendrier", duplicate(this.calendrier));
|
||||||
@ -269,18 +277,18 @@ export class RdDCalendrier extends Application {
|
|||||||
console.log(request);
|
console.log(request);
|
||||||
let jourDiff = this.getLectureAstrologieDifficulte(request.date);
|
let jourDiff = this.getLectureAstrologieDifficulte(request.date);
|
||||||
let niveau = Number(request.astrologie.data.niveau) + Number(request.conditions) + Number(jourDiff) + Number(request.etat);
|
let niveau = Number(request.astrologie.data.niveau) + Number(request.conditions) + Number(jourDiff) + Number(request.etat);
|
||||||
let rollData= {
|
let rollData = {
|
||||||
caracValue: request.carac_vue,
|
caracValue: request.carac_vue,
|
||||||
finalLevel: niveau,
|
finalLevel: niveau,
|
||||||
showDice: false
|
showDice: false
|
||||||
};
|
};
|
||||||
await RdDResolutionTable.rollData(rollData);
|
await RdDResolutionTable.rollData(rollData);
|
||||||
let nbAstral = this.getNombreAstral(request.date);
|
let nbAstral = await this.getNombreAstral(request.date);
|
||||||
request.rolled = rollData.rolled;
|
request.rolled = rollData.rolled;
|
||||||
request.isValid = true;
|
request.isValid = true;
|
||||||
if (!request.rolled.isSuccess) {
|
if (!request.rolled.isSuccess) {
|
||||||
request.isValid = false;
|
request.isValid = false;
|
||||||
nbAstral = await RdDDice.rollTotal("1dhr"+nbAstral);
|
nbAstral = await RdDDice.rollTotal("1dhr" + nbAstral);
|
||||||
// Mise à jour des nombres astraux du joueur
|
// Mise à jour des nombres astraux du joueur
|
||||||
let astralData = this.listeNombreAstral.find((nombreAstral, i) => nombreAstral.index == request.date);
|
let astralData = this.listeNombreAstral.find((nombreAstral, i) => nombreAstral.index == request.date);
|
||||||
astralData.valeursFausses.push({ actorId: request.id, nombreAstral: nbAstral });
|
astralData.valeursFausses.push({ actorId: request.id, nombreAstral: nbAstral });
|
||||||
@ -299,11 +307,11 @@ export class RdDCalendrier extends Application {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
getAjustementAstrologique(heureNaissance, name = 'inconnu') {
|
async getAjustementAstrologique(heureNaissance, name = 'inconnu') {
|
||||||
let heure = Grammar.toLowerCaseNoAccent(heureNaissance);
|
let heure = Grammar.toLowerCaseNoAccent(heureNaissance);
|
||||||
if (heure && heuresDef[heure]) {
|
if (heure && heuresDef[heure]) {
|
||||||
let hn = heuresDef[heure].heure;
|
let hn = heuresDef[heure].heure;
|
||||||
let chiffreAstral = this.getCurrentNombreAstral();
|
let chiffreAstral = await this.getCurrentNombreAstral();
|
||||||
let heureCourante = this.calendrier.heureRdD;
|
let heureCourante = this.calendrier.heureRdD;
|
||||||
let ecartChance = (hn + chiffreAstral - heureCourante) % 12;
|
let ecartChance = (hn + chiffreAstral - heureCourante) % 12;
|
||||||
switch (ecartChance) {
|
switch (ecartChance) {
|
||||||
@ -350,12 +358,12 @@ export class RdDCalendrier extends Application {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
updateDisplay() {
|
async updateDisplay() {
|
||||||
let data = this.fillCalendrierData();
|
let data = this.fillCalendrierData();
|
||||||
// Rebuild data
|
// 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) {
|
if (game.user.isGM) {
|
||||||
dateHTML = dateHTML + " - NA: " + this.getCurrentNombreAstral();
|
dateHTML = dateHTML + " - NA: " + await this.getCurrentNombreAstral();
|
||||||
}
|
}
|
||||||
for (let handle of document.getElementsByClassName("calendar-date-rdd")) {
|
for (let handle of document.getElementsByClassName("calendar-date-rdd")) {
|
||||||
handle.innerHTML = dateHTML;
|
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.minutesRelative = Number(calendrierData.minutesRelative);
|
||||||
this.calendrier.jour = Number(calendrierData.jourMois) - 1;
|
this.calendrier.jour = Number(calendrierData.jourMois) - 1;
|
||||||
this.calendrier.moisRdD = heuresList.findIndex(mois => mois === calendrierData.moisKey);
|
this.calendrier.moisRdD = heuresList.findIndex(mois => mois === calendrierData.moisKey);
|
||||||
this.calendrier.heureRdD = heuresList.findIndex(heure => heure === calendrierData.heureKey);; // Index dans heuresList
|
this.calendrier.heureRdD = heuresList.findIndex(heure => heure === calendrierData.heureKey);; // Index dans heuresList
|
||||||
game.settings.set("foundryvtt-reve-de-dragon", "calendrier", duplicate(this.calendrier));
|
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 */
|
/** @override */
|
||||||
activateListeners(html) {
|
async activateListeners(html) {
|
||||||
super.activateListeners(html);
|
super.activateListeners(html);
|
||||||
|
|
||||||
HtmlUtility._showControlWhen($(".gm-only"), game.user.isGM);
|
HtmlUtility._showControlWhen($(".gm-only"), game.user.isGM);
|
||||||
|
|
||||||
this.updateDisplay();
|
await this.updateDisplay();
|
||||||
|
|
||||||
html.find('.calendar-btn').click(ev => this.onCalendarButton(ev));
|
html.find('.calendar-btn').click(ev => this.onCalendarButton(ev));
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user