2021-01-08 22:23:50 +01:00
|
|
|
import { RdDItemCompetence } from "./item-competence.js";
|
2021-03-22 20:10:37 +01:00
|
|
|
import { Misc } from "./misc.js";
|
2022-01-29 22:49:34 +01:00
|
|
|
import { SYSTEM_SOCKET_ID } from "./constants.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 {
|
|
|
|
|
2021-04-01 00:01:37 +02:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
static async create(actor, dialogConfig) {
|
|
|
|
|
2022-09-07 18:47:56 +02:00
|
|
|
let dialogData = {
|
2021-04-01 00:01:37 +02:00
|
|
|
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
|
|
|
}
|
2022-09-07 18:47:56 +02:00
|
|
|
const html = await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/dialog-astrologie-joueur.html', dialogData);
|
2022-12-06 01:30:12 +01:00
|
|
|
let options = { classes: ["rdd-roll-dialog"], width: 600, height: 500, 'z-index': 99999 };
|
2021-04-01 00:01:37 +02:00
|
|
|
if (dialogConfig.options) {
|
|
|
|
mergeObject(options, dialogConfig.options, { overwrite: true });
|
|
|
|
}
|
2022-09-07 18:47:56 +02:00
|
|
|
return new RdDAstrologieJoueur(html, actor, dialogData);
|
2021-04-01 00:01:37 +02:00
|
|
|
}
|
|
|
|
|
2020-12-11 08:29:24 +01:00
|
|
|
/* -------------------------------------------- */
|
2022-09-07 18:47:56 +02:00
|
|
|
constructor(html, actor, dialogData) {
|
2020-12-11 08:29:24 +01:00
|
|
|
|
|
|
|
let myButtons = {
|
2021-04-01 00:01:37 +02: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" };
|
2022-12-06 01:30:12 +01:00
|
|
|
let dialogOptions = { classes: ["rdd-roll-dialog"], width: 600, height: 300, 'z-index': 99999 };
|
2020-12-11 08:29:24 +01:00
|
|
|
super(dialogConf, dialogOptions);
|
2021-04-01 00:01:37 +02:00
|
|
|
|
2020-12-11 08:29:24 +01:00
|
|
|
this.actor = actor;
|
2022-09-07 18:47:56 +02:00
|
|
|
this.dataNombreAstral = duplicate(dialogData);
|
2020-12-11 08:29:24 +01:00
|
|
|
}
|
2021-04-01 00:01:37 +02:00
|
|
|
|
2020-12-13 23:11:58 +01:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
static organizeNombres(actor) {
|
2021-04-01 00:01:37 +02:00
|
|
|
let itemNombres = actor.listItemsData('nombreastral');
|
2020-12-13 23:11:58 +01:00
|
|
|
let itemFiltered = {};
|
2021-04-01 00:01:37 +02:00
|
|
|
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
|
|
|
/* -------------------------------------------- */
|
2021-04-01 00:01:37 +02:00
|
|
|
requestJetAstrologie() {
|
2022-09-07 18:47:56 +02:00
|
|
|
let socketData = {
|
2022-06-12 12:14:55 +02:00
|
|
|
id: this.actor.id,
|
|
|
|
carac_vue: this.actor.system.carac['vue'].value,
|
2021-04-01 00:01:37 +02:00
|
|
|
etat: this.dataNombreAstral.etat,
|
|
|
|
astrologie: this.dataNombreAstral.astrologie,
|
2022-12-06 01:30:12 +01:00
|
|
|
conditions: $("[name='diffConditions']").val(),
|
2021-11-26 00:45:21 +01:00
|
|
|
date: $("#joursAstrologie").val(),
|
|
|
|
userId: game.user.id
|
2021-04-01 00:01:37 +02:00
|
|
|
}
|
2021-11-26 00:45:21 +01:00
|
|
|
if (Misc.isUniqueConnectedGM()) {
|
2022-09-07 18:47:56 +02:00
|
|
|
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",
|
2022-09-07 18:47:56 +02:00
|
|
|
data: socketData
|
2021-04-01 00:01:37 +02:00
|
|
|
});
|
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
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
2020-12-12 23:41:04 +01:00
|
|
|
quitDialog() {
|
2020-12-11 08:29:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
activateListeners(html) {
|
|
|
|
super.activateListeners(html);
|
2021-04-01 00:01:37 +02:00
|
|
|
|
2020-12-13 23:11:58 +01:00
|
|
|
$(function () {
|
2022-12-06 01:30:12 +01:00
|
|
|
$("[name='diffConditions']").val(0);
|
2020-12-13 23:11:58 +01:00
|
|
|
});
|
|
|
|
|
2020-12-12 23:41:04 +01:00
|
|
|
html.find('#jet-astrologie').click((event) => {
|
|
|
|
this.requestJetAstrologie();
|
2020-12-11 08:29:24 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|