diff --git a/module/actor/base-actor-sheet.js b/module/actor/base-actor-sheet.js index ecf23013..98cd8650 100644 --- a/module/actor/base-actor-sheet.js +++ b/module/actor/base-actor-sheet.js @@ -142,7 +142,8 @@ export class RdDBaseActorSheet extends ActorSheet { this.render(true); }); this.html.find('.item-edit').click(async event => RdDSheetUtility.getItem(event, this.actor)?.sheet.render(true)) - this.html.find('.item-montrer').click(async event => RdDSheetUtility.getItem(event, this.actor)?.postItem()); + this.html.find('.item-montrer').click(async event => RdDSheetUtility.getItem(event, this.actor)?.postItemToChat()); + this.html.find('.actor-montrer').click(async event => this.actor.postActorToChat()); // Everything below here is only needed if the sheet is editable if (!this.options.editable) return; @@ -169,6 +170,18 @@ export class RdDBaseActorSheet extends ActorSheet { } + + /* -------------------------------------------- */ + _getHeaderButtons() { + let buttons = super._getHeaderButtons(); + buttons.unshift({ + class: "montrer", + icon: "fas fa-comment", + onclick: ev => this.actor.postActorToChat() + }); + return buttons + } + /* -------------------------------------------- */ async _onDropItem(event, dragData) { const destItemId = this.html.find(event.target)?.closest('.item').attr('data-item-id') diff --git a/module/actor/base-actor.js b/module/actor/base-actor.js index 7b1e7935..b95a7ff5 100644 --- a/module/actor/base-actor.js +++ b/module/actor/base-actor.js @@ -1,6 +1,7 @@ import { SYSTEM_SOCKET_ID } from "../constants.js"; import { Monnaie } from "../item-monnaie.js"; import { Misc } from "../misc.js"; +import { RdDUtility } from "../rdd-utility.js"; import { SystemCompendiums } from "../settings/system-compendiums.js"; export class RdDBaseActor extends Actor { @@ -146,4 +147,21 @@ export class RdDBaseActor extends Actor { canReceive(item) { return false; } + + /* -------------------------------------------- */ + async postActorToChat(modeOverride) { + let chatData = { + doctype: 'Actor', + id: this.id, + type: this.type, + img: this.img, + pack: this.pack, + name: this.name, + system: { description: this.system.description } + } + renderTemplate('systems/foundryvtt-reve-de-dragon/templates/post-actor.html', chatData) + .then(html => ChatMessage.create(RdDUtility.chatDataSetup(html, modeOverride))); + } + + } \ No newline at end of file diff --git a/module/item-sheet.js b/module/item-sheet.js index 27c1ebb8..11b742cb 100644 --- a/module/item-sheet.js +++ b/module/item-sheet.js @@ -66,7 +66,7 @@ export class RdDItemSheet extends ItemSheet { buttons.unshift({ class: "montrer", icon: "fas fa-comment", - onclick: ev => this.item.postItem() + onclick: ev => this.item.postItemToChat() }); return buttons } @@ -211,7 +211,7 @@ export class RdDItemSheet extends ItemSheet { this.html.find('.item-edit').click(async event => RdDSheetUtility.getItem(event, this.actor)?.sheet.render(true)); this.html.find('.item-delete').click(async event => RdDUtility.confirmActorItemDelete(this, RdDSheetUtility.getItem(event, this.actor))); this.html.find('.item-vendre').click(async event => RdDSheetUtility.getItem(event, this.actor)?.proposerVente()); - this.html.find('.item-montrer').click(async event => RdDSheetUtility.getItem(event, this.actor)?.postItem()); + this.html.find('.item-montrer').click(async event => RdDSheetUtility.getItem(event, this.actor)?.postItemToChat()); this.html.find('.item-action').click(async event => RdDSheetUtility.getItem(event, this.actor)?.actionPrincipale(this.actor, async () => this.render(true))); } diff --git a/module/item.js b/module/item.js index 7bcbeda6..95fadacf 100644 --- a/module/item.js +++ b/module/item.js @@ -455,20 +455,19 @@ export class RdDItem extends Item { } /* -------------------------------------------- */ - async postItem(modeOverride) { + async postItemToChat(modeOverride) { console.log(this); - let chatData = duplicate(this); - chatData["properties"] = this.getProprietes(); - if (this.actor) { - chatData.actor = { id: this.actor.id }; + let chatData = { + doctype: 'Item', + id: this.id, + type: this.type, + img: this.img, + pack: this.pack, + name: this.name, + actor : this.actor ? { id: this.actor.id } : undefined, + system: { description: this.system.description }, + properties: this.getProprietes(), } - // JSON object for easy creation - chatData.jsondata = JSON.stringify( - { - compendium: "postedItem", - payload: chatData, - }); - renderTemplate(this.getChatItemTemplate(), chatData).then(html => { let chatOptions = RdDUtility.chatDataSetup(html, modeOverride); ChatMessage.create(chatOptions) diff --git a/module/rdd-calendrier.js b/module/rdd-calendrier.js index 2c1e134b..3a2e7d41 100644 --- a/module/rdd-calendrier.js +++ b/module/rdd-calendrier.js @@ -351,7 +351,7 @@ export class RdDCalendrier extends Application { ChatMessage.create({ content: `${actor.name} souffre d'un mal inconnu (${maladie.type}): vérifiez que les effets ne se sont pas aggravés !` }); } let itemMaladie = actor.getItem(maladie.id) - itemMaladie.postItem( 'gmroll'); + itemMaladie.postItemToChat('gmroll'); } } } diff --git a/module/rdd-utility.js b/module/rdd-utility.js index a8150ef0..98d210fe 100644 --- a/module/rdd-utility.js +++ b/module/rdd-utility.js @@ -783,8 +783,16 @@ export class RdDUtility { } }); html.on("click", '.rdd-world-content-link', async event => { - const itemId = html.find(event.currentTarget)?.data("id"); - game.items.get(itemId)?.sheet.render(true) + const htmlElement = html.find(event.currentTarget); + const id = htmlElement?.data("id"); + const doctype= htmlElement?.data("doctype"); + switch (doctype ?? 'Item') { + case 'Actor': + return game.actors.get(id)?.sheet.render(true); + case 'Item': + default: + return game.items.get(id)?.sheet.render(true); + } }); } diff --git a/templates/common/compendium-link.hbs b/templates/common/compendium-link.hbs index 5b4a1af9..905a04b5 100644 --- a/templates/common/compendium-link.hbs +++ b/templates/common/compendium-link.hbs @@ -1,6 +1,14 @@ {{#if pack}} {{!-- draggable="true" --}} -{{name}} +{{name}} {{else}} -{{name}} +{{name}} {{/if}} diff --git a/templates/post-actor.html b/templates/post-actor.html new file mode 100644 index 00000000..fd2cc702 --- /dev/null +++ b/templates/post-actor.html @@ -0,0 +1,7 @@ +
+ {{#if img}} + + {{/if}} +

{{> 'systems/foundryvtt-reve-de-dragon/templates/common/compendium-link.hbs' pack=pack id=id name=name doctype=doctype}}

+

{{{system.description}}}

+
diff --git a/templates/post-item-service.html b/templates/post-item-service.html index 4073de14..73c6b1c9 100644 --- a/templates/post-item-service.html +++ b/templates/post-item-service.html @@ -1,8 +1,8 @@ -
+
{{#if img}} {{/if}} -

{{> 'systems/foundryvtt-reve-de-dragon/templates/common/compendium-link.hbs' pack=pack id=_id name=name}}

+

{{> 'systems/foundryvtt-reve-de-dragon/templates/common/compendium-link.hbs' pack=pack id=id name=name docType=docType}}

{{{system.description}}}

diff --git a/templates/post-item.html b/templates/post-item.html index 380dcdcc..67be2ee3 100644 --- a/templates/post-item.html +++ b/templates/post-item.html @@ -1,4 +1,4 @@ -
+

{{name}}

{{#if img}} @@ -10,5 +10,4 @@ {{{property}}}
{{/each}}

-