foundryvtt-reve-de-dragon/module/rdd-astrologie-joueur.js

101 lines
3.1 KiB
JavaScript
Raw Permalink Normal View History

import { RdDItemCompetence } from "./item-competence.js";
import { Misc } from "./misc.js";
2022-01-29 22:49:34 +01:00
import { SYSTEM_SOCKET_ID } from "./constants.js";
import { ThemeAstral } from "./sommeil/theme-astral.js";
2021-01-26 18:57:56 +01:00
2020-12-11 08:29:24 +01:00
/**
* Extend the base Dialog entity by defining a custom window to perform roll.
* @extends {Dialog}
*/
export class RdDAstrologieJoueur extends Dialog {
/* -------------------------------------------- */
2022-12-29 02:31:29 +01:00
static async create(actor) {
let dialogData = {
nombres: this.organizeNombres(actor),
dates: game.system.rdd.calendrier.getJoursSuivants(10),
etat: actor.getEtatGeneral(),
ajustementsConditions: CONFIG.RDD.ajustementsConditions,
2022-06-12 12:14:55 +02:00
astrologie: RdDItemCompetence.findCompetence(actor.items, 'Astrologie')
2020-12-11 08:29:24 +01:00
}
const html = await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/dialog-astrologie-joueur.html', dialogData);
2022-12-29 02:31:29 +01:00
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);
}
2020-12-11 08:29:24 +01:00
/* -------------------------------------------- */
2022-12-29 02:31:29 +01:00
constructor(html, actor, dialogData, dialogOptions) {
const dialogConf = {
title: "Nombres Astraux",
content: html,
default: "saveButton",
buttons: {
2023-01-10 22:46:09 +01:00
saveButton: { label: "Fermer", callback: html => {} }
},
};
2020-12-11 08:29:24 +01:00
super(dialogConf, dialogOptions);
2020-12-11 08:29:24 +01:00
this.actor = actor;
this.dataNombreAstral = duplicate(dialogData);
2020-12-11 08:29:24 +01:00
}
/* -------------------------------------------- */
activateListeners(html) {
super.activateListeners(html);
this.html = html;
2022-12-29 02:31:29 +01:00
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();
});
}
2020-12-13 23:11:58 +01:00
/* -------------------------------------------- */
static organizeNombres(actor) {
2022-12-28 23:36:48 +01:00
let itemNombres = actor.listItems('nombreastral');
2020-12-13 23:11:58 +01:00
let itemFiltered = {};
for (let item of itemNombres) {
2022-06-12 12:14:55 +02:00
if (itemFiltered[item.system.jourindex]) {
itemFiltered[item.system.jourindex].listValues.push(item.system.value);
2020-12-13 23:11:58 +01:00
} else {
2022-06-12 12:14:55 +02:00
itemFiltered[item.system.jourindex] = {
listValues: [item.system.value],
jourlabel: item.system.jourlabel
2020-12-13 23:11:58 +01:00
}
}
}
return itemFiltered;
}
2020-12-12 23:31:19 +01:00
/* -------------------------------------------- */
requestJetAstrologie() {
let socketData = {
2022-06-12 12:14:55 +02:00
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);
2020-12-12 23:31:19 +01:00
} else {
2022-01-29 22:49:34 +01:00
game.socket.emit(SYSTEM_SOCKET_ID, {
2020-12-12 23:31:19 +01:00
msg: "msg_request_nombre_astral",
data: socketData
});
2020-12-12 23:31:19 +01:00
}
2020-12-13 23:11:58 +01:00
this.close();
2020-12-12 23:31:19 +01:00
}
2020-12-11 08:29:24 +01:00
}