From e7bd9ea3fb9cba023a8ec00bef55d154e57bd75f Mon Sep 17 00:00:00 2001 From: Vlyan Date: Sat, 23 Jul 2022 21:59:13 +0200 Subject: [PATCH] Working on Compatibility for FVTT v10 SendToChat : Fix Journal behaviour --- system/scripts/helpers.js | 23 +++++++++++++--------- system/scripts/journal.js | 19 +++++++++++++----- system/templates/journal/journal-text.html | 8 ++++---- 3 files changed, 32 insertions(+), 18 deletions(-) diff --git a/system/scripts/helpers.js b/system/scripts/helpers.js index c418af0..8eaed71 100644 --- a/system/scripts/helpers.js +++ b/system/scripts/helpers.js @@ -597,32 +597,37 @@ export class HelpersL5r5e { /** * Send the description of this Item to chat - * @param {JournalL5r5e|ItemSheetL5r5e} object + * @param {JournalL5r5e|ItemL5r5e} document * @return {Promise<*>} */ - static async sendToChat(object) { + static async sendToChat(document) { // Get the html - const tpl = await object.renderTextTemplate(); + const tpl = await document.renderTextTemplate(); if (!tpl) { return; } + // Get the JournalEntryPage instead of JournalEntry + if (document.documentName === "JournalEntry") { + document = document.getCurrentPage(); + } + // Create the link let link = null; - if (object.flags.core?.sourceId) { - link = object.flags.core?.sourceId.replace(/(\w+)\.(.+)/, "@$1[$2]"); + if (document.flags.core?.sourceId) { + link = document.flags.core?.sourceId.replace(/(\w+)\.(.+)/, "@$1[$2]"); if (!HelpersL5r5e.isLinkValid(link)) { link = null; } } - if (!link && object.pack) { - link = `@Compendium[${object.pack}.${object.id}]{${object.name}}`; + if (!link && document.pack) { + link = `@Compendium[${document.pack}.${document.id}]{${document.name}}`; if (!HelpersL5r5e.isLinkValid(link)) { link = null; } } - if (!link && !object.actor) { - link = object.link; + if (!link && !document.actor) { + link = document.link; if (!HelpersL5r5e.isLinkValid(link)) { link = null; } diff --git a/system/scripts/journal.js b/system/scripts/journal.js index dc91749..d7b08e8 100644 --- a/system/scripts/journal.js +++ b/system/scripts/journal.js @@ -8,10 +8,19 @@ export class JournalL5r5e extends JournalEntry { */ async renderTextTemplate() { const data = (await this.sheet?.getData()) || this; - const tpl = await renderTemplate(`${CONFIG.l5r5e.paths.templates}journal/journal-text.html`, data); - if (!tpl) { - return null; - } - return tpl; + const pageData = data.pages[0]; + + const tpl = await renderTemplate(`${CONFIG.l5r5e.paths.templates}journal/journal-text.html`, { + data: pageData, + }); + return tpl || null; + } + + /** + * Return the Current JournalEntryPage + * @return JournalEntryPage + */ + getCurrentPage() { + return Array.from(this.pages)[this.sheet?.pageIndex || 0] || null; } } diff --git a/system/templates/journal/journal-text.html b/system/templates/journal/journal-text.html index b9c8494..4fcc9c8 100644 --- a/system/templates/journal/journal-text.html +++ b/system/templates/journal/journal-text.html @@ -1,15 +1,15 @@

- {{#ifCond data.img '&&' data.content}}{{/ifCond}} {{data.name}} + {{#ifCond data.src '&&' data.text.content}}{{/ifCond}} {{data.name}}

- {{#if data.content}} - {{{data.content}}} + {{#if data.text.content}} + {{{data.text.content}}} {{else}} - {{#if data.img}}{{/if}} + {{#if data.src}}{{/if}} {{/if}}