foundryvtt-reve-de-dragon/module/actor-sheet.js

161 lines
5.2 KiB
JavaScript
Raw Normal View History

2020-05-21 21:48:20 +02:00
/**
* Extend the basic ActorSheet with some very simple modifications
* @extends {ActorSheet}
*/
2020-05-22 22:37:02 +02:00
import { RdDUtility } from "./rdd-utility.js";
2020-05-22 00:48:43 +02:00
export class RdDActorSheet extends ActorSheet {
2020-05-21 21:48:20 +02:00
/** @override */
static get defaultOptions() {
return mergeObject(super.defaultOptions, {
2020-05-22 00:48:43 +02:00
classes: ["rdd", "sheet", "actor"],
template: "systems/foundryvtt-reve-de-dragon/templates/actor-sheet.html",
2020-05-21 21:48:20 +02:00
width: 600,
height: 600,
tabs: [{navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "description"}],
dragDrop: [{dragSelector: ".item-list .item", dropSelector: null}]
});
}
2020-05-22 22:37:02 +02:00
/* -------------------------------------------- */
_checkNull(items) {
if (items && items.length) {
return items;
}
return [];
}
2020-05-21 21:48:20 +02:00
/* -------------------------------------------- */
2020-05-22 19:28:01 +02:00
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) {
2020-05-22 22:37:02 +02:00
//console.log("Push...", item, item.data.categorie);
2020-05-22 19:28:01 +02:00
let list = data.competenceByCategory[item.data.categorie];
if (!list) {
list = [];
data.competenceByCategory[item.data.categorie] = list;
}
list.push(item);
}
}
2020-05-29 00:43:16 +02:00
//endurance.max below is normal, this the base used to compute the grid.
data.data.fatigueHTML = "<table class='table-fatigue'>" + RdDUtility.makeHTMLfatigueMatrix( data.data.sante.fatigue.value, data.data.sante.endurance.max ).html() + "</table>";
2020-05-22 19:28:01 +02:00
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;
2020-05-28 23:36:09 +02:00
//console.log(">>>>> data update");
2020-05-27 23:47:49 +02:00
2020-05-22 19:28:01 +02:00
return data;
}
/* -------------------------------------------- */
2020-05-21 21:48:20 +02:00
/** @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));
});
2020-05-22 22:37:02 +02:00
// Roll Skill
html.find('.competence-label a').click((event) => {
let compName = event.currentTarget.text;
this.actor.rollCompetence( compName);
});
2020-05-27 23:47:49 +02:00
2020-05-24 20:19:57 +02:00
// On carac change
$(".competence-value").change((event) => {
let caracName = event.currentTarget.name.replace(".value", "").replace("data.carac.", "");
console.log("Value changed :", event, caracName);
this.actor.updateCarac( caracName, parseInt(event.target.value) );
} );
2020-05-28 23:36:09 +02:00
$("#vie-plus").click((event) => {
this.actor.santeIncDec("vie", 1);
2020-05-29 00:43:16 +02:00
this.actor.update({"data.sante.vie.value": this.actor.data.data.sante.vie.value});
2020-05-28 23:36:09 +02:00
this.render(true);
});
$("#vie-moins").click((event) => {
this.actor.santeIncDec("vie", -1);
2020-05-29 00:43:16 +02:00
this.actor.update({"data.sante.vie.value": this.actor.data.data.sante.vie.value});
2020-05-28 23:36:09 +02:00
this.render(true);
});
$("#endurance-plus").click((event) => {
this.actor.santeIncDec("endurance", 1);
2020-05-29 00:43:16 +02:00
this.actor.update({"data.sante.endurance.value": this.actor.data.data.sante.endurance.value});
2020-05-28 23:36:09 +02:00
this.render(true);
});
$("#endurance-moins").click((event) => {
this.actor.santeIncDec("endurance", -1);
2020-05-29 00:43:16 +02:00
this.actor.update({"data.sante.endurance.value": this.actor.data.data.sante.endurance.value});
2020-05-28 23:36:09 +02:00
this.render(true);
});
$("#fatigue-plus").click((event) => {
this.actor.santeIncDec("fatigue", 1);
2020-05-29 00:43:16 +02:00
this.actor.update({"data.sante.fatigue.value": this.actor.data.data.sante.fatigue.value});
2020-05-28 23:36:09 +02:00
this.render(true);
});
$("#fatigue-moins").click((event) => {
this.actor.santeIncDec("fatigue", -1);
2020-05-29 00:43:16 +02:00
this.actor.update({"data.sante.fatigue.value": this.actor.data.data.sante.fatigue.value});
2020-05-28 23:36:09 +02:00
this.render(true);
});
2020-05-21 21:48:20 +02:00
}
2020-05-28 23:36:09 +02:00
2020-05-21 21:48:20 +02:00
/* -------------------------------------------- */
/** @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);
}
}