Intégration astrologie

Intégration du thème astral dans les fenêtres d'astrologie
This commit is contained in:
2023-03-08 02:02:40 +01:00
parent 42ed5da2d4
commit 77cf72a752
20 changed files with 461 additions and 566 deletions

View File

@ -1,19 +1,14 @@
import { RdDCalendrierEditeur } from "./rdd-calendrier-editeur.js";
import { RdDAstrologieEditeur } from "./rdd-astrologie-editeur.js";
import { RdDResolutionTable } from "./rdd-resolution-table.js";
import { RdDUtility } from "./rdd-utility.js";
import { RdDDice } from "./rdd-dice.js";
import { Misc } from "./misc.js";
import { HIDE_DICE, SHOW_DICE, SYSTEM_RDD, SYSTEM_SOCKET_ID } from "./constants.js";
import { DialogChronologie } from "./dialog-chronologie.js";
import { RdDTimestamp, WORLD_TIMESTAMP_SETTING } from "./rdd-timestamp.js";
import { MAX_NOMBRE_ASTRAL, RdDTimestamp, WORLD_TIMESTAMP_SETTING } from "./rdd-timestamp.js";
import { DialogChateauDormant } from "./sommeil/dialog-chateau-dormant.js";
import { ReglesOptionelles } from "./settings/regles-optionelles.js";
const RDD_JOUR_PAR_MOIS = 28;
const RDD_HEURES_PAR_JOUR = 12;
const MAX_NOMBRE_ASTRAL = 12;
const JOURS_DU_MOIS = Array(RDD_JOUR_PAR_MOIS).fill().map((item, index) => 1 + index);
import { APP_ASTROLOGIE_REFRESH, AppAstrologie } from "./sommeil/app-astrologie.js";
/* -------------------------------------------- */
export class RdDCalendrier extends Application {
@ -43,10 +38,10 @@ export class RdDCalendrier extends Application {
if (Misc.isUniqueConnectedGM()) { // Uniquement si GM
RdDTimestamp.setWorldTime(this.timestamp);
this.listeNombreAstral = this.getListeNombreAstral();
this.rebuildListeNombreAstral(HIDE_DICE); // Ensure always up-to-date
this.nombresAstraux = this.getNombresAstraux();
this.rebuildNombresAstraux(HIDE_DICE); // Ensure always up-to-date
}
console.log('RdDCalendrier.constructor()', this.timestamp, this.timestamp.toCalendrier(), this.calendrierPos, this.listeNombreAstral);
console.log('RdDCalendrier.constructor()', this.timestamp, this.timestamp.toCalendrier(), this.calendrierPos, this.nombresAstraux);
Hooks.on('updateSetting', async (setting, update, options, id) => this.onUpdateSetting(setting, update, options, id));
}
@ -150,7 +145,7 @@ export class RdDCalendrier extends Application {
});
}
/* -------------------------------------------- */
getListeNombreAstral() {
getNombresAstraux() {
return game.settings.get(SYSTEM_RDD, "liste-nombre-astral") ?? [];
}
@ -212,8 +207,8 @@ export class RdDCalendrier extends Application {
}
/* -------------------------------------------- */
resetNombreAstral() {
this.listeNombreAstral = [];
resetNombresAstraux() {
this.nombresAstraux = [];
game.settings.set(SYSTEM_RDD, "liste-nombre-astral", []);
game.socket.emit(SYSTEM_SOCKET_ID, {
@ -233,30 +228,39 @@ export class RdDCalendrier extends Application {
if (indexDate == undefined) {
indexDate = this.timestamp.indexDate;
}
const listNombreAstral = this.getListeNombreAstral();
let astralData = listNombreAstral.find((nombreAstral, i) => nombreAstral.index == indexDate);
this.nombresAstraux = this.getNombresAstraux();
let astralData = this.nombresAstraux.find((nombreAstral, i) => nombreAstral.index == indexDate);
return astralData?.nombreAstral ?? 0;
}
/* -------------------------------------------- */
async rebuildListeNombreAstral(showDice = HIDE_DICE) {
async rebuildNombresAstraux(showDice = HIDE_DICE) {
if (Misc.isUniqueConnectedGM()) {
let newList = [];
for (let i = 0; i < MAX_NOMBRE_ASTRAL; i++) {
let dayIndex = this.timestamp.indexDate + i;
let na = this.listeNombreAstral.find(n => n.index == dayIndex);
let na = this.nombresAstraux.find(n => n.index == dayIndex);
if (na) {
newList[i] = na;
} else {
newList[i] = await this.ajouterNombreAstral(dayIndex, showDice);
}
}
this.listeNombreAstral = newList;
this.nombresAstraux = newList;
game.settings.set(SYSTEM_RDD, "liste-nombre-astral", newList);
game.actors.forEach(actor => actor.deleteEmbeddedDocuments("Item", actor.listItems('nombreastral').map(it => it.id)));
game.actors.filter(it => it.isPersonnage()).forEach(actor => actor.supprimerAnciensNombresAstraux());
this.notifyChangeNombresAstraux();
}
}
notifyChangeNombresAstraux() {
Hooks.callAll(APP_ASTROLOGIE_REFRESH);
game.socket.emit(SYSTEM_SOCKET_ID, {
msg: "msg_refresh_nombre_astral",
data: {}
});
}
/* -------------------------------------------- */
async setNewTimestamp(newTimestamp) {
const oldTimestamp = this.timestamp;
@ -266,7 +270,7 @@ export class RdDCalendrier extends Application {
await DialogChateauDormant.create();
}
this.timestamp = newTimestamp;
await this.rebuildListeNombreAstral();
await this.rebuildNombresAstraux();
this.updateDisplay();
}
@ -362,16 +366,16 @@ export class RdDCalendrier extends Application {
}
addNbAstralIncorect(actorId, date, nbAstral) {
let astralData = this.listeNombreAstral.find((nombreAstral, i) => nombreAstral.index == date);
let astralData = this.nombresAstraux.find((nombreAstral, i) => nombreAstral.index == date);
astralData.valeursFausses.push({ actorId: actorId, nombreAstral: nbAstral });
game.settings.set(SYSTEM_RDD, "liste-nombre-astral", this.listeNombreAstral);
game.settings.set(SYSTEM_RDD, "liste-nombre-astral", this.nombresAstraux);
}
/* -------------------------------------------- */
getAjustementAstrologique(heureNaissance, name = undefined) {
let defHeure = RdDTimestamp.findHeure(heureNaissance);
if (defHeure) {
return RdDCalendrier.ajustementAstrologiqueHeure(defHeure.heure, this.getNombreAstral(), this.timestamp.heure);
return RdDTimestamp.ajustementAstrologiqueHeure(defHeure.heure, this.getNombreAstral(), this.timestamp.heure);
}
else if (name) {
ui.notifications.warn(name + " n'a pas d'heure de naissance, ou elle est incorrecte : " + heureNaissance);
@ -382,20 +386,6 @@ export class RdDCalendrier extends Application {
return 0;
}
static ajustementAstrologiqueHeure(hn, nbAstral, heure) {
switch (RdDCalendrier.ecartHeureChance(hn, nbAstral, heure)) {
case 0: return 4;
case 4: case 8: return 2;
case 6: return -4;
case 3: case 9: return -2;
}
return 0;
}
static ecartHeureChance(heureNaissance, nombreAstral, heure) {
return ((heureNaissance + nombreAstral - heure) % RDD_HEURES_PAR_JOUR + RDD_HEURES_PAR_JOUR) % RDD_HEURES_PAR_JOUR;
}
/* -------------------------------------------- */
getData() {
let formData = super.getData();
@ -469,41 +459,8 @@ export class RdDCalendrier extends Application {
this.editeur.render(true);
}
static buildJoursMois() { return JOURS_DU_MOIS; }
/* -------------------------------------------- */
async showAstrologieEditor() {
const calendrierData = duplicate(this.fillCalendrierData());
this.listeNombreAstral = this.listeNombreAstral || [];
calendrierData.astrologieData = this.listeNombreAstral.map(astro => {
const timestamp = new RdDTimestamp({ indexDate: astro.index });
astro.date = { mois: timestamp.mois, jour: timestamp.jour + 1 }
for (let vf of astro.valeursFausses) {
let actor = game.actors.get(vf.actorId);
vf.actorName = (actor) ? actor.name : "Inconnu";
}
return astro;
});
const nbAstral = this.getNombreAstral()
calendrierData.heures = Array.from(Array(RDD_HEURES_PAR_JOUR).keys());
calendrierData.ajustementsActeur = game.actors.filter(it => it.isPersonnage() && it.hasPlayerOwner).map(actor => {
return {
actor,
ajustements: calendrierData.heures.map(heure => {
const hn = RdDTimestamp.findHeure(actor.getHeureNaissance())?.heure;
return {
heure,
ajustement: RdDCalendrier.ajustementAstrologiqueHeure(hn, nbAstral, heure)
}
})
}
});
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);
await AppAstrologie.create();
}
}