This commit is contained in:
2020-12-11 08:29:24 +01:00
parent e74031be0b
commit 349f8fc875
13 changed files with 165 additions and 47 deletions

View File

@ -23,7 +23,7 @@ const saisonsDef = { "printemps": { label: "Printemps"},
"hiver": { label: "Hiver"}
};
const RDD_JOUR_PAR_MOIS = 28;
const MAX_NOMBRE_ASTRAL = 30;
const MAX_NOMBRE_ASTRAL = 12;
/* -------------------------------------------- */
export class RdDCalendrier extends Application {
@ -38,7 +38,7 @@ export class RdDCalendrier extends Application {
this.calendrier.heuresRelative = 0;
this.calendrier.minutesRelative = 0;
this.calendrier.moisRdD = 0; // Index dans heuresList
this.calendrier.jour = 1;
this.calendrier.jour = 0;
if ( game.user.isGM) { // Uniquement si GM
game.settings.set("foundryvtt-reve-de-dragon", "calendrier", this.calendrier );
}
@ -72,9 +72,9 @@ export class RdDCalendrier extends Application {
/* -------------------------------------------- */
getDateFromIndex( index ) {
let month = Math.ceil(index / 28);
let day = index - (month*28);
return day+"/"+heuresList[month];
let month = Math.floor(index / 28);
let day = (index - (month*28)) + 1;
return day+" "+heuresList[month];
}
/* -------------------------------------------- */
@ -94,29 +94,34 @@ export class RdDCalendrier extends Application {
/* -------------------------------------------- */
getCurrentNombreAstral() {
let index = this.getCurrentDayIndex();
return this.listeNombreAstral[index].nombreAstral;
let astralData = this.listeNombreAstral.find( (nombreAstral, i) => nombreAstral.index == index );
return astralData.nombreAstral || "N/A";
}
/* -------------------------------------------- */
rebuildListeNombreAstral() {
// Auto-create if needed
if ( this.listeNombreAstral == undefined)
this.listeNombreAstral = {};
this.listeNombreAstral = [];
// Nettoyage des nombres astraux anciens
let jourCourant = this.getCurrentDayIndex();
let keys = Object.keys(this.listeNombreAstral);
for ( let jourIndex of keys) {
if ( Number(jourIndex) < jourCourant) {
this.listeNombreAstral[jourIndex] = undefined;
}
}
// A partir du jour courant, génération des nombres avec gestion des trous potentiels
for (let jourIndex = jourCourant; jourIndex<jourCourant+MAX_NOMBRE_ASTRAL; jourIndex++) {
if ( this.listeNombreAstral[jourIndex] == undefined) {
this.listeNombreAstral[jourIndex] = this.ajouterNombreAstral(jourIndex);
let newList = this.listeNombreAstral.filter( (nombreAstral, i) => nombreAstral.index >= jourCourant );
//console.log("LSTES", this.listeNombreAstral, newList );
let lastDay = jourCourant;
for (let i=0; i < MAX_NOMBRE_ASTRAL; i++) {
let nombreAstral = newList[i];
if ( nombreAstral ) {
lastDay = nombreAstral.index + 1;
} else {
newList.push( this.ajouterNombreAstral( lastDay) );
lastDay += 1;
}
}
this.listeNombreAstral = newList;
game.settings.set("foundryvtt-reve-de-dragon", "liste-nombre-astral", this.listeNombreAstral );
}
@ -147,14 +152,14 @@ export class RdDCalendrier extends Application {
/* -------------------------------------------- */
incrementerJour( ) {
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;
if ( this.calendrier.jour <= 0)
this.calendrier.jour = 1;
this.calendrier.jour = 0;
this.calendrier.moisRdD += 1;
// Reconstruire les nombres astraux
this.rebuildListeNombreAstral();
}
this.rebuildListeNombreAstral();
}
/* -------------------------------------------- */
@ -181,7 +186,7 @@ export class RdDCalendrier extends Application {
data.heureKey = heureKey;
data.moisKey = moisKey;
data.nomMois = heuresDef[moisKey].label; // heures et mois nommés identiques
data.jourMois = this.calendrier.jour;
data.jourMois = this.calendrier.jour + 1;
data.nomHeure = heuresDef[heureKey].label;
data.nomSaison = saisonsDef[heuresDef[moisKey].saison].label;
data.heuresRelative = this.calendrier.heuresRelative;
@ -238,7 +243,7 @@ export class RdDCalendrier extends Application {
saveEditeur( calendrierData ) {
this.calendrier.heuresRelative = Number(calendrierData.heuresRelative);
this.calendrier.minutesRelative = Number(calendrierData.minutesRelative);
this.calendrier.jour = Number(calendrierData.jourMois);
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) );
@ -264,18 +269,18 @@ export class RdDCalendrier extends Application {
/* -------------------------------------------- */
async showAstrologieEditor() {
let calendrierData = duplicate( this.fillCalendrierData( ) );
calendrierData.astrologieData = duplicate( this.listeNombreAstral );
for (let index in calendrierData.astrologieData ) {
let astralData = calendrierData.astrologieData[index];
astralData.humanDate = this.getDateFromIndex( index );
let calendrierData = duplicate( this.fillCalendrierData( ) );
let astrologieArray = [];
for (let astralData of this.listeNombreAstral ) {
astralData.humanDate = this.getDateFromIndex( astralData.index );
astrologieArray.push( duplicate(astralData ) );
}
if ( this.astrologieEditeur == undefined ) {
let html = await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/calendar-astrologie-template.html', calendrierData );
this.astrologieEditeur = new RdDAstrologieEditeur(html, this, calendrierData )
}
this.astrologieEditeur.updateData( calendrierData );
this.astrologieEditeur.render(true);
//console.log("ASTRO", astrologieArray);
calendrierData.astrologieData = astrologieArray;
let html = await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/calendar-astrologie-template.html', calendrierData );
let astrologieEditeur = new RdDAstrologieEditeur(html, this, calendrierData )
astrologieEditeur.updateData( calendrierData );
astrologieEditeur.render(true);
}
/* -------------------------------------------- */