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() {
|
2024-05-01 09:13:21 +02:00
|
|
|
return foundry.utils.mergeObject(super.defaultOptions, {
|
2023-03-08 02:02:40 +01:00
|
|
|
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
|
2024-06-01 01:53:14 +02:00
|
|
|
}, { inplace: false })
|
2023-03-08 02:02:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
constructor(actor, options = {}) {
|
|
|
|
super(options);
|
|
|
|
this.actor = actor;
|
|
|
|
}
|
|
|
|
|
|
|
|
getData(options) {
|
|
|
|
this.appData = super.getData(options)
|
|
|
|
const calendrier = game.system.rdd.calendrier;
|
2024-05-01 09:13:21 +02:00
|
|
|
foundry.utils.mergeObject(this.appData, {
|
2023-03-08 02:02:40 +01:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
})
|
2024-06-01 01:53:14 +02:00
|
|
|
return this.appData
|
2023-03-08 02:02:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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-05-12 22:40:06 +02:00
|
|
|
ajustementsActors: game.actors.filter(actor => actor.isPersonnageJoueur())
|
2023-03-08 02:02:40 +01:00
|
|
|
.map(actor => this.getAjustementActor(actor, nbAstral, heures)),
|
2024-05-12 22:40:06 +02:00
|
|
|
nombresAstraux: game.system.rdd.calendrier.getNombresAstraux()
|
|
|
|
.map(na => this.getDetailNombreAstral(na))
|
2023-03-08 02:02:40 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
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) {
|
2024-05-02 14:08:02 +02:00
|
|
|
const detail = foundry.utils.duplicate(nombreAstral);
|
2023-03-08 02:02:40 +01:00
|
|
|
const timestamp = new RdDTimestamp({ indexDate: nombreAstral.index });
|
|
|
|
detail.date = { mois: timestamp.mois, jour: timestamp.jour + 1 };
|
2024-05-12 22:40:06 +02:00
|
|
|
detail.lectures.forEach(lecture => lecture.actorName = game.actors.get(lecture.actorId).name ?? "Inconnu");
|
2023-03-08 02:02:40 +01:00
|
|
|
return detail;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
activateListeners(html) {
|
2024-05-12 22:40:06 +02:00
|
|
|
if (!this.hookReference){
|
|
|
|
this.hookReference = Hooks.on(APP_ASTROLOGIE_REFRESH, () => this.refreshAstrologie());
|
|
|
|
}
|
2023-03-08 02:02:40 +01:00
|
|
|
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() {
|
2024-05-12 22:40:06 +02:00
|
|
|
await game.system.rdd.calendrier.resetNombresAstraux();
|
2023-03-08 02:02:40 +01:00
|
|
|
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
|
|
|
|
}
|
2024-10-23 23:42:38 +02:00
|
|
|
if (Misc.isFirstConnectedGM()) {
|
2023-03-08 02:02:40 +01:00
|
|
|
game.system.rdd.calendrier.requestNombreAstral(socketData);
|
|
|
|
} else {
|
|
|
|
game.socket.emit(SYSTEM_SOCKET_ID, {
|
|
|
|
msg: "msg_request_nombre_astral",
|
|
|
|
data: socketData
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
refreshAstrologie() {
|
2024-05-12 22:40:06 +02:00
|
|
|
this.count = (this.count ?? 0)+1
|
|
|
|
console.log(`Refreshing ${this.count}`);
|
2023-03-08 02:02:40 +01:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|