Fix regression calendrier
This commit is contained in:
parent
c82618e3ab
commit
5cecbf3d4d
@ -45,9 +45,13 @@ export class RdDCalendrier extends Application {
|
||||
return { top: 200, left: 200 };
|
||||
}
|
||||
|
||||
static getDefSigne(moisRdD) {
|
||||
moisRdD = moisRdD % RDD_MOIS_PAR_AN;
|
||||
return Object.values(heuresDef).find(h => h.heure == moisRdD);
|
||||
static getDefSigne(chiffre) {
|
||||
chiffre = chiffre % RDD_MOIS_PAR_AN;
|
||||
return Object.values(heuresDef).find(h => h.heure == chiffre);
|
||||
}
|
||||
|
||||
static getChiffreFromSigne(signe) {
|
||||
return heuresList.indexOf(signe);
|
||||
}
|
||||
|
||||
static getCalendrier(index) {
|
||||
@ -63,55 +67,50 @@ export class RdDCalendrier extends Application {
|
||||
return calendrier;
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async initCalendrier() {
|
||||
// Calendrier
|
||||
this.calendrier = duplicate(game.settings.get("foundryvtt-reve-de-dragon", "calendrier"));
|
||||
this.calendrier.annee = this.calendrier.annee ?? (this.calendrier.moisRdD == RDD_MOIS_PAR_AN ? 1 : 0);
|
||||
this.calendrier.moisRdD = (this.calendrier.moisRdD ?? 0) % RDD_MOIS_PAR_AN;
|
||||
|
||||
//console.log("CALENDRIER", this.calendrier);
|
||||
if (this.calendrier == undefined || this.calendrier.moisRdD == undefined) {
|
||||
this.calendrier = RdDCalendrier.getCalendrier(0);
|
||||
if (game.user.isGM) { // Uniquement si GM
|
||||
game.settings.set("foundryvtt-reve-de-dragon", "calendrier", this.calendrier);
|
||||
}
|
||||
}
|
||||
constructor() {
|
||||
super();
|
||||
// position
|
||||
this.calendrierPos = duplicate(game.settings.get("foundryvtt-reve-de-dragon", "calendrier-pos"));
|
||||
if (this.calendrierPos == undefined || this.calendrierPos.top == undefined) {
|
||||
this.calendrierPos = RdDCalendrier.createCalendrierPos();
|
||||
if (game.user.isGM) { // Uniquement si GM
|
||||
game.settings.set("foundryvtt-reve-de-dragon", "calendrier-pos", this.calendrierPos);
|
||||
}
|
||||
game.settings.set("foundryvtt-reve-de-dragon", "calendrier-pos", this.calendrierPos);
|
||||
}
|
||||
|
||||
// Calendrier
|
||||
this.calendrier = duplicate(game.settings.get("foundryvtt-reve-de-dragon", "calendrier") ?? RdDCalendrier.getCalendrier(0));
|
||||
this.calendrier.annee = this.calendrier.annee ?? Math.floor((this.calendrier.moisRdD ?? 0) / RDD_MOIS_PAR_AN);
|
||||
this.calendrier.moisRdD = (this.calendrier.moisRdD ?? 0) % RDD_MOIS_PAR_AN;
|
||||
|
||||
if (game.user.isGM) { // Uniquement si GM
|
||||
game.settings.set("foundryvtt-reve-de-dragon", "calendrier", this.calendrier);
|
||||
}
|
||||
|
||||
// nombre astral
|
||||
if (game.user.isGM) {
|
||||
this.listeNombreAstral = this._loadListNombreAstral();
|
||||
await this.rebuildListeNombreAstral(false); // Ensure always up-to-date
|
||||
this.listeNombreAstral = this.getListeNombreAstral();
|
||||
this.rebuildListeNombreAstral(false); // Ensure always up-to-date
|
||||
}
|
||||
console.log(this.calendrier, this.calendrierPos, this.listeNombreAstral);
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
_loadListNombreAstral() {
|
||||
const listeNombreAstraux = game.settings.get("foundryvtt-reve-de-dragon", "liste-nombre-astral");
|
||||
return listeNombreAstraux ?? [];
|
||||
getListeNombreAstral() {
|
||||
return game.settings.get("foundryvtt-reve-de-dragon", "liste-nombre-astral") ?? [];
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static get defaultOptions() {
|
||||
const options = super.defaultOptions;
|
||||
options.template = "systems/foundryvtt-reve-de-dragon/templates/calendar-template.html";
|
||||
options.popOut = false;
|
||||
options.resizable = false;
|
||||
return options;
|
||||
return mergeObject(super.defaultOptions, {
|
||||
template: "systems/foundryvtt-reve-de-dragon/templates/calendar-template.html",
|
||||
popOut: false,
|
||||
resizable: false
|
||||
});
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
getDateFromIndex(index) {
|
||||
const date = RdDCalendrier.getCalendrier(index ?? this.getCurrentDayIndex());
|
||||
return (date.jour+1) + ' ' + heuresDef[heuresList[date.moisRdD]].label;
|
||||
return (date.jour + 1) + ' ' + RdDCalendrier.getDefSigne(date.moisRdD).label;
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
@ -152,7 +151,7 @@ export class RdDCalendrier extends Application {
|
||||
const nombreAstral = await RdDDice.rollTotal("1dh", { showDice: showDice, hideDice: !showDice, rollMode: "selfroll" });
|
||||
const dateFuture = this.getDateFromIndex(index);
|
||||
if (showDice) {
|
||||
ChatMessage.create({
|
||||
ChatMessage.create({
|
||||
whisper: ChatMessage.getWhisperRecipients("GM"),
|
||||
content: `Le chiffre astrologique du ${dateFuture} sera le ${nombreAstral}`
|
||||
});
|
||||
@ -183,34 +182,23 @@ export class RdDCalendrier extends Application {
|
||||
|
||||
/* -------------------------------------------- */
|
||||
getNombreAstral(indexDate) {
|
||||
if (this.listeNombreAstral == undefined) {
|
||||
this.listeNombreAstral = this._loadListNombreAstral() || [];
|
||||
}
|
||||
let liste = this.listeNombreAstral;
|
||||
if ( game.user.isGM ) {
|
||||
if ( typeof(liste) != 'Array' || liste.length == 0 ) {
|
||||
this.rebuildListeNombreAstral();
|
||||
liste = this.listeNombreAstral;
|
||||
}
|
||||
}
|
||||
let astralData = liste.find((nombreAstral, i) => nombreAstral.index == indexDate);
|
||||
|
||||
let astralData = this.getListeNombreAstral().find((nombreAstral, i) => nombreAstral.index == indexDate);
|
||||
return astralData?.nombreAstral;
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async rebuildListeNombreAstral(showDice = true) {
|
||||
if (game.user.isGM) {
|
||||
console.log("rebuildListeNombreAstral", showDice);
|
||||
let jourCourant = this.getCurrentDayIndex();
|
||||
|
||||
let newList = [];
|
||||
for (let i = 0; i < MAX_NOMBRE_ASTRAL; i++) {
|
||||
let dayIndex = jourCourant + i;
|
||||
let na = this.listeNombreAstral.find(n => n.index == dayIndex);
|
||||
if (na) {
|
||||
newList[i] = duplicate(na);
|
||||
newList[i] = na;
|
||||
} else {
|
||||
newList[i] = await this.ajouterNombreAstral(dayIndex, showDice );
|
||||
newList[i] = await this.ajouterNombreAstral(dayIndex, showDice);
|
||||
}
|
||||
}
|
||||
//console.log("SAVE list", newList, jourCourant);
|
||||
@ -242,7 +230,7 @@ export class RdDCalendrier extends Application {
|
||||
}
|
||||
if (this.calendrier.heureRdD >= RDD_HEURES_PAR_JOUR) {
|
||||
this.calendrier.heureRdD -= RDD_HEURES_PAR_JOUR;
|
||||
this.incrementerJour();
|
||||
await this.incrementerJour();
|
||||
}
|
||||
game.settings.set("foundryvtt-reve-de-dragon", "calendrier", duplicate(this.calendrier));
|
||||
// Notification aux joueurs
|
||||
@ -253,10 +241,10 @@ export class RdDCalendrier extends Application {
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
incrementerJour() {
|
||||
async incrementerJour() {
|
||||
const index = this.getCurrentDayIndex() + 1;
|
||||
this.calendrier = RdDCalendrier.getCalendrier(index);
|
||||
this.rebuildListeNombreAstral();
|
||||
await this.rebuildListeNombreAstral();
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
@ -268,7 +256,7 @@ export class RdDCalendrier extends Application {
|
||||
/* -------------------------------------------- */
|
||||
async positionnerHeure(indexHeure) {
|
||||
if (indexHeure <= this.calendrier.heureRdD) {
|
||||
this.incrementerJour();
|
||||
await this.incrementerJour();
|
||||
}
|
||||
this.calendrier.heureRdD = indexHeure;
|
||||
this.calendrier.minutesRelative = 0;
|
||||
@ -277,13 +265,14 @@ export class RdDCalendrier extends Application {
|
||||
|
||||
/* -------------------------------------------- */
|
||||
fillCalendrierData(formData = {}) {
|
||||
console.log(this.calendrier);
|
||||
let moisKey = heuresList[this.calendrier.moisRdD];
|
||||
let heureKey = heuresList[this.calendrier.heureRdD];
|
||||
console.log(moisKey, heureKey);
|
||||
|
||||
const mois = heuresDef[moisKey];
|
||||
const heure = heuresDef[heureKey];
|
||||
|
||||
//console.log(moisKey, heureKey);
|
||||
formData.heureKey = heureKey;
|
||||
formData.moisKey = moisKey;
|
||||
formData.jourMois = this.calendrier.jour + 1;
|
||||
@ -436,8 +425,8 @@ export class RdDCalendrier extends Application {
|
||||
async saveEditeur(calendrierData) {
|
||||
this.calendrier.minutesRelative = Number(calendrierData.minutesRelative);
|
||||
this.calendrier.jour = Number(calendrierData.jourMois) - 1;
|
||||
this.calendrier.moisRdD = RdDCalendrier.getDefSigne(calendrierData.moisKey);
|
||||
this.calendrier.heureRdD = RdDCalendrier.getDefSigne(calendrierData.heureKey); // Index dans heuresList
|
||||
this.calendrier.moisRdD = RdDCalendrier.getChiffreFromSigne(calendrierData.moisKey);
|
||||
this.calendrier.heureRdD = RdDCalendrier.getChiffreFromSigne(calendrierData.heureKey);
|
||||
game.settings.set("foundryvtt-reve-de-dragon", "calendrier", duplicate(this.calendrier));
|
||||
|
||||
await this.rebuildListeNombreAstral();
|
||||
@ -454,7 +443,7 @@ export class RdDCalendrier extends Application {
|
||||
async showCalendarEditor() {
|
||||
let calendrierData = duplicate(this.fillCalendrierData());
|
||||
if (this.editeur == undefined) {
|
||||
calendrierData.jourMoisOptions = this.buildJoursMois();
|
||||
calendrierData.jourMoisOptions = RdDCalendrier.buildJoursMois();
|
||||
calendrierData.heuresOptions = [0, 1];
|
||||
calendrierData.minutesOptions = Array(RDD_MINUTES_PAR_HEURES).fill().map((item, index) => 0 + index);
|
||||
let html = await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/calendar-editor-template.html', calendrierData);
|
||||
|
@ -221,7 +221,6 @@ Hooks.once("ready", async function () {
|
||||
/* -------------------------------------------- */
|
||||
/* Affiche/Init le calendrier */
|
||||
let calendrier = new RdDCalendrier();
|
||||
await calendrier.initCalendrier();
|
||||
let templatePath = "systems/foundryvtt-reve-de-dragon/templates/calendar-template.html";
|
||||
let templateData = {};
|
||||
renderTemplate(templatePath, templateData).then(html => {
|
||||
|
Loading…
Reference in New Issue
Block a user