2023-04-14 01:19:44 +02:00
|
|
|
import { SYSTEM_RDD, SYSTEM_SOCKET_ID } from "../constants.js";
|
2023-03-08 02:02:40 +01:00
|
|
|
import { Misc } from "../misc.js";
|
2023-03-29 22:53:40 +02:00
|
|
|
import { RdDTimestamp } from "../time/rdd-timestamp.js";
|
2023-03-08 02:02:40 +01:00
|
|
|
|
|
|
|
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',
|
2023-03-29 22:53:40 +02:00
|
|
|
classes: ['calendar-astrologie'],
|
2023-03-08 02:02:40 +01:00
|
|
|
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,
|
2023-04-21 22:23:40 +02:00
|
|
|
nombres: this._organizeNombresAstraux(this.actor.itemTypes['nombreastral']),
|
2023-03-08 02:02:40 +01:00
|
|
|
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 {
|
2024-03-09 23:12:13 +01:00
|
|
|
ajustementsActors:game.actors.filter(actor => actor.isPersonnageJoueur())
|
2023-03-08 02:02:40 +01:00
|
|
|
.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 => {
|
2023-12-26 19:03:49 +01:00
|
|
|
this.selectNombreAstral(event.currentTarget.value);
|
2023-03-08 02:02:40 +01:00
|
|
|
})
|
|
|
|
this.html.find('select[name="signe-naissance"]').change(event => {
|
2023-12-26 19:03:49 +01:00
|
|
|
this.selectHeureNaissance(event.currentTarget.value);
|
2023-03-08 02:02:40 +01:00
|
|
|
})
|
|
|
|
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());
|
2023-10-20 02:34:07 +02:00
|
|
|
this.html.find('[name="rebuild-nombres-astraux"]').click(event => this.onRebuild());
|
2023-03-09 23:49:37 +01:00
|
|
|
|
2023-03-08 02:02:40 +01:00
|
|
|
this.onCalculThemeAstral();
|
|
|
|
}
|
|
|
|
|
|
|
|
selectHeureNaissance(heureNaissance) {
|
|
|
|
this.appData.theme.signeNaissance = RdDTimestamp.definition(heureNaissance);
|
|
|
|
this.onCalculThemeAstral();
|
|
|
|
}
|
|
|
|
|
|
|
|
selectNombreAstral(nombreAstral) {
|
|
|
|
this.appData.theme.signeAstral = RdDTimestamp.definition(nombreAstral);
|
|
|
|
this.onCalculThemeAstral();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
2023-10-20 02:34:07 +02:00
|
|
|
async onRebuild() {
|
2023-03-08 02:02:40 +01:00
|
|
|
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);
|
2023-03-29 22:53:40 +02:00
|
|
|
this.html.find(`div.horloge-ajustement.heure-${dh.hh}`).text(txtAjustement)
|
2023-03-08 02:02:40 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
2023-03-09 23:49:37 +01:00
|
|
|
const angleAstrologie = ((chiffreAstral + heureNaissance) * 30) % 360 - 45;
|
2023-03-29 22:53:40 +02:00
|
|
|
this.html.find(`div.horloge-roue div.disque-astro img`).css(Misc.cssRotation(angleAstrologie));
|
2023-03-09 23:49:37 +01:00
|
|
|
|
2023-03-29 22:53:40 +02:00
|
|
|
const timestamp = game.system.rdd.calendrier.getTimestamp();
|
2023-03-08 22:33:23 +01:00
|
|
|
|
2023-03-29 22:53:40 +02:00
|
|
|
this.html.find(`div.horloge-roue div.horloge-aiguille-heure img`).css(Misc.cssRotation(timestamp.angleHeure));
|
|
|
|
this.html.find(`div.horloge-roue div.horloge-aiguille-minute img`).css(Misc.cssRotation(timestamp.angleMinute));
|
2023-03-08 02:02:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
2023-03-08 22:33:23 +01:00
|
|
|
|
2023-03-08 02:02:40 +01:00
|
|
|
async close(options) {
|
|
|
|
Hooks.off(APP_ASTROLOGIE_REFRESH, this.hookReference);
|
|
|
|
this.hookReference = undefined
|
|
|
|
await super.close(options)
|
|
|
|
}
|
|
|
|
}
|