2022-11-05 18:19:53 +01:00
|
|
|
import { RdDRencontre } from "./item-rencontre.js";
|
2022-12-03 18:29:29 +01:00
|
|
|
import { RdDItemSheet } from "./item-sheet.js";
|
2022-11-05 18:19:53 +01:00
|
|
|
|
2022-12-03 18:29:29 +01:00
|
|
|
export class RdDRencontreItemSheet extends RdDItemSheet {
|
|
|
|
|
|
|
|
static get ITEM_TYPE() { return "rencontre" };
|
2022-11-05 18:19:53 +01:00
|
|
|
|
|
|
|
static get defaultOptions() {
|
|
|
|
return mergeObject(super.defaultOptions, {
|
|
|
|
tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "carac" }]
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
/** @override */
|
|
|
|
setPosition(options = {}) {
|
|
|
|
const position = super.setPosition(options);
|
|
|
|
const sheetHeader = this.element.find(".sheet-header");
|
|
|
|
const sheetBody = this.element.find(".sheet-body");
|
|
|
|
sheetBody.css("height", position.height - sheetHeader[0].clientHeight)
|
|
|
|
return position;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
async getData() {
|
2022-12-17 20:06:51 +01:00
|
|
|
const formData = await super.getData();
|
2022-11-05 18:19:53 +01:00
|
|
|
mergeObject(formData, {
|
|
|
|
effets: {
|
|
|
|
succes: {
|
|
|
|
liste: RdDRencontre.getEffetsSucces(),
|
|
|
|
select: RdDRencontre.mapEffets(this.item.system.succes.effets)
|
|
|
|
},
|
|
|
|
echec: {
|
|
|
|
liste: RdDRencontre.getEffetsEchec(),
|
|
|
|
select: RdDRencontre.mapEffets(this.item.system.echec.effets)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return formData;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
/** @override */
|
|
|
|
activateListeners(html) {
|
|
|
|
super.activateListeners(html);
|
|
|
|
if (!this.options.editable) return;
|
2022-12-09 02:00:31 +01:00
|
|
|
this.html.find("a.effet-add").click(event => this.onAddEffet(event));
|
|
|
|
this.html.find("a.effet-delete").click(event => this.onDeleteEffet(event));
|
2022-11-05 18:19:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
async onAddEffet(event) {
|
2022-12-09 02:00:31 +01:00
|
|
|
const resultat = this.html.find(event.currentTarget)?.data("effet-resultat");
|
2022-11-05 18:19:53 +01:00
|
|
|
const keyEffets = `system.${resultat}.effets`;
|
|
|
|
|
2022-12-09 02:00:31 +01:00
|
|
|
const code = this.html.find(event.currentTarget)?.data("effet-code");
|
2022-11-05 18:19:53 +01:00
|
|
|
const liste = RdDRencontre.getListeEffets(this.item, resultat);
|
|
|
|
liste.push(code);
|
|
|
|
|
|
|
|
await this._updateEffetsRencontre(keyEffets, liste);
|
|
|
|
}
|
|
|
|
|
|
|
|
async onDeleteEffet(event) {
|
2022-12-09 02:00:31 +01:00
|
|
|
const resultat = this.html.find(event.currentTarget)?.data("effet-resultat");
|
2022-11-05 18:19:53 +01:00
|
|
|
const keyEffets = `system.${resultat}.effets`;
|
|
|
|
|
2022-12-09 02:00:31 +01:00
|
|
|
const pos = this.html.find(event.currentTarget)?.data("effet-pos");
|
2022-11-05 18:19:53 +01:00
|
|
|
const liste = RdDRencontre.getListeEffets(this.item, resultat);
|
|
|
|
liste.splice(pos, 1);
|
|
|
|
|
|
|
|
await this._updateEffetsRencontre(keyEffets, liste);
|
|
|
|
}
|
|
|
|
|
|
|
|
async _updateEffetsRencontre(key, liste) {
|
|
|
|
const updates = {};
|
|
|
|
updates[key] = liste;
|
|
|
|
this.item.update(updates);
|
|
|
|
}
|
|
|
|
}
|