#52 Gestion astrologie

This commit is contained in:
sladecraven 2020-12-08 23:28:29 +01:00
parent aa97f16f3a
commit b8f01d8da4
1 changed files with 51 additions and 28 deletions

View File

@ -55,26 +55,12 @@ export class RdDCalendrier extends Application {
if ( game.user.isGM) {
this.listeNombreAstral = duplicate(game.settings.get("foundryvtt-reve-de-dragon", "liste-nombre-astral"));
if ( this.listeNombreAstral == undefined ) {
let start = this.getCurrentDayIndex();
let dayList = {}
for(let index=start; index<=start+MAX_NOMBRE_ASTRAL; index++) { // Construction des nombres astraux pour les prochains jours
dayList[index] = this.ajouterNombreAstral();
}
this.listeNombreAstral = dayList;
game.settings.set("foundryvtt-reve-de-dragon", "liste-nombre-astral", this.listeNombreAstral );
this.rebuildListeNombreAstral();
}
}
console.log(this.calendrier, this.calendrierPos);
}
/* -------------------------------------------- */
ajouterNombreAstral(index) {
return {
nombreAstral: new Roll("1d12").roll().total,
valeursFausses: [],
index: index
}
}
/* -------------------------------------------- */
getCurrentDayIndex( ) {
@ -89,7 +75,39 @@ export class RdDCalendrier extends Application {
options.resizable = false;
return options;
}
/* -------------------------------------------- */
ajouterNombreAstral(index) {
return {
nombreAstral: new Roll("1d12").roll().total,
valeursFausses: [],
index: index
}
}
/* -------------------------------------------- */
rebuildListeNombreAstral() {
// Auto-create if needed
if ( this.listeNombreAstral == undefined)
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);
}
}
game.settings.set("foundryvtt-reve-de-dragon", "liste-nombre-astral", this.listeNombreAstral );
}
/* -------------------------------------------- */
incrementTime(heure, minute = 0) {
this.calendrier.minutesRelative += minute;
@ -104,16 +122,7 @@ export class RdDCalendrier extends Application {
}
if ( this.calendrier.heureRdD > 11 ) {
this.calendrier.heureRdD -= 11;
this.calendrier.jour += 1;
}
if ( this.calendrier.jour > RDD_JOUR_PAR_MOIS) {
this.calendrier.jour -= this.calendrier.jour;
if ( this.calendrier.jour <= 0)
this.calendrier.jour = 1;
this.calendrier.moisRdD += 1;
// Ajouter un nouveau nombre astral
let index = this.getCurrentDayIndex();
this.listeNombreAstral[index] = this.ajouterNombreAstral();
this.incrementerJour();
}
game.settings.set("foundryvtt-reve-de-dragon", "calendrier", duplicate(this.calendrier) );
// Notification aux joueurs
@ -123,6 +132,19 @@ export class RdDCalendrier extends Application {
} );
}
/* -------------------------------------------- */
incrementerJour( ) {
this.calendrier.jour += 1;
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.moisRdD += 1;
// Reconstruire les nombres astraux
this.rebuildListeNombreAstral();
}
}
/* -------------------------------------------- */
syncPlayerTime( calendrier ) {
this.calendrier = duplicate(calendrier); // Local copy update
@ -132,7 +154,7 @@ export class RdDCalendrier extends Application {
/* -------------------------------------------- */
positionnerHeure( indexHeure ) {
if ( indexHeure <= this.calendrier.heureRdD )
this.calendrier.jour +=1;
this.incrementerJour();
this.calendrier.heureRdD = indexHeure;
this.calendrier.minutesRelative = 0;
this.calendrier.heuresRelative = 0;
@ -206,8 +228,9 @@ export class RdDCalendrier extends Application {
this.calendrier.jour = Number(calendrierData.jourMois);
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();
this.updateDisplay();
}