2022-12-03 18:29:29 +01:00
|
|
|
import { RdDItemSheet } from "./item-sheet.js";
|
2021-05-11 00:52:25 +02:00
|
|
|
import { RdDItemSigneDraconique } from "./item-signedraconique.js";
|
2022-11-05 18:19:53 +01:00
|
|
|
import { TMRUtility } from "./tmr-utility.js";
|
2021-05-10 19:17:31 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Item sheet pour signes draconiques
|
2022-12-03 18:29:29 +01:00
|
|
|
* @extends {RdDItemSheet}
|
2021-05-10 19:17:31 +02:00
|
|
|
*/
|
2022-12-03 18:29:29 +01:00
|
|
|
export class RdDSigneDraconiqueItemSheet extends RdDItemSheet {
|
2021-05-10 19:17:31 +02:00
|
|
|
|
2022-12-03 18:29:29 +01:00
|
|
|
static get ITEM_TYPE() { return "signedraconique" }
|
2021-05-10 19:17:31 +02:00
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
/** @override */
|
|
|
|
setPosition(options = {}) {
|
|
|
|
const position = super.setPosition(options);
|
|
|
|
const sheetHeader = this.element.find(".sheet-header");
|
|
|
|
const sheetBody = this.element.find(".sheet-body");
|
2022-09-24 00:31:51 +02:00
|
|
|
sheetBody.css("height", position.height - sheetHeader[0].clientHeight)
|
2021-05-10 19:17:31 +02:00
|
|
|
return position;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
async getData() {
|
2022-12-17 20:06:51 +01:00
|
|
|
const formData = await super.getData();
|
2022-09-24 00:31:51 +02:00
|
|
|
this.tmrs = TMRUtility.buildSelectionTypesTMR(this.item.system.typesTMR);
|
2022-12-17 20:06:51 +01:00
|
|
|
formData.tmrs = this.tmrs;
|
2022-06-12 08:17:59 +02:00
|
|
|
return formData;
|
2021-05-10 19:17:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
/** @override */
|
|
|
|
activateListeners(html) {
|
|
|
|
super.activateListeners(html);
|
|
|
|
|
|
|
|
if (!this.options.editable) return;
|
|
|
|
|
2021-05-11 21:21:33 +02:00
|
|
|
html.find(".signe-aleatoire").click(event => this.setSigneAleatoire());
|
2022-12-03 18:29:29 +01:00
|
|
|
html.find("input.select-tmr").change(event => this.onSelectTmr(event));
|
|
|
|
html.find(".signe-xp-sort").change(event => this.onValeurXpSort(event.currentTarget.attributes['data-typereussite']?.value, Number(event.currentTarget.value)));
|
2021-05-11 21:21:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
async setSigneAleatoire() {
|
|
|
|
const newSigne = await RdDItemSigneDraconique.randomSigneDraconique();
|
2022-12-03 18:29:29 +01:00
|
|
|
newSigne.name = this.item.name;
|
2022-09-07 18:47:56 +02:00
|
|
|
this.item.update(newSigne);
|
2021-05-10 19:17:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
async onSelectTmr(event) {
|
2022-09-24 00:31:51 +02:00
|
|
|
const tmrName = $(event.currentTarget)?.data("tmr-name");
|
|
|
|
const onTmr = this.tmrs.find(it => it.name == tmrName);
|
|
|
|
if (onTmr){
|
|
|
|
onTmr.selected = event.currentTarget.checked;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.item.update({ 'system.typesTMR': TMRUtility.buildListTypesTMRSelection(this.tmrs) });
|
2021-05-10 19:17:31 +02:00
|
|
|
}
|
|
|
|
|
2021-05-11 00:52:25 +02:00
|
|
|
async onValeurXpSort(event) {
|
|
|
|
const codeReussite = event.currentTarget.attributes['data-typereussite']?.value ?? 0;
|
|
|
|
const xp = Number(event.currentTarget.value);
|
2022-09-07 18:47:56 +02:00
|
|
|
const oldValeur = this.item.system.valeur;
|
2021-05-11 00:52:25 +02:00
|
|
|
const newValeur = RdDItemSigneDraconique.calculValeursXpSort(codeReussite, xp, oldValeur);
|
2022-09-07 18:47:56 +02:00
|
|
|
await this.item.update({ 'system.valeur': newValeur });
|
2021-05-10 19:17:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|