2020-11-14 23:24:01 +01:00
|
|
|
/**
|
|
|
|
* Extend the basic ActorSheet with some very simple modifications
|
|
|
|
* @extends {ActorSheet}
|
|
|
|
*/
|
|
|
|
|
2020-12-27 19:55:51 +01:00
|
|
|
import { HtmlUtility } from "./html-utility.js";
|
2021-03-17 01:21:37 +01:00
|
|
|
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}]
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
2021-03-17 01:21:37 +01:00
|
|
|
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
|
|
|
|
2021-03-17 01:21:37 +01:00
|
|
|
formData.options.isGM = game.user.isGM;
|
2021-03-25 03:18:27 +01:00
|
|
|
RdDUtility.filterItemsPerTypeForSheet(formData);
|
2021-03-17 01:21:37 +01:00
|
|
|
|
2020-12-01 20:52:05 +01:00
|
|
|
|
2021-03-16 22:56:57 +01:00
|
|
|
return formData;
|
2020-11-14 23:24:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
/** @override */
|
|
|
|
activateListeners(html) {
|
|
|
|
super.activateListeners(html);
|
2020-12-27 22:21:08 +01:00
|
|
|
|
2020-12-27 19:55:51 +01:00
|
|
|
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
|
2021-12-11 02:20:20 +01:00
|
|
|
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
|
2021-12-11 02:20:20 +01:00
|
|
|
html.find('.item-delete').click(event => {
|
|
|
|
const li = $(event.currentTarget).parents(".item");
|
2021-03-29 23:41:08 +02:00
|
|
|
this.actor.deleteEmbeddedDocuments('Item', [li.data("itemId")]);
|
2020-11-14 23:24:01 +01:00
|
|
|
li.slideUp(200, () => this.render(false));
|
|
|
|
});
|
|
|
|
|
|
|
|
// Roll Carac
|
2021-12-11 02:20:20 +01:00
|
|
|
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
|
2021-12-11 02:20:20 +01:00
|
|
|
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) );
|
|
|
|
} );
|
2021-12-11 02:20:20 +01:00
|
|
|
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) );
|
|
|
|
} );
|
2021-12-11 02:20:20 +01:00
|
|
|
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
|
2021-12-11 02:20:20 +01:00
|
|
|
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
|
|
|
});
|
|
|
|
|
2021-12-11 02:20:20 +01:00
|
|
|
html.find('.endurance-plus').click(event => {
|
2020-11-14 23:24:01 +01:00
|
|
|
this.actor.santeIncDec("endurance", 1);
|
|
|
|
this.render(true);
|
|
|
|
});
|
2021-12-11 02:20:20 +01:00
|
|
|
html.find('.endurance-moins').click(event => {
|
2020-11-14 23:24:01 +01:00
|
|
|
this.actor.santeIncDec("endurance", -1);
|
|
|
|
this.render(true);
|
|
|
|
});
|
2020-12-27 19:55:51 +01:00
|
|
|
|
2021-12-11 02:20:20 +01:00
|
|
|
html.find('.encaisser-direct').click(event => {
|
2020-12-27 19:55:51 +01:00
|
|
|
this.actor.encaisser();
|
|
|
|
});
|
|
|
|
|
2021-12-11 02:20:20 +01:00
|
|
|
html.find('.remise-a-neuf').click(event => {
|
2020-12-27 19:55:51 +01:00
|
|
|
if (game.user.isGM) {
|
|
|
|
this.actor.remiseANeuf();
|
|
|
|
}
|
|
|
|
});
|
2020-11-14 23:24:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
|
|
|
/** @override */
|
2021-05-09 18:16:01 +02:00
|
|
|
setPosition(options = {}) {
|
2020-11-14 23:24:01 +01:00
|
|
|
const position = super.setPosition(options);
|
2021-05-09 18:16:01 +02:00
|
|
|
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");
|
2021-05-09 18:16:01 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|