From 77cf72a752c68088e4dae67cbc17da82a346891d Mon Sep 17 00:00:00 2001 From: Vincent Vandemeulebrouck Date: Wed, 8 Mar 2023 02:02:40 +0100 Subject: [PATCH] =?UTF-8?q?Int=C3=A9gration=20astrologie?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Intégration du thème astral dans les fenêtres d'astrologie --- module/actor.js | 23 +- module/actor/base-actor.js | 9 +- module/rdd-astrologie-editeur.js | 54 ----- module/rdd-astrologie-joueur.js | 100 --------- module/rdd-calendrier.js | 99 +++------ module/rdd-main.js | 4 +- module/rdd-timestamp.js | 72 +++--- module/rdd-utility.js | 4 +- module/sommeil/app-astrologie.js | 207 ++++++++++++++++++ module/sommeil/theme-astral.js | 58 ----- packs/macros.db | 2 +- styles/simple.css | 8 +- .../calendar-astrologie-template-table.html | 56 ----- templates/calendar-astrologie-template.html | 68 ------ templates/dialog-astrologie-joueur.html | 61 ------ templates/sommeil/app-astrologie.hbs | 18 ++ templates/sommeil/astrologie-gardien.hbs | 57 +++++ templates/sommeil/astrologie-joueur.hbs | 43 ++++ templates/sommeil/astrologie-theme.hbs | 32 +++ templates/sommeil/theme-astral.hbs | 52 ----- 20 files changed, 461 insertions(+), 566 deletions(-) delete mode 100644 module/rdd-astrologie-editeur.js delete mode 100644 module/rdd-astrologie-joueur.js create mode 100644 module/sommeil/app-astrologie.js delete mode 100644 module/sommeil/theme-astral.js delete mode 100644 templates/calendar-astrologie-template-table.html delete mode 100644 templates/calendar-astrologie-template.html delete mode 100644 templates/dialog-astrologie-joueur.html create mode 100644 templates/sommeil/app-astrologie.hbs create mode 100644 templates/sommeil/astrologie-gardien.hbs create mode 100644 templates/sommeil/astrologie-joueur.hbs create mode 100644 templates/sommeil/astrologie-theme.hbs delete mode 100644 templates/sommeil/theme-astral.hbs diff --git a/module/actor.js b/module/actor.js index f6b1cee3..0a005dc1 100644 --- a/module/actor.js +++ b/module/actor.js @@ -4,7 +4,6 @@ import { RdDRollDialogEthylisme } from "./rdd-roll-ethylisme.js"; import { RdDRoll } from "./rdd-roll.js"; import { RdDTMRDialog } from "./rdd-tmr-dialog.js"; import { Misc } from "./misc.js"; -import { RdDAstrologieJoueur } from "./rdd-astrologie-joueur.js"; import { RdDResolutionTable } from "./rdd-resolution-table.js"; import { RdDDice } from "./rdd-dice.js"; import { RdDRollTables } from "./rdd-rolltables.js"; @@ -36,6 +35,7 @@ import { DialogRepos } from "./sommeil/dialog-repos.js"; import { RdDBaseActor } from "./actor/base-actor.js"; import { RdDTimestamp } from "./rdd-timestamp.js"; import { RdDItemTache } from "./item-tache.js"; +import { APP_ASTROLOGIE_REFRESH, AppAstrologie } from "./sommeil/app-astrologie.js"; const POSSESSION_SANS_DRACONIC = { img: 'systems/foundryvtt-reve-de-dragon/icons/entites/possession.webp', @@ -2916,7 +2916,7 @@ export class RdDActor extends RdDBaseActor { } /* -------------------------------------------- */ - async resetNombreAstral() { + async resetNombresAstraux() { let toDelete = this.listItems('nombreastral'); const deletions = toDelete.map(it => it._id); await this.deleteEmbeddedDocuments("Item", deletions); @@ -2936,24 +2936,23 @@ export class RdDActor extends RdDBaseActor { } }; await this.createEmbeddedDocuments("Item", [item]); - // Affichage Dialog - this.astrologieNombresAstraux(); + game.system.rdd.calendrier.notifyChangeNombresAstraux(); } async supprimerAnciensNombresAstraux() { - const toDelete = this.listItems('nombreastral') - .filter(it => game.system.rdd.calendrier.isAfterIndexDate(it.system.jourindex)) - .map(it => it._id); - await this.deleteEmbeddedDocuments("Item", toDelete); + const calendrier = game.system.rdd.calendrier; + if (calendrier) { + const toDelete = this.listItems('nombreastral') + .filter(it => calendrier.isAfterIndexDate(it.system.jourindex)) + .map(it => it._id); + await this.deleteEmbeddedDocuments("Item", toDelete); + } } /* -------------------------------------------- */ async astrologieNombresAstraux() { - // Suppression des anciens nombres astraux await this.supprimerAnciensNombresAstraux(); - - // Afficher l'interface spéciale - await RdDAstrologieJoueur.create(this); + await AppAstrologie.create(this); } /* -------------------------------------------- */ diff --git a/module/actor/base-actor.js b/module/actor/base-actor.js index 21c682c0..7f6d9715 100644 --- a/module/actor/base-actor.js +++ b/module/actor/base-actor.js @@ -26,10 +26,13 @@ export class RdDBaseActor extends Actor { case "msg_remote_actor_call": return RdDBaseActor.onRemoteActorCall(sockmsg.data, sockmsg.userId); case "msg_reset_nombre_astral": - console.log("RESET ASTRAL", game.user.character); - game.user.character.resetNombreAstral(); + game.user.character.resetNombresAstraux(); + game.system.rdd.calendrier.notifyChangeNombresAstraux(); return; - } + case "msg_refresh_nombre_astral": + Hooks.callAll(APP_ASTROLOGIE_REFRESH); + return; + } } static remoteActorCall(callData, userId = undefined) { diff --git a/module/rdd-astrologie-editeur.js b/module/rdd-astrologie-editeur.js deleted file mode 100644 index 134046dc..00000000 --- a/module/rdd-astrologie-editeur.js +++ /dev/null @@ -1,54 +0,0 @@ -import { ThemeAstral } from "./sommeil/theme-astral.js"; - -/** - * Extend the base Dialog entity by defining a custom window to perform roll. - * @extends {Dialog} - */ -export class RdDAstrologieEditeur extends Dialog { - - /* -------------------------------------------- */ - constructor(html, calendrier, calendrierData) { - let dialogConf = { - title: "Editeur d'Astrologie", - content: html, - default: "fermer", - buttons: { - fermer: { label: "Fermer", callback: html => { } } - } - }; - let dialogOptions = { - classes: ["rdd-roll-dialog"], - width: 600, - height: 'fit-content', - 'max-height': 800, - 'z-index': 99999 - } - super(dialogConf, dialogOptions) - - this.calendrier = calendrier; - this.updateData(calendrierData); - } - - activateListeners(html) { - super.activateListeners(html); - this.html = html; - this.html.find('[name="theme-astral"]').click(event => ThemeAstral.create()); - this.html.find('[name="reset-nombres-astraux"]').click(event => this.resetNombreAstraux()); - } - - - /* -------------------------------------------- */ - async resetNombreAstraux() { - game.system.rdd.calendrier.resetNombreAstral(); - await game.system.rdd.calendrier.rebuildListeNombreAstral(); - - game.system.rdd.calendrier.showAstrologieEditor(); - this.close() - } - - /* -------------------------------------------- */ - updateData(calendrierData) { - this.calendrierData = duplicate(calendrierData); - } - -} diff --git a/module/rdd-astrologie-joueur.js b/module/rdd-astrologie-joueur.js deleted file mode 100644 index 04b48dc3..00000000 --- a/module/rdd-astrologie-joueur.js +++ /dev/null @@ -1,100 +0,0 @@ -import { RdDItemCompetence } from "./item-competence.js"; -import { Misc } from "./misc.js"; -import { SYSTEM_SOCKET_ID } from "./constants.js"; -import { ThemeAstral } from "./sommeil/theme-astral.js"; - - -/** - * Extend the base Dialog entity by defining a custom window to perform roll. - * @extends {Dialog} - */ -export class RdDAstrologieJoueur extends Dialog { - - /* -------------------------------------------- */ - static async create(actor) { - - let dialogData = { - nombres: this.organizeNombres(actor), - dates: game.system.rdd.calendrier.getJoursSuivants(10), - etat: actor.getEtatGeneral(), - ajustementsConditions: CONFIG.RDD.ajustementsConditions, - astrologie: RdDItemCompetence.findCompetence(actor.items, 'Astrologie') - } - const html = await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/dialog-astrologie-joueur.html', dialogData); - - const options = { classes: ["rdd-roll-dialog"], width: 600, height: 'fit-content', 'z-index': 99999 }; - const dialog = new RdDAstrologieJoueur(html, actor, dialogData, options); - dialog.render(true); - } - - /* -------------------------------------------- */ - constructor(html, actor, dialogData, dialogOptions) { - const dialogConf = { - title: "Nombres Astraux", - content: html, - default: "saveButton", - buttons: { - saveButton: { label: "Fermer", callback: html => {} } - }, - }; - super(dialogConf, dialogOptions); - - this.actor = actor; - this.dataNombreAstral = duplicate(dialogData); - } - - /* -------------------------------------------- */ - activateListeners(html) { - super.activateListeners(html); - this.html = html; - - this.html.find("[name='diffConditions']").val(0); - - this.html.find('[name="jet-astrologie"]').click(event => { - this.requestJetAstrologie(); - }); - this.html.find('[name="theme-astral"]').click(event => { - ThemeAstral.create(); - }); - } - - /* -------------------------------------------- */ - static organizeNombres(actor) { - let itemNombres = actor.listItems('nombreastral'); - let itemFiltered = {}; - for (let item of itemNombres) { - if (itemFiltered[item.system.jourindex]) { - itemFiltered[item.system.jourindex].listValues.push(item.system.value); - } else { - itemFiltered[item.system.jourindex] = { - listValues: [item.system.value], - jourlabel: item.system.jourlabel - } - } - } - return itemFiltered; - } - - /* -------------------------------------------- */ - requestJetAstrologie() { - let socketData = { - id: this.actor.id, - carac_vue: this.actor.system.carac['vue'].value, - etat: this.dataNombreAstral.etat, - astrologie: this.dataNombreAstral.astrologie, - conditions: this.html.find('[name="diffConditions"]').val(), - date: this.html.find('[name="joursAstrologie"]').val(), - userId: game.user.id - } - if (Misc.isUniqueConnectedGM()) { - game.system.rdd.calendrier.requestNombreAstral(socketData); - } else { - game.socket.emit(SYSTEM_SOCKET_ID, { - msg: "msg_request_nombre_astral", - data: socketData - }); - } - this.close(); - } - -} diff --git a/module/rdd-calendrier.js b/module/rdd-calendrier.js index 4eb6ce2e..db158270 100644 --- a/module/rdd-calendrier.js +++ b/module/rdd-calendrier.js @@ -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(); } } \ No newline at end of file diff --git a/module/rdd-main.js b/module/rdd-main.js index a6a1d188..81f12111 100644 --- a/module/rdd-main.js +++ b/module/rdd-main.js @@ -55,7 +55,7 @@ import { RdDFauneItemSheet } from "./item/sheet-faune.js"; import { RdDConteneurItemSheet } from "./item/sheet-conteneur.js"; import { RdDSigneDraconiqueItemSheet } from "./item/sheet-signedraconique.js"; import { RdDItemInventaireSheet } from "./item/sheet-base-inventaire.js"; -import { ThemeAstral } from "./sommeil/theme-astral.js"; +import { AppAstrologie } from "./sommeil/app-astrologie.js"; /** * RdD system @@ -97,7 +97,7 @@ export class SystemReveDeDragon { /* -------------------------------------------- */ async onInit() { game.system.rdd = this; - this.ThemeAstral = ThemeAstral; + this.AppAstrologie = AppAstrologie; console.log(`Initializing Reve de Dragon System`); diff --git a/module/rdd-timestamp.js b/module/rdd-timestamp.js index 6ad453b7..06b77d7d 100644 --- a/module/rdd-timestamp.js +++ b/module/rdd-timestamp.js @@ -5,10 +5,11 @@ import { RdDDice } from "./rdd-dice.js"; export const WORLD_TIMESTAMP_SETTING = "calendrier"; -const RDD_MOIS_PAR_AN = 12; -const RDD_JOURS_PAR_MOIS = 28; const RDD_JOURS_PAR_AN = 336; //RDD_JOURS_PAR_MOIS * RDD_MOIS_PAR_AN; -const RDD_HEURES_PAR_JOUR = 12; +const RDD_MOIS_PAR_AN = 12; +export const RDD_JOURS_PAR_MOIS = 28; +export const RDD_HEURES_PAR_JOUR = 12; +export const MAX_NOMBRE_ASTRAL = 12; const RDD_MINUTES_PAR_HEURES = 120; const RDD_MINUTES_PAR_JOUR = 1440; //RDD_HEURES_PAR_JOUR * RDD_MINUTES_PAR_HEURES; const ROUNDS_PAR_MINUTE = 10; @@ -46,16 +47,9 @@ const FORMULES_PERIODE = [ { code: 'jour', label: "Jours", calcul: async (t, nombre) => t.addJours(nombre) }, ] + export class RdDTimestamp { - static hh(heure) { - return heure < 9 ? `0${heure + 1}` : `${heure + 1}`; - } - - static iconeHeure(heure) { - return `systems/foundryvtt-reve-de-dragon/icons/heures/hd${RdDTimestamp.hh(heure)}.svg`; - } - static init() { game.settings.register(SYSTEM_RDD, WORLD_TIMESTAMP_SETTING, { name: WORLD_TIMESTAMP_SETTING, @@ -73,10 +67,35 @@ export class RdDTimestamp { } } + + static hh(heure) { + return heure < 9 ? `0${heure + 1}` : `${heure + 1}`; + } + + static iconeHeure(heure) { + return `systems/foundryvtt-reve-de-dragon/icons/heures/hd${RdDTimestamp.hh(heure)}.svg`; + } + + static definitions() { + return DEFINITION_HEURES + } + + static formulesDuree() { + return FORMULES_DUREE + } + + static formulesPeriode() { + return FORMULES_PERIODE + } + + static heures() { + return Misc.intArray(0, RDD_HEURES_PAR_JOUR) + } + /** - * @param signe + * @param signe * @returns L'entrée de DEFINITION_HEURES correspondant au signe - */ + */ static definition(signe) { if (signe == undefined) { signe = 0; @@ -91,23 +110,26 @@ export class RdDTimestamp { return definition } - static definitions() { - return DEFINITION_HEURES - } - static formulesDuree() { - return FORMULES_DUREE - } - - static formulesPeriode() { - return FORMULES_PERIODE - } - static imgSigneHeure(heure) { return RdDTimestamp.imgSigne(RdDTimestamp.definition(heure)); } static imgSigne(signe) { - return signe == undefined ? '' : `${signe.label}` + return signe == undefined ? '' : `${signe.label}` + } + + static ajustementAstrologiqueHeure(hn, nbAstral, heure) { + let ecart = (hn + nbAstral - heure) % RDD_HEURES_PAR_JOUR; + if (ecart < 0) { + ecart = (ecart + RDD_HEURES_PAR_JOUR) % RDD_HEURES_PAR_JOUR; + } + switch (ecart) { + case 0: return 4; + case 4: case 8: return 2; + case 6: return -4; + case 3: case 9: return -2; + } + return 0; } static handleTimestampEditor(html, path, consumeTimestamp = async (path, timestamp) => { }) { diff --git a/module/rdd-utility.js b/module/rdd-utility.js index 3eab79ac..460b96bb 100644 --- a/module/rdd-utility.js +++ b/module/rdd-utility.js @@ -234,8 +234,10 @@ export class RdDUtility { 'systems/foundryvtt-reve-de-dragon/templates/dialog-roll-meditation.html', 'systems/foundryvtt-reve-de-dragon/templates/dialog-tmr.html', 'systems/foundryvtt-reve-de-dragon/templates/dialog-roll-alchimie.html', - 'systems/foundryvtt-reve-de-dragon/templates/dialog-astrologie-joueur.html', 'systems/foundryvtt-reve-de-dragon/templates/sommeil/sommeil-actor-moral.hbs', + 'systems/foundryvtt-reve-de-dragon/templates/sommeil/astrologie-gardien.hbs', + 'systems/foundryvtt-reve-de-dragon/templates/sommeil/astrologie-joueur.hbs', + 'systems/foundryvtt-reve-de-dragon/templates/sommeil/astrologie-theme.hbs', // Calendrier 'systems/foundryvtt-reve-de-dragon/templates/calendar-template.html', 'systems/foundryvtt-reve-de-dragon/templates/calendar-editor-template.html', diff --git a/module/sommeil/app-astrologie.js b/module/sommeil/app-astrologie.js new file mode 100644 index 00000000..8e273657 --- /dev/null +++ b/module/sommeil/app-astrologie.js @@ -0,0 +1,207 @@ +import { SYSTEM_RDD } from "../constants.js"; +import { Misc } from "../misc.js"; +import { RdDTimestamp } from "../rdd-timestamp.js"; + +export const APP_ASTROLOGIE_REFRESH = `${SYSTEM_RDD}-refresh-astrologie` + +export class AppAstrologie extends Application { + static async create(actor = undefined, options = {}) { + if (actor == undefined && !game.user.isGM) { + actor = game.user.character + } + if (!actor && !game.user.isGM) { + console.error("AppAstrologie uniquement accessible pour le MJ, ou depuis un personnage pour un joueur") + } + new AppAstrologie(actor, options).render(true); + } + + + static get defaultOptions() { + return mergeObject(super.defaultOptions, { + template: "systems/foundryvtt-reve-de-dragon/templates/sommeil/app-astrologie.hbs", + title: "Astrologie", + width: 'fit-content', + height: 'fit-content', + popOut: true, + resizable: false + }); + } + + constructor(actor, options = {}) { + super(options); + this.actor = actor; + this.hookReference = Hooks.on(APP_ASTROLOGIE_REFRESH, () => this.refreshAstrologie()); + } + + getData(options) { + this.appData = super.getData(options) + const calendrier = game.system.rdd.calendrier; + mergeObject(this.appData, { + isGM: game.user.isGM, + isActor: this.actor != undefined, + calendrier: calendrier.getTimestamp().toCalendrier(), + dates: calendrier.getJoursSuivants(10), + heures: RdDTimestamp.definitions(), + actorAstrologie: this.getActorAstrologie(), + gmAstrologie: this.getGMAstrologie(calendrier), + theme: { + signeAstral: RdDTimestamp.definition(0), + signeNaissance: RdDTimestamp.definition(0) + } + }) + return this.appData; + } + + getActorAstrologie() { + if (this.actor) { + return { + actor: this.actor, + nombres: this._organizeNombresAstraux(this.actor.listItems('nombreastral')), + ajustements: CONFIG.RDD.difficultesLibres, + etat: this.actor.getEtatGeneral(), + astrologie: this.actor.getCompetence('Astrologie') + } + } + return {} + } + + _organizeNombresAstraux(nombresAstraux) { + let organized = {}; + nombresAstraux.forEach(na => { + if (!organized[na.system.jourindex]) { + organized[na.system.jourindex] = { + listValues: [], + jourlabel: na.system.jourlabel + } + } + organized[na.system.jourindex].listValues.push(na.system.value); + }) + return organized; + } + + getGMAstrologie(calendrier) { + if (game.user.isGM) { + const nbAstral = calendrier.getNombreAstral() + const heures = RdDTimestamp.heures(); + return { + ajustementsActors: game.actors.filter(it => it.isPersonnage() && it.hasPlayerOwner) + .map(actor => this.getAjustementActor(actor, nbAstral, heures)), + nombresAstraux: calendrier.getNombresAstraux().map(na => this.getDetailNombreAstral(na)) + } + } + return {} + } + + getAjustementActor(actor, nbAstral, heures) { + const hn = RdDTimestamp.findHeure(actor.getHeureNaissance())?.heure ?? 0; + return { + actor, + ajustements: heures.map(heure => { + return { heure, ajustement: RdDTimestamp.ajustementAstrologiqueHeure(hn, nbAstral, heure) }; + }) + } + } + + getDetailNombreAstral(nombreAstral) { + const detail = duplicate(nombreAstral); + const timestamp = new RdDTimestamp({ indexDate: nombreAstral.index }); + detail.date = { mois: timestamp.mois, jour: timestamp.jour + 1 }; + detail.valeursFausses.forEach(fausse => fausse.actorName = game.actors.get(fausse.actorId).name ?? "Inconnu"); + return detail; + } + + /* -------------------------------------------- */ + activateListeners(html) { + super.activateListeners(html); + this.html = html; + this.html.find('select[name="signe-astral"]').change(event => { + this.selectNombreAstral(this.html.find('select[name="signe-astral"]').val()); + }) + this.html.find('select[name="signe-naissance"]').change(event => { + this.selectHeureNaissance(this.html.find('select[name="signe-naissance"]').val()); + }) + this.html.find('td.nombre-astral').click(event => { + this.selectNombreAstral(Number.parseInt(event.currentTarget.attributes['data-nombre-astral'].value) - 1); + }) + this.html.find('tr.heure-naissance').click(event => { + this.selectHeureNaissance(event.currentTarget.attributes['data-heure-naissance'].value); + }) + this.html.find('[name="jet-astrologie"]').click(event => this.requestJetAstrologie()); + this.html.find('[name="rebuild-nombres-astraux"]').click(event => this.rebuildNombresAstraux()); + + this.onCalculThemeAstral(); + } + + selectHeureNaissance(heureNaissance) { + this.appData.theme.signeNaissance = RdDTimestamp.definition(heureNaissance); + this.onCalculThemeAstral(); + } + + selectNombreAstral(nombreAstral) { + this.appData.theme.signeAstral = RdDTimestamp.definition(nombreAstral); + this.onCalculThemeAstral(); + } + + /* -------------------------------------------- */ + async rebuildNombresAstraux() { + game.system.rdd.calendrier.resetNombresAstraux(); + + await game.system.rdd.calendrier.rebuildNombresAstraux(); + } + + onCalculThemeAstral() { + const chiffreAstral = this.appData.theme.signeAstral.heure + 1; + const heureNaissance = this.appData.theme.signeNaissance.heure + 1; + RdDTimestamp.definitions().forEach(dh => { + const ajustement = RdDTimestamp.ajustementAstrologiqueHeure(heureNaissance, chiffreAstral, dh.heure + 1); + const txtAjustement = ajustement == 0 ? '' : Misc.toSignedString(ajustement); + this.html.find(`div.astro-ajustement.ajustement-${dh.hh}`).text(txtAjustement) + }); + + this.html.find(`select[name="signe-astral"]`).val(this.appData.theme.signeAstral.key) + this.html.find(`select[name="signe-naissance"]`).val(this.appData.theme.signeNaissance.key) + + const angle = ((chiffreAstral + heureNaissance) * 30) % 360; + const rotation = `rotate(${angle}deg)`; + this.html.find(`div.astro-roue div.astro-disque img`).css({ + 'transform': rotation, + '-ms-transform': rotation, + '-moz-transform': rotation, + '-webkit-transform': rotation, + '-o-transform': rotation + }); + + } + + requestJetAstrologie() { + if (!this.appData?.isActor) { + return + } + let socketData = { + id: this.appData.actorAstrologie.actor.id, + carac_vue: this.actor.system.carac['vue'].value, + etat: this.actor.getEtatGeneral(), + astrologie: this.actor.getCompetence('Astrologie'), + conditions: this.html.find('[name="diffConditions"]').val(), + date: this.html.find('[name="joursAstrologie"]').val(), + userId: game.user.id + } + if (Misc.isUniqueConnectedGM()) { + game.system.rdd.calendrier.requestNombreAstral(socketData); + } else { + game.socket.emit(SYSTEM_SOCKET_ID, { + msg: "msg_request_nombre_astral", + data: socketData + }); + } + } + + refreshAstrologie() { + this.render(true) + } + async close(options) { + Hooks.off(APP_ASTROLOGIE_REFRESH, this.hookReference); + this.hookReference = undefined + await super.close(options) + } +} \ No newline at end of file diff --git a/module/sommeil/theme-astral.js b/module/sommeil/theme-astral.js deleted file mode 100644 index 5c91833a..00000000 --- a/module/sommeil/theme-astral.js +++ /dev/null @@ -1,58 +0,0 @@ -import { Misc } from "../misc.js"; -import { RdDCalendrier } from "../rdd-calendrier.js"; -import { RdDTimestamp } from "../rdd-timestamp.js"; - -export class ThemeAstral extends Application { - static get defaultOptions() { - return mergeObject(super.defaultOptions, { - template: "systems/foundryvtt-reve-de-dragon/templates/sommeil/theme-astral.hbs", - title: "Thème astral", - width: 'fit-content', - height: 'fit-content', - popOut: true, - resizable: false - }); - } - - static async create() { - new ThemeAstral().render(true); - } - constructor() { - super({}); - } - - activateListeners(html) { - super.activateListeners(html); - this.html = html; - this.html.find('select[name="signe-astral"]').change(event => { - this.onCalculThemeAstral(); - }) - this.html.find('select[name="signe-naissance"]').change(event => { - this.onCalculThemeAstral(); - }) - this.onCalculThemeAstral(); - } - - onCalculThemeAstral() { - const signeAstral = RdDTimestamp.definition(this.html.find('select[name="signe-astral"]').val()) - const chiffreAstral = signeAstral.heure + 1; - const signeNaissance = RdDTimestamp.definition(this.html.find('select[name="signe-naissance"]').val()) - const heureNaissance = signeNaissance.heure + 1; - const heureChance = (chiffreAstral + heureNaissance) % 12 + 1 - RdDTimestamp.definitions().forEach(dh => { - const ajustement = RdDCalendrier.ajustementAstrologiqueHeure(heureNaissance, chiffreAstral, dh.heure + 1); - const txtAjustement = ajustement == 0 ? '' : Misc.toSignedString(ajustement); - this.html.find(`div.astro-ajustement.ajustement-${dh.hh}`).text(txtAjustement) - }); - - const angle = (heureChance * 30 + 330) % 360; - const rotation = `rotate(${angle}deg)`; - this.html.find(`div.astro-roue div.astro-disque img`).css({ - 'transform': rotation, - '-ms-transform': rotation, - '-moz-transform': rotation, - '-webkit-transform': rotation, - '-o-transform': rotation - }); - } -} \ No newline at end of file diff --git a/packs/macros.db b/packs/macros.db index 65de8aaf..f9de0dc6 100644 --- a/packs/macros.db +++ b/packs/macros.db @@ -8,6 +8,6 @@ {"name":"Encaissement","type":"script","scope":"global","author":"Hp9ImM4o9YRTSdfu","img":"icons/svg/bones.svg","command":"const selected = game.system.rdd.RdDUtility.getSelectedActor();\nif (selected) {\n selected.encaisser();\n}\nelse {\n ui.notifications.info('Pas de personnage sélectionné');\n}","ownership":{"default":0,"Hp9ImM4o9YRTSdfu":3},"flags":{"core":{"sourceId":"Macro.XHNbjnGKXaCiCadq"}},"_stats":{"systemId":"foundryvtt-reve-de-dragon","systemVersion":"10.3.15","coreVersion":"10.291","createdTime":1671220038331,"modifiedTime":1671234017623,"lastModifiedBy":"Hp9ImM4o9YRTSdfu"},"folder":null,"sort":0,"_id":"WD6T8AdRbX2Ylxqe"} {"name":"Jet quelconque","type":"script","scope":"global","author":"Hp9ImM4o9YRTSdfu","img":"icons/sundries/gaming/dice-runed-tan.webp","command":"const selected = game.system.rdd.RdDUtility.getSelectedActor();\nif (selected) {\n selected.roll();\n}\nelse {\n ui.notifications.info('Pas de personnage sélectionné');\n}","ownership":{"default":0,"Hp9ImM4o9YRTSdfu":3},"flags":{"core":{"sourceId":"Macro.XHNbjnGKXaCiCadq"}},"_stats":{"systemId":"foundryvtt-reve-de-dragon","systemVersion":"10.3.15","coreVersion":"10.291","createdTime":1671220038331,"modifiedTime":1671233500655,"lastModifiedBy":"Hp9ImM4o9YRTSdfu"},"folder":null,"sort":0,"_id":"bnJnbKDHpbqY8Pr9"} {"name":"Recherche et tirage","type":"script","scope":"global","author":"Hp9ImM4o9YRTSdfu","img":"icons/tools/scribal/magnifying-glass.webp","command":"game.system.rdd.commands.tirage()","ownership":{"default":0,"Hp9ImM4o9YRTSdfu":3},"flags":{"core":{"sourceId":"Macro.ZFWPNdQBjQs9z0YW"}},"_stats":{"systemId":"foundryvtt-reve-de-dragon","systemVersion":"10.5.4","coreVersion":"10.291","createdTime":1673472449426,"modifiedTime":1673655461651,"lastModifiedBy":"Hp9ImM4o9YRTSdfu"},"folder":null,"sort":0,"_id":"iVZnxOxhCMpkvYh3"} -{"name":"Thème astral","type":"script","scope":"global","author":"Hp9ImM4o9YRTSdfu","img":"icons/magic/nature/symbol-moon-stars-white.webp","command":"game.system.rdd.ThemeAstral.create();","ownership":{"default":0,"Hp9ImM4o9YRTSdfu":3},"flags":{"core":{"sourceId":"Macro.oA0HPFeFK6YMspAX"}},"_stats":{"systemId":"foundryvtt-reve-de-dragon","systemVersion":"10.6.19","coreVersion":"10.291","createdTime":1678127868791,"modifiedTime":1678150559112,"lastModifiedBy":"Hp9ImM4o9YRTSdfu"},"folder":null,"sort":0,"_id":"koqhiDJSGP4gQ4vf"} +{"name":"Thème astral","type":"script","scope":"global","author":"Hp9ImM4o9YRTSdfu","img":"icons/magic/nature/symbol-moon-stars-white.webp","command":"game.system.rdd.AppAstrologie.create()","ownership":{"default":0,"Hp9ImM4o9YRTSdfu":3},"flags":{"core":{"sourceId":"Macro.oA0HPFeFK6YMspAX"}},"_stats":{"systemId":"foundryvtt-reve-de-dragon","systemVersion":"10.6.19","coreVersion":"10.291","createdTime":1678127868791,"modifiedTime":1678237392810,"lastModifiedBy":"Hp9ImM4o9YRTSdfu"},"folder":null,"sort":0,"_id":"koqhiDJSGP4gQ4vf"} {"name":"Jet d'éthylisme","type":"script","scope":"global","author":"Hp9ImM4o9YRTSdfu","img":"icons/consumables/drinks/alcohol-beer-stein-wooden-metal-brown.webp","command":"const selected = game.system.rdd.RdDUtility.getSelectedActor();\nif (selected) {\n selected.jetEthylisme();\n}\nelse {\n ui.notifications.info('Pas de personnage sélectionné');\n}","ownership":{"default":0,"Hp9ImM4o9YRTSdfu":3},"flags":{"core":{"sourceId":"Macro.XHNbjnGKXaCiCadq"}},"_stats":{"systemId":"foundryvtt-reve-de-dragon","systemVersion":"10.3.15","coreVersion":"10.291","createdTime":1671220038331,"modifiedTime":1671233646086,"lastModifiedBy":"Hp9ImM4o9YRTSdfu"},"folder":null,"sort":0,"_id":"mvub1dRHNFmWjRr7"} {"name":"Tirer le tarot","type":"chat","scope":"global","author":"Hp9ImM4o9YRTSdfu","img":"systems/foundryvtt-reve-de-dragon/icons/tarots/dos-tarot.webp","command":"/tirer tarot","ownership":{"default":0,"Hp9ImM4o9YRTSdfu":3},"flags":{"core":{"sourceId":"Macro.HBZSKR9OHCQbLcTC"}},"_stats":{"systemId":"foundryvtt-reve-de-dragon","systemVersion":"10.3.15","coreVersion":"10.291","createdTime":1669469547231,"modifiedTime":1671237401618,"lastModifiedBy":"Hp9ImM4o9YRTSdfu"},"folder":null,"sort":0,"_id":"vTfJTFYYiRu8X5LM"} diff --git a/styles/simple.css b/styles/simple.css index 1402e1fd..77db8254 100644 --- a/styles/simple.css +++ b/styles/simple.css @@ -870,12 +870,16 @@ form.rdddialogchrono input[type=datetime-local] { color: var(--color-text-dark-primary); border-radius: 3px; } +div.theme-astral{ + width: 14rem; + margin: 0.4rem; +} form.dialog-astro { width: 17rem; } -form.dialog-astro div.astro-roue { +div.astro-roue { position: relative; - left: 2rem; + left: calc(50% - 6.5rem); width: 13rem; height: 13rem; } diff --git a/templates/calendar-astrologie-template-table.html b/templates/calendar-astrologie-template-table.html deleted file mode 100644 index bac8d367..00000000 --- a/templates/calendar-astrologie-template-table.html +++ /dev/null @@ -1,56 +0,0 @@ -
-
-
-

Horoscope

-
-
- {{!-- Sheet Body --}} -
-
- - - - {{#each astrologieData as |nombreData key|}} - - {{/each}} - - - - {{#each astrologieData as |nombreData key|}} - - {{/each}} - -
Date{{nombreData.date.jour}}{{timestamp-imgSigneHeure nombreData.date.mois}}
Nombre astral -
    - {{nombreData.nombreAstral}} - {{#each nombreData.valeursFausses as |fausseVal key|}} -
  1. {{fausseVal.actorName}} - {{fausseVal.nombreAstral}}
  2. - {{/each}} -
-
-
-
- - - - - - - - - {{#each heuresParActeur as |heuresDef name|}} - - - {{#each heuresDef as |ajustement|}} - - {{/each}} - - {{/each}} -
+4+2-2-4
{{name}}: - {{#each ajustement.heures as |heure|}} - {{timestamp-imgSigneHeure heure}} - {{/each}} -
-
-
-
diff --git a/templates/calendar-astrologie-template.html b/templates/calendar-astrologie-template.html deleted file mode 100644 index 84bf7ae8..00000000 --- a/templates/calendar-astrologie-template.html +++ /dev/null @@ -1,68 +0,0 @@ -
-
-
-

Horoscope

-
- -
- {{!-- Sheet Body --}} -
-
- - - - {{#each astrologieData as |nombreData key|}} - - {{/each}} - - - - {{#each astrologieData as |nombreData key|}} - - {{/each}} - -
Date{{nombreData.date.jour}}{{timestamp-imgSigneHeure nombreData.date.mois}}
Nombre astral -
    - {{nombreData.nombreAstral}} - {{#each nombreData.valeursFausses as |fausseVal key|}} -
  1. {{fausseVal.actorName}} - {{fausseVal.nombreAstral}}
  2. - {{/each}} -
-
-
-
- - - - {{#each heures as |heure|}} - - {{/each}} - - {{#each ajustementsActeur as |ajustementActeur|}} - - - {{#each ajustementActeur.ajustements as |ajustement|}} - - {{/each}} - - {{/each}} -
- {{timestamp-imgSigneHeure heure}} -
- - {{actor.name}} {{timestamp-imgSigneHeure actor.system.heure}} - {{#if (ne ajustement.ajustement 0)}} - - {{numberFormat ajustement.ajustement decimals=0 sign=true}} - - {{else}} -
- {{timestamp-imgSigneHeure ajustement.heure}} -
- {{/if}}
-
-
-
diff --git a/templates/dialog-astrologie-joueur.html b/templates/dialog-astrologie-joueur.html deleted file mode 100644 index 5b77d137..00000000 --- a/templates/dialog-astrologie-joueur.html +++ /dev/null @@ -1,61 +0,0 @@ -
-
-
-

Astrologie

-
-
- - - {{!-- Sheet Body --}} -
-
- - - - - -
- - -
- - - - {{#each nombres as |nombreData key|}} - - {{/each}} - - - {{#each nombres as |nombreData key|}} - - {{/each}} - -
{{nombreData.jourlabel}}
-
    - {{#each nombreData.listValues as |nombreAstral key|}} -
  1. {{nombreAstral}}
  2. - {{/each}} -
-
-
-
- -
diff --git a/templates/sommeil/app-astrologie.hbs b/templates/sommeil/app-astrologie.hbs new file mode 100644 index 00000000..0919facb --- /dev/null +++ b/templates/sommeil/app-astrologie.hbs @@ -0,0 +1,18 @@ +
+
+
+
+

Astrologie {{#if isActor}}: {{actorAstrologie.actor.name}}{{/if}}

+
+ {{log 'astrologie' this}} + {{#if isActor}} + {{> 'systems/foundryvtt-reve-de-dragon/templates/sommeil/astrologie-joueur.hbs'}} + {{else}} + {{> 'systems/foundryvtt-reve-de-dragon/templates/sommeil/astrologie-gardien.hbs'}} + {{/if}} +
+
+ {{> 'systems/foundryvtt-reve-de-dragon/templates/sommeil/astrologie-theme.hbs'}} +
+
+
diff --git a/templates/sommeil/astrologie-gardien.hbs b/templates/sommeil/astrologie-gardien.hbs new file mode 100644 index 00000000..adf79101 --- /dev/null +++ b/templates/sommeil/astrologie-gardien.hbs @@ -0,0 +1,57 @@ +
+ Réinitialiser les nombres astraux +
+
+ + + + {{#each gmAstrologie.nombresAstraux as |nba|}} + + {{/each}} + + + + {{#each gmAstrologie.nombresAstraux as |nba|}} + + {{/each}} + +
Date{{nba.date.jour}}{{timestamp-imgSigneHeure nba.date.mois}}
Nombre astral +
    + {{nba.nombreAstral}} + {{#each nba.valeursFausses as |fausse|}} +
  1. {{fausse.actorName}} - {{fausse.nombreAstral}}
  2. + {{/each}} +
+
+
+
+ + + + {{#each heures as |heure|}} + + {{/each}} + + {{#each gmAstrologie.ajustementsActors as |ajustementActeur|}} + + + {{#each ajustementActeur.ajustements as |ajustement|}} + + {{/each}} + + {{/each}} +
+ {{timestamp-imgSigneHeure heure.heure}} +
+ + {{actor.name}} {{timestamp-imgSigneHeure actor.system.heure}} + {{#if (ne ajustement.ajustement 0)}} + + {{numberFormat ajustement.ajustement decimals=0 sign=true}} + + {{else}} +
+ {{timestamp-imgSigneHeure ajustement.heure}} +
+ {{/if}}
+
diff --git a/templates/sommeil/astrologie-joueur.hbs b/templates/sommeil/astrologie-joueur.hbs new file mode 100644 index 00000000..324ba610 --- /dev/null +++ b/templates/sommeil/astrologie-joueur.hbs @@ -0,0 +1,43 @@ +
+ + + + + + Lire les étoiles +
+
+ + + + {{#each actorAstrologie.nombres as |nombre|}} + + {{/each}} + + + {{#each actorAstrologie.nombres as |nombre|}} + + {{/each}} + +
{{nombre.jourlabel}}
+
    + {{#each nombre.listValues as |value|}} +
  1. {{value}}
  2. + {{/each}} +
+
+
diff --git a/templates/sommeil/astrologie-theme.hbs b/templates/sommeil/astrologie-theme.hbs new file mode 100644 index 00000000..0d9b6219 --- /dev/null +++ b/templates/sommeil/astrologie-theme.hbs @@ -0,0 +1,32 @@ +
+
+ + + + +
+
+
+
+
+
+ +
+ {{#each heures as |heure|}} +
+
+ {{/each}} +
+
\ No newline at end of file diff --git a/templates/sommeil/theme-astral.hbs b/templates/sommeil/theme-astral.hbs deleted file mode 100644 index 655cf161..00000000 --- a/templates/sommeil/theme-astral.hbs +++ /dev/null @@ -1,52 +0,0 @@ -
-
- - -
-
- - -
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-2
-
+2
-
-
-4
-
-
+2
-
-2
-
-
-
+4
- -
-
\ No newline at end of file