From f3bbcd74994c345e83b4fc61533a02afcea6804d Mon Sep 17 00:00:00 2001 From: Vlyan Date: Sun, 1 Aug 2021 16:45:11 +0200 Subject: [PATCH] - Added "send to chat" button on items sheets. - Minor fixe on editable state. --- CHANGELOG.md | 5 ++ system/lang/en-en.json | 1 + system/lang/es-es.json | 1 + system/lang/fr-fr.json | 1 + system/scripts/actors/base-sheet.js | 4 +- system/scripts/actors/character-sheet.js | 4 +- .../scripts/actors/twenty-questions-dialog.js | 4 +- system/scripts/dice/roll-n-keep-dialog.js | 6 +-- system/scripts/helpers.js | 7 +-- system/scripts/item.js | 14 ++++++ system/scripts/items/advancement-sheet.js | 2 +- system/scripts/items/item-pattern-sheet.js | 4 +- system/scripts/items/item-sheet.js | 50 ++++++++++++++++++- system/scripts/items/title-sheet.js | 4 +- system/scripts/journals/base-journal-sheet.js | 2 +- 15 files changed, 87 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fc8c627..6d2d7ad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ # Changelog ## 1.3.3 - TODO +- Added "send to chat" button on items sheets. +- Fixed Compendium entries thanks to TesserWract : + - Utaku Battle Maiden: Replace "Striking as Air" with "Courtier's Resolve". + - Weapons: Chair, lute, sake bottle and cups, and scroll case use the "Unarmed skill" and changed the umbrella's stab grip to be 2-handed. +- Minor fixe on editable state. ## 1.3.2 - Ronin's Bubble - Added a tooltip on hover with all information for items, and removed all these silly moving description (which made me crazy). diff --git a/system/lang/en-en.json b/system/lang/en-en.json index e42f5e0..3cecc5b 100644 --- a/system/lang/en-en.json +++ b/system/lang/en-en.json @@ -42,6 +42,7 @@ "edit": "Edit", "delete_confirm": "Are you sure you want to delete '{name}' ?", "drop_here": "Drop here", + "send_to_chat": "Send to Chat", "edge_translation_disclaimer": "" }, "logo": { diff --git a/system/lang/es-es.json b/system/lang/es-es.json index 237abd9..d5be9a7 100644 --- a/system/lang/es-es.json +++ b/system/lang/es-es.json @@ -42,6 +42,7 @@ "edit": "Editar", "delete_confirm": "¿Estás seguro de que quieres borrar '{name}' ?", "drop_here": "Dejar caer aquí", + "send_to_chat": "Send to Chat", "edge_translation_disclaimer": "Edge Studio nos da su permiso para ofrecer este módulo a la comunidad, pero tanto los textos así como los códigos que lo constituyen no tienen su aprobación explícita." }, "logo": { diff --git a/system/lang/fr-fr.json b/system/lang/fr-fr.json index c576fd7..3a06cc4 100644 --- a/system/lang/fr-fr.json +++ b/system/lang/fr-fr.json @@ -42,6 +42,7 @@ "edit": "Modifier", "delete_confirm": "Etes-vous sûr de vouloir supprimer '{name}' ?", "drop_here": "Déposez ici", + "send_to_chat": "Env. dans la Conv.", "edge_translation_disclaimer": "" }, "logo": { diff --git a/system/scripts/actors/base-sheet.js b/system/scripts/actors/base-sheet.js index 50b92d9..fb7667c 100644 --- a/system/scripts/actors/base-sheet.js +++ b/system/scripts/actors/base-sheet.js @@ -177,7 +177,7 @@ export class BaseSheetL5r5e extends ActorSheet { */ async _onDrop(event) { // *** Everything below here is only needed if the sheet is editable *** - if (!this.options.editable) { + if (!this.isEditable) { return; } @@ -317,7 +317,7 @@ export class BaseSheetL5r5e extends ActorSheet { game.l5r5e.HelpersL5r5e.commonListeners(html, this.actor); // *** Everything below here is only needed if the sheet is editable *** - if (!this.options.editable) { + if (!this.isEditable) { return; } diff --git a/system/scripts/actors/character-sheet.js b/system/scripts/actors/character-sheet.js index b2ac79c..e2b25d5 100644 --- a/system/scripts/actors/character-sheet.js +++ b/system/scripts/actors/character-sheet.js @@ -22,7 +22,7 @@ export class CharacterSheetL5r5e extends BaseSheetL5r5e { */ _getHeaderButtons() { let buttons = super._getHeaderButtons(); - if (!this.options.editable || this.actor.limited) { + if (!this.isEditable || this.actor.limited) { return buttons; } @@ -71,7 +71,7 @@ export class CharacterSheetL5r5e extends BaseSheetL5r5e { super.activateListeners(html); // *** Everything below here is only needed if the sheet is editable *** - if (!this.options.editable) { + if (!this.isEditable) { return; } diff --git a/system/scripts/actors/twenty-questions-dialog.js b/system/scripts/actors/twenty-questions-dialog.js index 1c3c582..6f8bab4 100644 --- a/system/scripts/actors/twenty-questions-dialog.js +++ b/system/scripts/actors/twenty-questions-dialog.js @@ -188,7 +188,7 @@ export class TwentyQuestionsDialog extends FormApplication { }); // *** Everything below here is only needed if the sheet is editable *** - if (!this.options.editable) { + if (!this.isEditable) { return; } @@ -228,7 +228,7 @@ export class TwentyQuestionsDialog extends FormApplication { */ async _onDropItem(type, event) { // *** Everything below here is only needed if the sheet is editable *** - if (!this.options.editable) { + if (!this.isEditable) { return; } diff --git a/system/scripts/dice/roll-n-keep-dialog.js b/system/scripts/dice/roll-n-keep-dialog.js index 7366721..db679e5 100644 --- a/system/scripts/dice/roll-n-keep-dialog.js +++ b/system/scripts/dice/roll-n-keep-dialog.js @@ -258,7 +258,7 @@ export class RollnKeepDialog extends FormApplication { } // *** Everything below here is only needed if the sheet is editable *** - if (!this.options.editable) { + if (!this.isEditable) { return; } @@ -277,7 +277,7 @@ export class RollnKeepDialog extends FormApplication { */ async _onDropItem(event) { // *** Everything below here is only needed if the sheet is editable *** - if (!this.options.editable) { + if (!this.isEditable) { return; } @@ -660,7 +660,7 @@ export class RollnKeepDialog extends FormApplication { */ async _updateObject(event, formData) { // *** Everything below here is only needed if the sheet is editable *** - if (!this.options.editable) { + if (!this.isEditable) { return; } diff --git a/system/scripts/helpers.js b/system/scripts/helpers.js index 8e2a074..9bf1958 100644 --- a/system/scripts/helpers.js +++ b/system/scripts/helpers.js @@ -431,11 +431,7 @@ export class HelpersL5r5e { return; } - const type = item.type.replace("_", "-"); // ex: item_pattern - const tpl = await renderTemplate( - `${CONFIG.l5r5e.paths.templates}items/${type}/${type}-text.html`, - item - ); + const tpl = await item.renderTextTemplate(); if (!tpl) { return; } @@ -460,6 +456,7 @@ export class HelpersL5r5e { * Get a Item from a Actor Sheet * @param {Event} event HTML Event * @param {ActorL5r5e} actor + * @return {ItemL5r5e} */ static async getEmbedItemByEvent(event, actor) { const current = $(event.currentTarget); diff --git a/system/scripts/item.js b/system/scripts/item.js index afaf595..74c4570 100644 --- a/system/scripts/item.js +++ b/system/scripts/item.js @@ -115,6 +115,20 @@ export class ItemL5r5e extends Item { return parentItem; } + /** + * Render the text template for this Item (tooltips and chat) + * @return {Promise} + */ + async renderTextTemplate() { + const type = this.type.replace("_", "-"); // ex: item_pattern + await game.l5r5e.HelpersL5r5e.refreshItemProperties(this); + const tpl = await renderTemplate(`${CONFIG.l5r5e.paths.templates}items/${type}/${type}-text.html`, this); + if (!tpl) { + return null; + } + return tpl; + } + // ***** Embedded items management ***** /** * Shortcut for this.data.data.items.get diff --git a/system/scripts/items/advancement-sheet.js b/system/scripts/items/advancement-sheet.js index 60362e1..4c34509 100644 --- a/system/scripts/items/advancement-sheet.js +++ b/system/scripts/items/advancement-sheet.js @@ -37,7 +37,7 @@ export class AdvancementSheetL5r5e extends ItemSheetL5r5e { super.activateListeners(html); // Everything below here is only needed if the sheet is editable - if (!this.options.editable) { + if (!this.isEditable) { return; } diff --git a/system/scripts/items/item-pattern-sheet.js b/system/scripts/items/item-pattern-sheet.js index e7f9f47..d9d8444 100644 --- a/system/scripts/items/item-pattern-sheet.js +++ b/system/scripts/items/item-pattern-sheet.js @@ -56,7 +56,7 @@ export class ItemPatternSheetL5r5e extends ItemSheetL5r5e { super.activateListeners(html); // Everything below here is only needed if the sheet is editable - if (!this.options.editable) { + if (!this.isEditable) { return; } @@ -71,7 +71,7 @@ export class ItemPatternSheetL5r5e extends ItemSheetL5r5e { */ async _onDrop(event) { // Everything below here is only needed if the sheet is editable - if (!this.options.editable) { + if (!this.isEditable) { return; } diff --git a/system/scripts/items/item-sheet.js b/system/scripts/items/item-sheet.js index f4282e0..adad52e 100644 --- a/system/scripts/items/item-sheet.js +++ b/system/scripts/items/item-sheet.js @@ -14,6 +14,48 @@ export class ItemSheetL5r5e extends ItemSheet { }); } + /** + * Add the SendToChat button on top of sheet + * @override + */ + _getHeaderButtons() { + let buttons = super._getHeaderButtons(); + + // Send To Chat + buttons.unshift({ + label: game.i18n.localize("l5r5e.global.send_to_chat"), + class: "twenty-questions", + icon: "fas fa-comment-dots", + onclick: async () => this.sendToChat(), + }); + + return buttons; + } + + /** + * Send the description of this Item to chat + * @return {Promise<*>} + */ + async sendToChat() { + const tpl = await this.object.renderTextTemplate(); + if (!tpl) { + return; + } + + let link = null; + if (this.object.data.flags.core?.sourceId) { + link = this.object.data.flags.core?.sourceId.replace(/(\w+)\.(.+)/, "@$1[$2]"); + } else if (this.object.pack) { + link = `@Compendium[${this.object.pack}.${this.object.id}]{${this.object.name}}`; + } else if (!this.object.actor) { + link = this.object.link; + } + + return ChatMessage.create({ + content: (link ? link + `
` : "") + tpl, + }); + } + /** * @return {Object|Promise} */ @@ -26,6 +68,10 @@ export class ItemSheetL5r5e extends ItemSheet { // Prepare Properties (id/name => object) await this._prepareProperties(sheetData); + // Fix editable + sheetData.editable = this.isEditable; + sheetData.options.editable = sheetData.editable; + return sheetData; } @@ -94,7 +140,7 @@ export class ItemSheetL5r5e extends ItemSheet { game.l5r5e.HelpersL5r5e.commonListeners(html); // Everything below here is only needed if the sheet is editable - if (!this.options.editable) { + if (!this.isEditable) { return; } @@ -130,7 +176,7 @@ export class ItemSheetL5r5e extends ItemSheet { */ async _onDrop(event) { // Everything below here is only needed if the sheet is editable - if (!this.options.editable) { + if (!this.isEditable) { return; } diff --git a/system/scripts/items/title-sheet.js b/system/scripts/items/title-sheet.js index a0e39bb..c496399 100644 --- a/system/scripts/items/title-sheet.js +++ b/system/scripts/items/title-sheet.js @@ -57,7 +57,7 @@ export class TitleSheetL5r5e extends ItemSheetL5r5e { */ async _onDrop(event) { // Everything below here is only needed if the sheet is editable - if (!this.options.editable) { + if (!this.isEditable) { return; } @@ -86,7 +86,7 @@ export class TitleSheetL5r5e extends ItemSheetL5r5e { super.activateListeners(html); // Everything below here is only needed if the sheet is editable - if (!this.options.editable) { + if (!this.isEditable) { return; } diff --git a/system/scripts/journals/base-journal-sheet.js b/system/scripts/journals/base-journal-sheet.js index 0002bde..6aa1a69 100644 --- a/system/scripts/journals/base-journal-sheet.js +++ b/system/scripts/journals/base-journal-sheet.js @@ -43,7 +43,7 @@ export class BaseJournalSheetL5r5e extends JournalSheet { game.l5r5e.HelpersL5r5e.commonListeners(html); // *** Everything below here is only needed if the sheet is editable *** - // if (!this.options.editable) { + // if (!this.isEditable) { // return; // } }