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
* @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;
}

View File

@@ -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;
}
}

View File

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