Added Send to chat to JournalEntry

This commit is contained in:
Vlyan
2021-08-03 18:30:31 +02:00
parent b2afa334a0
commit 0116497921
7 changed files with 81 additions and 30 deletions

View File

@@ -1,7 +1,7 @@
# Changelog
## 1.3.3 - TODO
- Added "send to chat" button on items sheets.
- Added "send to chat" header button on Item and Journal sheets.
- Added Opportunity usage helper Compendium.
- Fixed Compendium entries thanks to TesserWract :
- Utaku Battle Maiden: Replace "Striking as Air" with "Courtier's Resolve".

View File

@@ -42,7 +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.",
"send_to_chat": "Env. dans la conv.",
"edge_translation_disclaimer": ""
},
"logo": {

View File

@@ -483,4 +483,29 @@ export class HelpersL5r5e {
}
return item;
}
/**
* Send the description of this Item to chat
* @param {JournalL5r5e|ItemSheetL5r5e} object
* @return {Promise<*>}
*/
static async sendToChat(object) {
const tpl = await object.renderTextTemplate();
if (!tpl) {
return;
}
let link = null;
if (object.data.flags.core?.sourceId) {
link = object.data.flags.core?.sourceId.replace(/(\w+)\.(.+)/, "@$1[$2]");
} else if (object.pack) {
link = `@Compendium[${object.pack}.${object.id}]{${object.name}}`;
} else if (!object.actor) {
link = object.link;
}
return ChatMessage.create({
content: (link ? link + `<br>` : "") + tpl,
});
}
}

View File

@@ -24,38 +24,14 @@ export class ItemSheetL5r5e extends ItemSheet {
// Send To Chat
buttons.unshift({
label: game.i18n.localize("l5r5e.global.send_to_chat"),
class: "twenty-questions",
class: "send-to-chat",
icon: "fas fa-comment-dots",
onclick: async () => this.sendToChat(),
onclick: async () => game.l5r5e.HelpersL5r5e.sendToChat(this.object),
});
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 + `<br>` : "") + tpl,
});
}
/**
* @return {Object|Promise}
*/

View File

@@ -1,4 +1,16 @@
/**
* Extends the JournalEntity to process special things from L5R.
*/
export class JournalL5r5e extends JournalEntry {}
export class JournalL5r5e extends JournalEntry {
/**
* Render the text template for this Journal (tooltips and chat)
* @return {Promise<string|null>}
*/
async renderTextTemplate() {
const tpl = await renderTemplate(`${CONFIG.l5r5e.paths.templates}journal/journal-text.html`, this);
if (!tpl) {
return null;
}
return tpl;
}
}

View File

@@ -3,6 +3,35 @@
* @extends {JournalSheet}
*/
export class BaseJournalSheetL5r5e extends JournalSheet {
// /** @override */
// static get defaultOptions() {
// return foundry.utils.mergeObject(super.defaultOptions, {
// classes: ["l5r5e", "sheet", "journal"], // app window-app sheet journal-sheet
// template: CONFIG.l5r5e.paths.templates + "journal/journal-sheet.html",
// width: 520,
// height: 480,
// tabs: [{ navSelector: ".journal-tabs", contentSelector: ".journal-body", initial: "description" }],
// });
// }
/**
* 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: "send-to-chat",
icon: "fas fa-comment-dots",
onclick: async () => game.l5r5e.HelpersL5r5e.sendToChat(this.object),
});
return buttons;
}
/**
* Activate a named TinyMCE text editor
* @param {string} name The named data field which the editor modifies.
@@ -25,7 +54,6 @@ export class BaseJournalSheetL5r5e extends JournalSheet {
* @override
*/
async _updateObject(event, formData) {
// event.type = mcesave / submit
if (formData.content) {
formData.content = game.l5r5e.HelpersL5r5e.convertSymbols(formData.content, true);
}

View File

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