forked from public/foundryvtt-reve-de-dragon
		
	Fix: recalcul nombre astral pour retour arrière
quand on remet la date en arrière (suite à erreur sur l'avancement du calendrier), le nombre astral est maintenant correctement initialisé (nombres aléatoires) Ce qui permet de ne plus tomber sur le cas "N/A" ou sur un nombre non disponible, et donc débloque la fenêtre de jets de dés (bloquée à cause de l'ajustement astrologique)
This commit is contained in:
		| @@ -117,45 +117,33 @@ export class RdDCalendrier extends Application { | |||||||
|  |  | ||||||
|   /* -------------------------------------------- */ |   /* -------------------------------------------- */ | ||||||
|   getCurrentNombreAstral() { |   getCurrentNombreAstral() { | ||||||
|     let index = this.getCurrentDayIndex(); |     let indexDate = this.getCurrentDayIndex(); | ||||||
|     return this.getNombreAstral(index); |     return this.getNombreAstral(indexDate); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   /* -------------------------------------------- */ |   /* -------------------------------------------- */ | ||||||
|   getNombreAstral( index ) { |   getNombreAstral( indexDate ) { | ||||||
|     const liste = this.listeNombreAstral || this._loadListNombreAstral(); |     const liste = this.listeNombreAstral ?? this._loadListNombreAstral(); | ||||||
|     let astralData = liste.find( (nombreAstral, i) => nombreAstral.index == index ); |     let astralData = liste.find( (nombreAstral, i) => nombreAstral.index == indexDate ); | ||||||
|     if ( astralData == undefined ) { |     if (! astralData?.nombreAstral ) { | ||||||
|       this.rebuildListeNombreAstral(); |       this.rebuildListeNombreAstral(); | ||||||
|       astralData = liste.find( (nombreAstral, i) => nombreAstral.index == index ); |       astralData = liste.find( (nombreAstral, i) => nombreAstral.index == indexDate ); | ||||||
|     } |     } | ||||||
|     return astralData.nombreAstral || "N/A"; |     return astralData?.nombreAstral ?? "N/A"; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   /* -------------------------------------------- */ |   /* -------------------------------------------- */ | ||||||
|   rebuildListeNombreAstral() { |   rebuildListeNombreAstral() { | ||||||
|     // Auto-create if needed |  | ||||||
|     if ( this.listeNombreAstral == undefined)  |  | ||||||
|       this.listeNombreAstral = []; |  | ||||||
|  |  | ||||||
|     // Nettoyage des nombres astraux anciens |  | ||||||
|     let jourCourant = this.getCurrentDayIndex(); |     let jourCourant = this.getCurrentDayIndex(); | ||||||
|     let jourFin = jourCourant + 12; |     let jourFin = jourCourant + 12; | ||||||
|     let newList = this.listeNombreAstral.filter( (nombreAstral, i) =>  nombreAstral && nombreAstral.index >= jourCourant && nombreAstral.index < jourFin); |     let newList = [0,1,2,3,4,5,6,7,8,9,10,11].map( i => this.ajouterNombreAstral(jourCourant + i)); | ||||||
|     //console.log("LSTES", this.listeNombreAstral, newList ); |     if (this.listeNombreAstral) { | ||||||
|  |       for (const na of this.listeNombreAstral) { | ||||||
|     let lastDay = jourCourant; |         if (na && na.index >= jourCourant && na.index < jourFin) { | ||||||
|     for (let i=0; i < MAX_NOMBRE_ASTRAL; i++) { |           newList[na.index - jourCourant] = na; | ||||||
|       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 ); |     game.settings.set("foundryvtt-reve-de-dragon", "liste-nombre-astral", this.listeNombreAstral ); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user