Working on Compatibility for FVTT v10

SendToChat : Fix Journal behaviour
This commit is contained in:
Vlyan
2022-07-23 21:59:13 +02:00
parent 096429d2f8
commit e7bd9ea3fb
3 changed files with 32 additions and 18 deletions

View File

@@ -597,32 +597,37 @@ export class HelpersL5r5e {
/** /**
* Send the description of this Item to chat * Send the description of this Item to chat
* @param {JournalL5r5e|ItemSheetL5r5e} object * @param {JournalL5r5e|ItemL5r5e} document
* @return {Promise<*>} * @return {Promise<*>}
*/ */
static async sendToChat(object) { static async sendToChat(document) {
// Get the html // Get the html
const tpl = await object.renderTextTemplate(); const tpl = await document.renderTextTemplate();
if (!tpl) { if (!tpl) {
return; return;
} }
// Get the JournalEntryPage instead of JournalEntry
if (document.documentName === "JournalEntry") {
document = document.getCurrentPage();
}
// Create the link // Create the link
let link = null; let link = null;
if (object.flags.core?.sourceId) { if (document.flags.core?.sourceId) {
link = object.flags.core?.sourceId.replace(/(\w+)\.(.+)/, "@$1[$2]"); link = document.flags.core?.sourceId.replace(/(\w+)\.(.+)/, "@$1[$2]");
if (!HelpersL5r5e.isLinkValid(link)) { if (!HelpersL5r5e.isLinkValid(link)) {
link = null; link = null;
} }
} }
if (!link && object.pack) { if (!link && document.pack) {
link = `@Compendium[${object.pack}.${object.id}]{${object.name}}`; link = `@Compendium[${document.pack}.${document.id}]{${document.name}}`;
if (!HelpersL5r5e.isLinkValid(link)) { if (!HelpersL5r5e.isLinkValid(link)) {
link = null; link = null;
} }
} }
if (!link && !object.actor) { if (!link && !document.actor) {
link = object.link; link = document.link;
if (!HelpersL5r5e.isLinkValid(link)) { if (!HelpersL5r5e.isLinkValid(link)) {
link = null; link = null;
} }

View File

@@ -8,10 +8,19 @@ export class JournalL5r5e extends JournalEntry {
*/ */
async renderTextTemplate() { async renderTextTemplate() {
const data = (await this.sheet?.getData()) || this; const data = (await this.sheet?.getData()) || this;
const tpl = await renderTemplate(`${CONFIG.l5r5e.paths.templates}journal/journal-text.html`, data); const pageData = data.pages[0];
if (!tpl) {
return null; const tpl = await renderTemplate(`${CONFIG.l5r5e.paths.templates}journal/journal-text.html`, {
data: pageData,
});
return tpl || null;
} }
return tpl;
/**
* Return the Current JournalEntryPage
* @return JournalEntryPage
*/
getCurrentPage() {
return Array.from(this.pages)[this.sheet?.pageIndex || 0] || null;
} }
} }

View File

@@ -1,15 +1,15 @@
<div class="{{cssClass}}" data-actor-id="{{actor._id}}" data-item-id="{{data._id}}"> <div class="{{cssClass}}" data-actor-id="{{actor._id}}" data-item-id="{{data._id}}">
<header class="card-header"> <header class="card-header">
<h2 class="item-name"> <h2 class="item-name">
{{#ifCond data.img '&&' data.content}}<img src="{{data.img}}" title="{{data.name}}" />{{/ifCond}} {{data.name}} {{#ifCond data.src '&&' data.text.content}}<img src="{{data.src}}" title="{{data.name}}" />{{/ifCond}} {{data.name}}
</h2> </h2>
</header> </header>
<section class="sheet-body"> <section class="sheet-body">
<p> <p>
{{#if data.content}} {{#if data.text.content}}
{{{data.content}}} {{{data.text.content}}}
{{else}} {{else}}
{{#if data.img}}<img src="{{data.img}}" title="{{data.name}}" />{{/if}} {{#if data.src}}<img src="{{data.src}}" title="{{data.name}}" />{{/if}}
{{/if}} {{/if}}
</p> </p>
</section> </section>