foundryvtt-reve-de-dragon/module/item-signedraconique-sheet.js

97 lines
3.2 KiB
JavaScript
Raw Normal View History

import { SYSTEM_RDD } from "./constants.js";
2021-05-11 00:52:25 +02:00
import { RdDItemSigneDraconique } from "./item-signedraconique.js";
2021-05-10 19:17:31 +02:00
import { Misc } from "./misc.js";
2021-05-11 00:52:25 +02:00
import { TMRType, TMRUtility } from "./tmr-utility.js";
2021-05-10 19:17:31 +02:00
/**
* Item sheet pour signes draconiques
* @extends {ItemSheet}
*/
export class RdDSigneDraconiqueItemSheet extends ItemSheet {
/** @override */
static get defaultOptions() {
return mergeObject(super.defaultOptions, {
classes: [SYSTEM_RDD, "sheet", "item"],
2021-05-10 19:17:31 +02:00
template: "systems/foundryvtt-reve-de-dragon/templates/item-signedraconique-sheet.html",
width: 550,
height: 550
});
}
/* -------------------------------------------- */
_getHeaderButtons() {
let buttons = super._getHeaderButtons();
buttons.unshift({ class: "post", icon: "fas fa-comment", onclick: ev => this.item.postItem() });
return buttons;
}
/* -------------------------------------------- */
/** @override */
setPosition(options = {}) {
const position = super.setPosition(options);
const sheetHeader = this.element.find(".sheet-header");
const sheetBody = this.element.find(".sheet-body");
const bodyHeight = position.height - sheetHeader[0].clientHeight;
sheetBody.css("height", bodyHeight);
return position;
}
/* -------------------------------------------- */
async getData() {
2022-06-12 08:17:59 +02:00
const formData = duplicate(Misc.data(this.object));
mergeObject(formData, {
title: formData.name,
2021-05-10 19:17:31 +02:00
isGM: game.user.isGM,
owner: this.document.isOwner,
isOwned: this.actor ? true : false,
actorId: this.actor?.id,
editable: this.isEditable,
cssClass: this.isEditable ? "editable" : "locked",
2022-06-12 08:17:59 +02:00
});
formData.tmrs = TMRUtility.listSelectedTMR(formData.data.typesTMR ?? []);
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());
2021-05-10 19:17:31 +02:00
html.find(".select-tmr").change((event) => this.onSelectTmr(event));
2021-05-11 21:21:33 +02:00
html.find(".signe-xp-sort").change((event) => this.onValeurXpSort(event.currentTarget.attributes['data-typereussite']?.value, Number(event.currentTarget.value)));
}
async setSigneAleatoire() {
const newSigne = await RdDItemSigneDraconique.randomSigneDraconique();
this.object.update(newSigne);
2021-05-10 19:17:31 +02:00
}
async onSelectTmr(event) {
2022-06-12 08:17:59 +02:00
event.preventDefault();
const selectedTMR = $(".select-tmr").val();
this.object.update({ 'data.typesTMR': selectedTMR });
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-06-12 08:17:59 +02:00
const oldValeur = Misc.templateData(this.object).valeur;
2021-05-11 00:52:25 +02:00
const newValeur = RdDItemSigneDraconique.calculValeursXpSort(codeReussite, xp, oldValeur);
2022-06-12 08:17:59 +02:00
await this.object.update({ 'data.valeur': newValeur });
2021-05-10 19:17:31 +02:00
}
/* -------------------------------------------- */
get template() {
return `systems/foundryvtt-reve-de-dragon/templates/item-signedraconique-sheet.html`;
}
get title() {
return `Signe draconique: ${this.object.name}`;
}
}