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

146 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() {
2021-03-25 03:18:27 +01:00
let formData = {
title: this.title,
id: this.actor.id,
type: this.actor.type,
img: this.actor.img,
name: this.actor.name,
2021-03-25 03:18:27 +01:00
editable: this.isEditable,
cssClass: this.isEditable ? "editable" : "locked",
system: foundry.utils.deepClone(this.actor.system),
effects: this.actor.effects.map(e => foundry.utils.deepClone(e)),
2021-03-25 03:18:27 +01:00
// items: items,
limited: this.actor.limited,
2021-03-25 03:18:27 +01:00
options: this.options,
owner: this.actor.isOwner,
2022-09-27 21:03:18 +02:00
description: await TextEditor.enrichHTML(this.object.system.description, {async: true}),
notesmj: await TextEditor.enrichHTML(this.object.system.notesmj, {async: true}),
2021-03-25 03:18:27 +01:00
};
2020-11-14 23:24:01 +01:00
formData.options.isGM = game.user.isGM;
2022-09-26 23:01:29 +02:00
RdDUtility.filterItemsPerTypeForSheet(formData, this.actor.itemTypes);
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.actor.update(formData);
2020-11-14 23:24:01 +01:00
}
}