2022-12-26 00:33:13 +01:00
|
|
|
import { HeritiersUtility } from "./heritiers-utility.js";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Extend the basic ItemSheet with some very simple modifications
|
|
|
|
* @extends {ItemSheet}
|
|
|
|
*/
|
|
|
|
export class HeritiersItemSheet extends ItemSheet {
|
|
|
|
|
|
|
|
/** @override */
|
|
|
|
static get defaultOptions() {
|
|
|
|
|
2024-05-23 11:25:51 +02:00
|
|
|
return foundry.utils.mergeObject(super.defaultOptions, {
|
2022-12-26 00:33:13 +01:00
|
|
|
classes: ["fvtt-les-heritiers", "sheet", "item"],
|
|
|
|
template: "systems/fvtt-les-heritiers/templates/item-sheet.html",
|
|
|
|
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() {
|
2024-05-23 11:25:51 +02:00
|
|
|
const objectData = foundry.utils.duplicate(this.object)
|
2022-12-26 00:33:13 +01:00
|
|
|
let formData = {
|
|
|
|
title: this.title,
|
|
|
|
id: this.id,
|
|
|
|
type: objectData.type,
|
|
|
|
img: objectData.img,
|
|
|
|
name: objectData.name,
|
|
|
|
editable: this.isEditable,
|
|
|
|
cssClass: this.isEditable ? "editable" : "locked",
|
|
|
|
system: objectData.system,
|
|
|
|
limited: this.object.limited,
|
|
|
|
options: this.options,
|
|
|
|
owner: this.document.isOwner,
|
2024-03-23 11:37:15 +01:00
|
|
|
config: game.system.lesheritiers.config,
|
2023-04-09 21:45:46 +02:00
|
|
|
isArmeMelee: HeritiersUtility.isArmeMelee(this.object),
|
2022-12-26 00:33:13 +01:00
|
|
|
description: await TextEditor.enrichHTML(this.object.system.description, {async: true}),
|
|
|
|
mr: (this.object.type == 'specialisation'),
|
2024-03-23 11:37:15 +01:00
|
|
|
isGM: game.user.isGM,
|
|
|
|
usageMax: -1
|
|
|
|
}
|
|
|
|
|
|
|
|
// Items specific data
|
|
|
|
if (this.object.type == 'pouvoir' && this.document.isOwner && this.actor) {
|
|
|
|
formData.usageMax = this.actor.getPouvoirUsageMax(this.object)
|
|
|
|
if (this.object.system.pointsusagecourant == -1) {
|
|
|
|
this.object.system.pointsusagecourant = formData.usageMax
|
|
|
|
}
|
2022-12-26 00:33:13 +01:00
|
|
|
}
|
2024-11-17 22:45:48 +01:00
|
|
|
if (this.object.type == 'sort' ) {
|
|
|
|
formData.competencesMagie = HeritiersUtility.getCompetencesMagie()
|
|
|
|
}
|
|
|
|
|
2022-12-26 00:33:13 +01:00
|
|
|
|
|
|
|
//this.options.editable = !(this.object.origin == "embeddedItem");
|
|
|
|
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() {
|
2024-05-23 11:25:51 +02:00
|
|
|
let chatData = foundry.utils.duplicate(HeritiersUtility.data(this.item));
|
2022-12-26 00:33:13 +01:00
|
|
|
if (this.actor) {
|
|
|
|
chatData.actor = { id: this.actor.id };
|
|
|
|
}
|
|
|
|
// 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")) {
|
|
|
|
chatData.img = null;
|
|
|
|
}
|
|
|
|
// JSON object for easy creation
|
|
|
|
chatData.jsondata = JSON.stringify(
|
|
|
|
{
|
|
|
|
compendium: "postedItem",
|
|
|
|
payload: chatData,
|
|
|
|
});
|
|
|
|
|
|
|
|
renderTemplate('systems/fvtt-Heritiers-rpg/templates/post-item.html', chatData).then(html => {
|
|
|
|
let chatOptions = HeritiersUtility.chatDataSetup(html);
|
|
|
|
ChatMessage.create(chatOptions)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
/** @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);
|
|
|
|
});
|
|
|
|
|
|
|
|
html.find('.delete-subitem').click(ev => {
|
|
|
|
this.deleteSubitem(ev);
|
|
|
|
})
|
2023-01-18 16:16:18 +01:00
|
|
|
|
2022-12-28 14:10:58 +01:00
|
|
|
html.find('#add-specialite').click(ev => {
|
2024-05-23 11:25:51 +02:00
|
|
|
let spec = foundry.utils.duplicate(this.object.system.specialites)
|
|
|
|
spec.push( { name: "Nouvelle Spécialité", id: foundry.utils.randomID(16), used: false })
|
2022-12-28 14:10:58 +01:00
|
|
|
this.object.update( { 'system.specialites': spec })
|
2022-12-26 00:33:13 +01:00
|
|
|
})
|
2022-12-28 14:10:58 +01:00
|
|
|
html.find('.delete-specialite').click(ev => {
|
|
|
|
const li = $(ev.currentTarget).parents(".specialite-item")
|
|
|
|
let index = li.data("specialite-index")
|
2024-05-23 11:25:51 +02:00
|
|
|
let spec = foundry.utils.duplicate(this.object.system.specialites)
|
2022-12-28 14:10:58 +01:00
|
|
|
spec.splice(index,1)
|
|
|
|
this.object.update( { 'system.specialites': spec })
|
2022-12-26 00:33:13 +01:00
|
|
|
})
|
2023-01-18 16:16:18 +01:00
|
|
|
html.find('.edit-specialite').change(ev => {
|
|
|
|
const li = $(ev.currentTarget).parents(".specialite-item")
|
|
|
|
let index = li.data("specialite-index")
|
2024-05-23 11:25:51 +02:00
|
|
|
let spec = foundry.utils.duplicate(this.object.system.specialites)
|
2023-01-18 16:16:18 +01:00
|
|
|
spec[index].name = ev.currentTarget.value
|
2024-05-23 11:25:51 +02:00
|
|
|
spec[index].id = spec[index].id || foundry.utils.randomID(16)
|
2023-01-18 16:16:18 +01:00
|
|
|
this.object.update( { 'system.specialites': spec })
|
|
|
|
})
|
|
|
|
html.find('.edit-specialite-description').change(ev => {
|
|
|
|
const li = $(ev.currentTarget).parents(".specialite-item")
|
|
|
|
let index = li.data("specialite-index")
|
2024-05-23 11:25:51 +02:00
|
|
|
let spec = foundry.utils.duplicate(this.object.system.specialites)
|
2023-01-18 16:16:18 +01:00
|
|
|
spec[index].description = ev.currentTarget.value
|
2024-05-23 11:25:51 +02:00
|
|
|
spec[index].id = spec[index].id || foundry.utils.randomID(16)
|
2023-01-18 16:16:18 +01:00
|
|
|
this.object.update( { 'system.specialites': spec })
|
|
|
|
})
|
2022-12-26 00:33:13 +01:00
|
|
|
|
|
|
|
html.find('#add-automation').click(ev => {
|
2024-05-23 11:25:51 +02:00
|
|
|
let autom = foundry.utils.duplicate(this.object.system.automations)
|
|
|
|
autom.push( { eventtype: "on-drop", name: "Automatisation 1", competence: "", minLevel: 0, id: foundry.utils.randomID(16) })
|
2022-12-26 00:33:13 +01:00
|
|
|
this.object.update( { 'system.automations': autom })
|
|
|
|
})
|
|
|
|
html.find('.delete-automation').click(ev => {
|
|
|
|
const li = $(ev.currentTarget).parents(".automation-item")
|
|
|
|
let index = li.data("automation-index")
|
2024-05-23 11:25:51 +02:00
|
|
|
let autom = foundry.utils.duplicate(this.object.system.automations)
|
2022-12-26 00:33:13 +01:00
|
|
|
autom.splice(index,1)
|
|
|
|
this.object.update( { 'system.automations': autom })
|
|
|
|
})
|
|
|
|
html.find('.automation-edit-field').change(ev => {
|
|
|
|
let index = $(ev.currentTarget).data("automation-index")
|
|
|
|
let field = $(ev.currentTarget).data("automation-field")
|
2024-05-23 11:25:51 +02:00
|
|
|
let auto = foundry.utils.duplicate(this.object.system.automations)
|
2022-12-26 00:33:13 +01:00
|
|
|
auto[index][field] = ev.currentTarget.value
|
2024-05-23 11:25:51 +02:00
|
|
|
auto[index].id = auto[index].id || foundry.utils.randomID(16)
|
2022-12-26 00:33:13 +01:00
|
|
|
this.object.update( { 'system.automations': auto })
|
|
|
|
})
|
|
|
|
|
|
|
|
// 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");
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
get template() {
|
|
|
|
let type = this.item.type;
|
|
|
|
return `systems/fvtt-les-heritiers/templates/item-${type}-sheet.html`;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
/** @override */
|
|
|
|
_updateObject(event, formData) {
|
|
|
|
return this.object.update(formData);
|
|
|
|
}
|
|
|
|
}
|