2022-03-13 16:17:04 +01:00
|
|
|
import { Imperium5Utility } from "./imperium5-utility.js";
|
|
|
|
|
2022-03-19 09:30:00 +01:00
|
|
|
/* -------------------------------------------- */
|
2022-03-13 16:17:04 +01:00
|
|
|
/**
|
|
|
|
* Extend the basic ItemSheet with some very simple modifications
|
|
|
|
* @extends {ItemSheet}
|
|
|
|
*/
|
2022-03-19 09:30:00 +01:00
|
|
|
export class Imperium5ItemSheet extends ItemSheet {
|
2022-03-13 16:17:04 +01:00
|
|
|
|
2022-03-19 09:30:00 +01:00
|
|
|
/* -------------------------------------------- */
|
2022-03-13 16:17:04 +01:00
|
|
|
/** @override */
|
|
|
|
static get defaultOptions() {
|
|
|
|
|
|
|
|
return mergeObject(super.defaultOptions, {
|
2022-03-19 09:30:00 +01:00
|
|
|
classes: ["fvtt-imperium5", "sheet", "item"],
|
|
|
|
template: "systems/fvtt-imperium5/templates/item-sheet.html",
|
2022-03-13 16:17:04 +01:00
|
|
|
dragDrop: [{ dragSelector: null, dropSelector: null }],
|
|
|
|
width: 620,
|
|
|
|
height: 550,
|
|
|
|
tabs: [{navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "description"}]
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
_getHeaderButtons() {
|
|
|
|
let buttons = super._getHeaderButtons();
|
|
|
|
// Add "Post to chat" button
|
|
|
|
// We previously restricted this to GM and editable items only. If you ever find this comment because it broke something: eh, sorry!
|
|
|
|
buttons.unshift(
|
|
|
|
{
|
|
|
|
class: "post",
|
|
|
|
icon: "fas fa-comment",
|
|
|
|
onclick: ev => { }
|
|
|
|
})
|
|
|
|
return buttons
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
/** @override */
|
|
|
|
setPosition(options = {}) {
|
|
|
|
const position = super.setPosition(options);
|
|
|
|
const sheetBody = this.element.find(".sheet-body");
|
|
|
|
const bodyHeight = position.height - 192;
|
|
|
|
sheetBody.css("height", bodyHeight);
|
|
|
|
if (this.item.type.includes('weapon')) {
|
|
|
|
position.width = 640;
|
|
|
|
}
|
|
|
|
return position;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
async getData() {
|
2022-10-19 17:30:47 +02:00
|
|
|
const objectData = duplicate(this.object.system)
|
2022-03-13 16:17:04 +01:00
|
|
|
|
|
|
|
let formData = {
|
|
|
|
title: this.title,
|
|
|
|
id: this.id,
|
2022-10-19 17:30:47 +02:00
|
|
|
type: this.object.type,
|
|
|
|
img: this.object.img,
|
|
|
|
name: this.object.name,
|
2022-03-13 16:17:04 +01:00
|
|
|
editable: this.isEditable,
|
|
|
|
cssClass: this.isEditable ? "editable" : "locked",
|
2022-10-19 17:30:47 +02:00
|
|
|
system: objectData,
|
2022-03-13 16:17:04 +01:00
|
|
|
limited: this.object.limited,
|
|
|
|
options: this.options,
|
|
|
|
owner: this.document.isOwner,
|
|
|
|
isGM: game.user.isGM
|
|
|
|
}
|
|
|
|
|
2022-10-19 17:30:47 +02:00
|
|
|
this.options.editable = !(this.object.system.origin == "embeddedItem");
|
2022-03-13 16:17:04 +01:00
|
|
|
console.log("ITEM DATA", formData, this);
|
|
|
|
return formData;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
_getHeaderButtons() {
|
|
|
|
let buttons = super._getHeaderButtons();
|
|
|
|
buttons.unshift({
|
|
|
|
class: "post",
|
|
|
|
icon: "fas fa-comment",
|
|
|
|
onclick: ev => this.postItem()
|
|
|
|
});
|
|
|
|
return buttons
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
postItem() {
|
2022-10-19 17:30:47 +02:00
|
|
|
let chatData = duplicate( this.item.system)
|
2022-03-13 16:17:04 +01:00
|
|
|
if (this.actor) {
|
2022-03-19 09:30:00 +01:00
|
|
|
chatData.actor = { id: this.actor.id }
|
2022-03-13 16:17:04 +01:00
|
|
|
}
|
|
|
|
// Don't post any image for the item (which would leave a large gap) if the default image is used
|
|
|
|
if (chatData.img.includes("/blank.png")) {
|
2022-03-19 09:30:00 +01:00
|
|
|
chatData.img = null
|
2022-03-13 16:17:04 +01:00
|
|
|
}
|
|
|
|
// JSON object for easy creation
|
|
|
|
chatData.jsondata = JSON.stringify(
|
|
|
|
{
|
|
|
|
compendium: "postedItem",
|
|
|
|
payload: chatData,
|
|
|
|
});
|
|
|
|
|
2022-03-19 09:30:00 +01:00
|
|
|
renderTemplate('systems/fvtt-imperium5/templates/post-item.html', chatData).then(html => {
|
|
|
|
let chatOptions = Imperium5Utility.chatDataSetup(html);
|
2022-03-13 16:17:04 +01:00
|
|
|
ChatMessage.create(chatOptions)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
async viewSubitem(ev) {
|
|
|
|
let field = $(ev.currentTarget).data('type');
|
|
|
|
let idx = Number($(ev.currentTarget).data('index'));
|
2022-10-19 17:30:47 +02:00
|
|
|
let itemData = this.object.system[field][idx];
|
2022-03-13 16:17:04 +01:00
|
|
|
if (itemData.name != 'None') {
|
|
|
|
let spec = await Item.create(itemData, { temporary: true });
|
|
|
|
spec.data.origin = "embeddedItem";
|
2022-03-19 09:30:00 +01:00
|
|
|
new Imperium5ItemSheet(spec).render(true);
|
2022-03-13 16:17:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
async deleteSubitem(ev) {
|
|
|
|
let field = $(ev.currentTarget).data('type');
|
|
|
|
let idx = Number($(ev.currentTarget).data('index'));
|
2022-10-19 17:30:47 +02:00
|
|
|
let oldArray = this.object.system[field];
|
|
|
|
let itemData = this.object.system[field][idx];
|
2022-03-13 16:17:04 +01:00
|
|
|
if (itemData.name != 'None') {
|
|
|
|
let newArray = [];
|
|
|
|
for (var i = 0; i < oldArray.length; i++) {
|
|
|
|
if (i != idx) {
|
|
|
|
newArray.push(oldArray[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.object.update({ [`data.${field}`]: newArray });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
async manageSpec() {
|
2022-10-19 17:30:47 +02:00
|
|
|
let itemData = this.object.system.specialisation[0];
|
2022-03-13 16:17:04 +01:00
|
|
|
if (itemData.name != 'None') {
|
|
|
|
let spec = await Item.create(itemData, { temporary: true });
|
|
|
|
spec.data.origin = "embeddedItem";
|
2022-03-19 09:30:00 +01:00
|
|
|
new Imperium5ItemSheet(spec).render(true);
|
2022-03-13 16:17:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
/** @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.object.options.actor.getOwnedItem(li.data("item-id"));
|
|
|
|
item.sheet.render(true);
|
2022-03-19 09:30:00 +01:00
|
|
|
})
|
2022-03-13 16:17:04 +01:00
|
|
|
|
|
|
|
html.find('.delete-subitem').click(ev => {
|
|
|
|
this.deleteSubitem(ev);
|
2022-03-19 09:30:00 +01:00
|
|
|
})
|
2022-03-13 16:17:04 +01:00
|
|
|
|
|
|
|
// Update Inventory Item
|
|
|
|
html.find('.item-delete').click(ev => {
|
|
|
|
const li = $(ev.currentTarget).parents(".item");
|
|
|
|
let itemId = li.data("item-id");
|
|
|
|
let itemType = li.data("item-type");
|
2022-03-19 09:30:00 +01:00
|
|
|
})
|
2022-03-13 16:17:04 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
async _onDrop(event) {
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
get template() {
|
|
|
|
let type = this.item.type;
|
2022-03-19 09:30:00 +01:00
|
|
|
return `systems/fvtt-imperium5/templates/item-default-sheet.html`;
|
2022-03-13 16:17:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
/** @override */
|
|
|
|
_updateObject(event, formData) {
|
|
|
|
return this.object.update(formData);
|
|
|
|
}
|
|
|
|
}
|