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

102 lines
3.3 KiB
JavaScript
Raw Normal View History

import { RdDItemCompetence } from "./item-competence.js";
2020-12-11 08:29:24 +01:00
import { Misc } from "./misc.js";
2020-12-12 23:31:19 +01:00
import { RdDCalendrier } from "./rdd-calendrier.js";
import { RdDUtility } from "./rdd-utility.js";
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 {
/* -------------------------------------------- */
static async create(actor, dialogConfig) {
2020-12-13 23:11:58 +01:00
let data = { nombres: this.organizeNombres( actor),
2020-12-12 23:31:19 +01:00
dates: game.system.rdd.calendrier.getJoursSuivants( 10 ),
etat: actor.getEtatGeneral(),
2020-12-12 23:31:19 +01:00
ajustementsConditions: CONFIG.RDD.ajustementsConditions,
astrologie: RdDItemCompetence.findCompetence( actor.data.items, 'Astrologie')
2020-12-11 08:29:24 +01:00
}
const html = await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/dialog-astrologie-joueur.html', data);
let options = { classes: ["rdddialog"], width: 600, height: 500, 'z-index': 99999 };
if (dialogConfig.options) {
2020-12-12 23:31:19 +01:00
mergeObject(options, dialogConfig.options, { overwrite: true });
2020-12-11 08:29:24 +01:00
}
return new RdDAstrologieJoueur(html, actor, data);
}
/* -------------------------------------------- */
constructor(html, actor, data ) {
let myButtons = {
2020-12-12 23:41:04 +01:00
saveButton: { label: "Fermer", callback: html => this.quitDialog() }
2020-12-11 08:29:24 +01:00
};
// Get all n
// Common conf
let dialogConf = { content: html, title: "Nombres Astraux", buttons: myButtons, default: "saveButton" };
let dialogOptions = { classes: ["rdddialog"], width: 600, height: 300, 'z-index': 99999 } ;
super(dialogConf, dialogOptions);
this.actor = actor;
this.dataNombreAstral = duplicate(data);
}
2020-12-12 23:31:19 +01:00
2020-12-13 23:11:58 +01:00
/* -------------------------------------------- */
static organizeNombres(actor) {
let itemNombres = actor.data.items.filter( (item) => item.type == 'nombreastral');
let itemFiltered = {};
for ( let item of itemNombres) {
if ( itemFiltered[item.data.jourindex] ) {
itemFiltered[item.data.jourindex].listValues.push(item.data.value);
} else {
itemFiltered[item.data.jourindex] = {
listValues: [ item.data.value ],
jourlabel: item.data.jourlabel
}
}
}
return itemFiltered;
}
2020-12-12 23:31:19 +01:00
/* -------------------------------------------- */
requestJetAstrologie( ) {
let data = { id: this.actor.data._id,
carac_vue: this.actor.data.data.carac['vue'].value,
2020-12-13 23:11:58 +01:00
etat: this.dataNombreAstral.etat,
2020-12-12 23:31:19 +01:00
astrologie: this.dataNombreAstral.astrologie,
conditions: $("#diffConditions").val(),
date: $("#joursAstrologie").val()
}
if ( game.user.isGM) {
game.system.rdd.calendrier.requestNombreAstral( data );
} else {
game.socket.emit("system.foundryvtt-reve-de-dragon", {
msg: "msg_request_nombre_astral",
data: data
} );
}
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
/* -------------------------------------------- */
2020-12-12 23:41:04 +01:00
quitDialog() {
2020-12-11 08:29:24 +01:00
}
/* -------------------------------------------- */
activateListeners(html) {
super.activateListeners(html);
2020-12-13 23:11:58 +01:00
$(function () {
$("#diffConditions").val(0);
});
2020-12-12 23:41:04 +01:00
html.find('#jet-astrologie').click((event) => {
this.requestJetAstrologie();
2020-12-11 08:29:24 +01:00
});
}
}