fvtt-vadentis/modules/vadentis-actor-sheet.js

122 lines
4.0 KiB
JavaScript
Raw Normal View History

2021-04-01 21:18:36 +02:00
/**
* Extend the basic ActorSheet with some very simple modifications
* @extends {ActorSheet}
*/
import { VadentisUtility } from "./vadentis-utility.js";
/* -------------------------------------------- */
export class VadentisActorSheet extends ActorSheet {
/** @override */
static get defaultOptions() {
return mergeObject(super.defaultOptions, {
2021-04-01 22:35:03 +02:00
classes: ["vadentis", "sheet", "actor"],
2021-04-01 21:18:36 +02:00
template: "systems/foundryvtt-vadentis/templates/actor-sheet.html",
width: 640,
height: 720,
tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "stats" }],
dragDrop: [{ dragSelector: ".item-list .item", dropSelector: null }],
2021-04-01 22:52:41 +02:00
editScore: false
2021-04-01 21:18:36 +02:00
});
}
/* -------------------------------------------- */
getData() {
let data = super.getData();
2021-04-01 22:35:03 +02:00
data.stats = this.actor.stats;
data.combat = this.actor.combat;
data.magie = this.actor.magie;
2021-04-01 22:52:41 +02:00
data.editScore = this.options.editScore;
console.log("Edit : ", data.editScore);
data.isGM = game.user.isGM;
2021-04-01 21:18:36 +02:00
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("item-id"));
item.sheet.render(true);
});
html.find('.item-equip').click(ev => {
const li = $(ev.currentTarget).parents(".item");
const item = this.actor.equipObject( li.data("item-id") );
this.render(true);
});
html.find('.item-worn').click(ev => {
const li = $(ev.currentTarget).parents(".item");
const item = this.actor.wornObject( li.data("item-id") );
this.render(true);
});
// Delete Inventory Item
html.find('.item-delete').click(ev => {
const li = $(ev.currentTarget).parents(".item");
SoSUtility.confirmDelete(this, li);
});
html.find('.stat-label a').click((event) => {
let statName = event.currentTarget.attributes.name.value;
this.actor.rollStat(statName);
});
html.find('.skill-label a').click((event) => {
const li = $(event.currentTarget).parents(".item");
const skill = this.actor.getOwnedItem(li.data("item-id"));
this.actor.rollSkill(skill);
});
html.find('.weapon-label a').click((event) => {
const li = $(event.currentTarget).parents(".item");
const weapon = this.actor.getOwnedItem(li.data("item-id"));
this.actor.rollWeapon(weapon);
});
html.find('.skill-value').change((event) => {
let skillName = event.currentTarget.attributes.skillname.value;
//console.log("Competence changed :", skillName);
this.actor.updateSkill(skillName, parseInt(event.target.value));
});
html.find('.skill-xp').change((event) => {
let skillName = event.currentTarget.attributes.skillname.value;
//console.log("Competence changed :", skillName);
this.actor.updateSkillExperience(skillName, parseInt(event.target.value));
});
html.find('.lock-unlock-sheet').click((event) => {
2021-04-01 22:52:41 +02:00
this.options.editScore = !this.options.editScore;
2021-04-01 21:18:36 +02:00
this.render(true);
});
html.find('.item-link a').click((event) => {
const itemId = $(event.currentTarget).data("item-id");
const item = this.actor.getOwnedItem(itemId);
item.sheet.render(true);
});
}
/* -------------------------------------------- */
/** @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);
}
}