102 lines
2.9 KiB
JavaScript
102 lines
2.9 KiB
JavaScript
/**
|
|
* Extend the basic ActorSheet with some very simple modifications
|
|
* @extends {ActorSheet}
|
|
*/
|
|
export class RdDActorSheet extends ActorSheet {
|
|
|
|
/** @override */
|
|
static get defaultOptions() {
|
|
return mergeObject(super.defaultOptions, {
|
|
classes: ["rdd", "sheet", "actor"],
|
|
template: "systems/foundryvtt-reve-de-dragon/templates/actor-sheet.html",
|
|
width: 600,
|
|
height: 600,
|
|
tabs: [{navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "description"}],
|
|
dragDrop: [{dragSelector: ".item-list .item", dropSelector: null}]
|
|
});
|
|
}
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
getData() {
|
|
let data = super.getData();
|
|
|
|
data.itemsByType = {};
|
|
for (const item of data.items) {
|
|
let list = data.itemsByType[item.type];
|
|
if (!list) {
|
|
list = [];
|
|
data.itemsByType[item.type] = list;
|
|
}
|
|
list.push(item);
|
|
}
|
|
data.competenceByCategory = {};
|
|
if (data.itemsByType.competence) {
|
|
for (const item of data.itemsByType.competence) {
|
|
console.log("Push...", item, item.data.categorie);
|
|
let list = data.competenceByCategory[item.data.categorie];
|
|
if (!list) {
|
|
list = [];
|
|
data.competenceByCategory[item.data.categorie] = list;
|
|
}
|
|
list.push(item);
|
|
}
|
|
}
|
|
|
|
data.data.materiel = this._checkNull(data.itemsByType['objet']);
|
|
data.data.armes = this._checkNull(data.itemsByType['arme']);
|
|
data.data.armures = this._checkNull(data.itemsByType['armure']);
|
|
data.data.livres = this._checkNull(data.itemsByType['livre']);
|
|
data.data.potions = this._checkNull(data.itemsByType['potions']);
|
|
data.data.competenceByCategory = data.competenceByCategory;
|
|
|
|
return data;
|
|
}
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
/** @override */
|
|
activateListeners(html) {
|
|
super.activateListeners(html);
|
|
|
|
// Everything below here is only needed if the sheet is editable
|
|
if (!this.options.editable) return;
|
|
|
|
// Update Inventory Item
|
|
html.find('.item-edit').click(ev => {
|
|
const li = $(ev.currentTarget).parents(".item");
|
|
const item = this.actor.getOwnedItem(li.data("itemId"));
|
|
item.sheet.render(true);
|
|
});
|
|
|
|
// Delete Inventory Item
|
|
html.find('.item-delete').click(ev => {
|
|
const li = $(ev.currentTarget).parents(".item");
|
|
this.actor.deleteOwnedItem(li.data("itemId"));
|
|
li.slideUp(200, () => this.render(false));
|
|
});
|
|
|
|
}
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
/** @override */
|
|
setPosition(options={}) {
|
|
const position = super.setPosition(options);
|
|
const sheetBody = this.element.find(".sheet-body");
|
|
const bodyHeight = position.height - 192;
|
|
sheetBody.css("height", bodyHeight);
|
|
return position;
|
|
}
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
/** @override */
|
|
_updateObject(event, formData) {
|
|
|
|
// Update the Actor
|
|
return this.object.update(formData);
|
|
}
|
|
}
|