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

169 lines
6.2 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() {
2021-04-13 14:01:22 +02:00
this.actor.calculerSommeStats();
2021-04-01 21:18:36 +02:00
let data = super.getData();
2021-04-03 22:48:02 +02:00
data.editScore = this.options.editScore;
data.donnees = this.actor.getDonnees();
data.eglises = this.actor.getEglises();
2021-04-02 14:59:58 +02:00
data.competences = this.actor.getCompetences();
2021-04-03 22:48:02 +02:00
data.sorts = this.actor.getSorts();
data.devotions = this.actor.getDevotions();
data.attributs = this.actor.getAttributs();
data.techniques = this.actor.getTechniques();
data.armes = this.actor.getArmes();
data.armures = this.actor.getArmures();
data.equipements = this.actor.getEquipements();
2021-04-23 12:51:52 +02:00
data.monnaies = this.actor.getMonnaies();
2021-04-13 14:01:22 +02:00
2021-04-03 22:48:02 +02:00
data.optionsBase = VadentisUtility.createDirectOptionList(0, 50);
2021-04-08 13:58:51 +02:00
data.optionsMalus = VadentisUtility.createDirectReverseOptionList(-50, 0);
2021-04-03 22:48:02 +02:00
data.optionsBonus = VadentisUtility.createDirectOptionList(0, 50);
data.optionsPV = VadentisUtility.createOptionList(-50, 200);
data.optionsPE = VadentisUtility.createOptionList(-50, 200);
data.optionsPA = VadentisUtility.createOptionList(0, 20);
2021-04-01 22:52:41 +02:00
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);
});
// Delete Inventory Item
html.find('.item-delete').click(ev => {
const li = $(ev.currentTarget).parents(".item");
2021-04-02 14:59:58 +02:00
VadentisUtility.confirmDelete(this, li);
2021-04-01 21:18:36 +02:00
});
2021-04-02 14:59:58 +02:00
html.find('.combat-label a').click((event) => {
let combatName = event.currentTarget.attributes.name.value;
this.actor.rollCombat(combatName);
2021-04-01 21:18:36 +02:00
});
2021-04-13 14:01:22 +02:00
html.find('.magie-label a').click((event) => {
let magieName = event.currentTarget.attributes.name.value;
this.actor.rollMagie(magieName);
});
2021-04-02 14:59:58 +02:00
html.find('.competence-label a').click((event) => {
2021-04-01 21:18:36 +02:00
const li = $(event.currentTarget).parents(".item");
2021-04-02 14:59:58 +02:00
const competenceId = li.data("item-id");
this.actor.rollCompetence(competenceId);
2021-04-01 21:18:36 +02:00
});
2021-04-03 22:48:02 +02:00
html.find('.technique-label a').click((event) => {
const li = $(event.currentTarget).parents(".item");
const techniqueId = li.data("item-id");
this.actor.rollTechnique(techniqueId);
});
2021-04-02 16:47:38 +02:00
html.find('.sort-label a').click((event) => {
const li = $(event.currentTarget).parents(".item");
const sortId = li.data("item-id");
this.actor.rollSort(sortId);
});
2021-04-03 22:48:02 +02:00
html.find('.arme-label a').click((event) => {
const li = $(event.currentTarget).parents(".item");
const armeId = li.data("item-id");
this.actor.rollArme(armeId);
});
2021-04-02 16:47:38 +02:00
html.find('.devotion-label a').click((event) => {
const li = $(event.currentTarget).parents(".item");
const devotionId = li.data("item-id");
this.actor.rollDevotion(devotionId);
});
2021-04-01 21:18:36 +02:00
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);
});
2021-04-08 13:58:51 +02:00
html.find('.weapon-damage').click((event) => {
const li = $(event.currentTarget).parents(".item");
const weapon = this.actor.getOwnedItem(li.data("item-id"));
this.actor.rollDamage(weapon, 'damage');
});
html.find('.weapon-damage-critical').click((event) => {
const li = $(event.currentTarget).parents(".item");
const weapon = this.actor.getOwnedItem(li.data("item-id"));
this.actor.rollDamage(weapon, 'criticaldamage');
});
2021-04-02 14:59:58 +02:00
html.find('.competence-base').change((event) => {
2021-04-01 21:18:36 +02:00
let skillName = event.currentTarget.attributes.skillname.value;
2021-04-02 14:59:58 +02:00
this.actor.updateCompetence(skillName, "base", parseInt(event.target.value));
});
html.find('.competence-bonus').change((event) => {
let skillName = event.currentTarget.attributes.skillname.value;
this.actor.updateCompetence(skillName, "bonus", parseInt(event.target.value));
});
html.find('.competence-malus').change((event) => {
let skillName = event.currentTarget.attributes.skillname.value;
this.actor.updateCompetence(skillName, "malus", parseInt(event.target.value));
2021-04-01 21:18:36 +02:00
});
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);
});
2021-04-03 22:48:02 +02:00
html.find('.item-equip').click(ev => {
const li = $(ev.currentTarget).parents(".item");
this.actor.equiperObject( li.data("item-id") );
this.render(true);
});
2021-04-01 21:18:36 +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);
}
}