bol/module/item/item-sheet.js

116 lines
3.5 KiB
JavaScript
Raw Normal View History

2021-11-01 00:28:42 +01:00
import { BoLUtility } from "../system/bol-utility.js";
2021-07-08 10:12:12 +02:00
/**
* Extend the basic ItemSheet with some very simple modifications
* @extends {ItemSheet}
*/
export class BoLItemSheet extends ItemSheet {
/** @override */
static get defaultOptions() {
return mergeObject(super.defaultOptions, {
classes: ["bol", "sheet", "item"],
template: "systems/bol/templates/item/item-sheet.hbs",
width: 650,
2022-03-27 22:56:43 +02:00
height: 780,
2021-07-08 10:12:12 +02:00
tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "description" }]
});
}
/* -------------------------------------------- */
/** @override */
2022-09-27 20:47:30 +02:00
async getData(options) {
2022-07-01 15:48:54 +02:00
const data = super.getData(options)
let itemData = duplicate(data.document)
data.config = game.bol.config
data.item = itemData
data.category = itemData.system.category
data.isGM = game.user.isGM;
2022-07-01 16:30:21 +02:00
data.itemProperties = this.item.itemProperties;
2023-06-23 08:37:50 +02:00
data.description = await TextEditor.enrichHTML(this.object.system.description, { async: true })
2022-01-23 09:25:09 +01:00
2022-01-27 07:47:42 +01:00
// Dynamic default data fix/adapt
if (itemData.type == "item") {
2022-07-01 15:48:54 +02:00
if (!itemData.system.category) {
itemData.system.category = "equipment"
2022-01-23 09:25:09 +01:00
}
2023-06-23 08:37:50 +02:00
if (itemData.system.category == "equipment" && itemData.system.properties.equipable) {
2022-07-01 15:48:54 +02:00
if (!itemData.system.properties.slot) {
itemData.system.properties.slot = "-"
2022-02-11 23:29:57 +01:00
}
}
2022-07-01 15:48:54 +02:00
if (itemData.system.category == 'spell') {
2023-06-23 08:37:50 +02:00
if (!itemData.system.properties.mandatoryconditions) {
2022-07-01 15:48:54 +02:00
itemData.system.properties.mandatoryconditions = []
2022-02-12 21:09:28 +01:00
}
2023-06-23 08:37:50 +02:00
if (!itemData.system.properties.optionnalconditions) {
2022-07-01 15:48:54 +02:00
itemData.system.properties.optionnalconditions = []
2022-02-12 21:09:28 +01:00
}
2022-01-27 07:47:42 +01:00
for (let i = 0; i < 4; i++) {
2022-07-01 15:48:54 +02:00
itemData.system.properties.mandatoryconditions[i] = itemData.system.properties.mandatoryconditions[i] ?? ""
2022-01-27 07:47:42 +01:00
}
for (let i = 0; i < 8; i++) {
2022-07-01 15:48:54 +02:00
itemData.system.properties.optionnalconditions[i] = itemData.system.properties.optionnalconditions[i] ?? ""
2022-01-27 07:47:42 +01:00
}
}
} else {
2022-07-01 15:48:54 +02:00
if (!itemData.system.subtype) {
itemData.system.category = "origin"
2022-01-23 09:25:09 +01:00
}
}
console.log("ITEMDATA", data);
return data;
2021-07-08 10:12:12 +02:00
}
/* -------------------------------------------- */
2023-06-23 08:37:50 +02:00
_getHeaderButtons() {
let buttons = super._getHeaderButtons();
buttons.unshift({
class: "post",
icon: "fas fa-comment",
onclick: ev => this.postItem()
});
return buttons
}
/* -------------------------------------------- */
postItem() {
let chatData = duplicate(this.item)
if (this.actor) {
chatData.actor = { id: this.actor.id };
}
BoLUtility.postItem(chatData);
}
2021-07-08 10:12:12 +02:00
2023-06-23 08:37:50 +02:00
/* -------------------------------------------- */
2021-07-08 10:12:12 +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 */
activateListeners(html) {
2022-01-27 07:47:42 +01:00
2021-07-08 10:12:12 +02:00
super.activateListeners(html);
// Everything below here is only needed if the sheet is editable
if (!this.options.editable) return;
// Roll handlers, click handlers, etc. would go here.
html.find('.armorQuality').change(ev => {
const li = $(ev.currentTarget);
console.log(game.bol.config.soakFormulas[li.val()]);
$('.soakFormula').val(game.bol.config.soakFormulas[li.val()]);
});
2021-07-08 10:12:12 +02:00
}
2021-11-08 14:40:29 +01:00
2021-07-08 10:12:12 +02:00
}