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

147 lines
4.7 KiB
JavaScript
Raw Normal View History

2020-11-14 23:24:01 +01:00
/**
* Extend the basic ActorSheet with some very simple modifications
* @extends {ActorSheet}
*/
import { HtmlUtility } from "./html-utility.js";
import { Misc } from "./misc.js";
2021-03-25 03:18:27 +01:00
import { RdDUtility } from "./rdd-utility.js";
2020-11-14 23:24:01 +01:00
/* -------------------------------------------- */
export class RdDActorEntiteSheet extends ActorSheet {
/** @override */
static get defaultOptions() {
return mergeObject(super.defaultOptions, {
classes: ["rdd", "sheet", "actor"],
template: "systems/foundryvtt-reve-de-dragon/templates/actor-entite-sheet.html",
width: 640,
height: 720,
tabs: [{navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "carac"}],
dragDrop: [{dragSelector: ".item-list .item", dropSelector: null}]
});
}
/* -------------------------------------------- */
async getData() {
2022-06-12 09:46:58 +02:00
const objectData = this.object;
2021-03-25 03:18:27 +01:00
let formData = {
title: this.title,
2022-06-12 08:17:59 +02:00
id: objectData.id,
type: objectData.type,
img: objectData.img,
name: objectData.name,
2021-03-25 03:18:27 +01:00
// actor: this.object,
editable: this.isEditable,
cssClass: this.isEditable ? "editable" : "locked",
2022-06-12 08:17:59 +02:00
data: foundry.utils.deepClone(this.actor.system),
2022-06-12 19:40:44 +02:00
effects: this.object.effects.map(e => foundry.utils.deepClone(e)),
2021-03-25 03:18:27 +01:00
// items: items,
limited: this.object.limited,
options: this.options,
owner: this.document.isOwner,
2022-06-12 19:40:44 +02:00
itemsByType: Misc.classify(this.object.items.map(i => foundry.utils.deepClone(i))),
2021-03-25 03:18:27 +01:00
};
2020-11-14 23:24:01 +01:00
formData.options.isGM = game.user.isGM;
2021-03-25 03:18:27 +01:00
RdDUtility.filterItemsPerTypeForSheet(formData);
2021-03-16 22:56:57 +01:00
return formData;
2020-11-14 23:24:01 +01:00
}
/* -------------------------------------------- */
/** @override */
activateListeners(html) {
super.activateListeners(html);
HtmlUtility._showControlWhen($(".gm-only"), game.user.isGM);
2020-11-14 23:24:01 +01:00
// Everything below here is only needed if the sheet is editable
if (!this.options.editable) return;
// Update Inventory Item
html.find('.item-edit').click(event => {
const li = $(event.currentTarget).parents(".item");
2021-03-30 21:56:18 +02:00
const item = this.actor.getEmbeddedDocument('Item', li.data("itemId"));
2020-11-14 23:24:01 +01:00
item.sheet.render(true);
});
// Delete Inventory Item
html.find('.item-delete').click(event => {
const li = $(event.currentTarget).parents(".item");
this.actor.deleteEmbeddedDocuments('Item', [li.data("itemId")]);
2020-11-14 23:24:01 +01:00
li.slideUp(200, () => this.render(false));
});
// Roll Carac
html.find('.carac-label a').click(async event => {
2020-11-14 23:24:01 +01:00
let caracName = event.currentTarget.attributes.name.value;
this.actor.rollCarac( caracName.toLowerCase() );
});
// On competence change
html.find('.creature-carac').change(async event => {
2020-11-14 23:24:01 +01:00
let compName = event.currentTarget.attributes.compname.value;
this.actor.updateCreatureCompetence( compName, "carac_value", parseInt(event.target.value) );
} );
html.find('.creature-niveau').change(async event => {
2020-11-14 23:24:01 +01:00
let compName = event.currentTarget.attributes.compname.value;
this.actor.updateCreatureCompetence( compName, "niveau", parseInt(event.target.value) );
} );
html.find('.creature-dommages').change(async event => {
2020-11-14 23:24:01 +01:00
let compName = event.currentTarget.attributes.compname.value;
this.actor.updateCreatureCompetence( compName, "dommages", parseInt(event.target.value) );
} );
// Roll Skill
html.find('.competence-label a').click(async event => {
2020-11-14 23:24:01 +01:00
let compName = event.currentTarget.text;
2021-01-19 23:39:35 +01:00
this.actor.rollCompetence( compName );
2020-11-14 23:24:01 +01:00
});
html.find('.endurance-plus').click(event => {
2020-11-14 23:24:01 +01:00
this.actor.santeIncDec("endurance", 1);
this.render(true);
});
html.find('.endurance-moins').click(event => {
2020-11-14 23:24:01 +01:00
this.actor.santeIncDec("endurance", -1);
this.render(true);
});
html.find('.encaisser-direct').click(event => {
this.actor.encaisser();
});
html.find('.remise-a-neuf').click(event => {
if (game.user.isGM) {
this.actor.remiseANeuf();
}
});
2020-11-14 23:24:01 +01:00
}
/* -------------------------------------------- */
/** @override */
setPosition(options = {}) {
2020-11-14 23:24:01 +01:00
const position = super.setPosition(options);
const sheetHeader = this.element.find(".sheet-header");
const sheetTabs = this.element.find(".sheet-tabs");
2020-11-14 23:24:01 +01:00
const sheetBody = this.element.find(".sheet-body");
const bodyHeight = position.height - sheetHeader[0].clientHeight - sheetTabs[0].clientHeight;
2020-11-14 23:24:01 +01:00
sheetBody.css("height", bodyHeight);
return position;
}
/* -------------------------------------------- */
/** @override */
_updateObject(event, formData) {
// Update the Actor
return this.object.update(formData);
}
}