Post to chat pour les acteurs

This commit is contained in:
Vincent Vandemeulebrouck 2022-12-29 02:25:45 +01:00
parent 26808d7b49
commit c79298b60a
10 changed files with 76 additions and 24 deletions

View File

@ -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')

View File

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

View File

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

View File

@ -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)

View File

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

View File

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

View File

@ -1,6 +1,14 @@
{{#if pack}}
{{!-- draggable="true" --}}
<a class="content-link" data-pack="{{pack}}" data-uuid="Compendium.{{pack}}.{{id}}" data-id="{{id}}"><i class="fas fa-suitcase"></i>{{name}}</a>
<a class="content-link"
data-uuid="Compendium.{{pack}}.{{id}}"
data-pack="{{pack}}"
{{#if doctype}}data-doctype="{{doctype}}"{{/if}}
data-id="{{id}}"
><i class="fas fa-suitcase"></i>{{name}}</a>
{{else}}
<a class="rdd-world-content-link" data-id="{{id}}"><i class="fas fa-suitcase"></i>{{name}}</a>
<a class="rdd-world-content-link"
{{#if doctype}}data-doctype="{{doctype}}"{{/if}}
data-id="{{id}}"
><i class="fas fa-suitcase"></i>{{name}}</a>
{{/if}}

View File

@ -0,0 +1,7 @@
<div class="post-item">
{{#if img}}
<img class="chat-icon" src="{{img}}" title="{{name}}" />
{{/if}}
<p>{{> 'systems/foundryvtt-reve-de-dragon/templates/common/compendium-link.hbs' pack=pack id=id name=name doctype=doctype}}</p>
<p class="card-content">{{{system.description}}}</p>
</div>

View File

@ -1,8 +1,8 @@
<div class="post-item" data-transfer="{{transfer}}">
<div class="post-item">
{{#if img}}
<img class="chat-icon" src="{{img}}" title="{{name}}" />
{{/if}}
<p>{{> 'systems/foundryvtt-reve-de-dragon/templates/common/compendium-link.hbs' pack=pack id=_id name=name}}</p>
<p>{{> 'systems/foundryvtt-reve-de-dragon/templates/common/compendium-link.hbs' pack=pack id=id name=name docType=docType}}</p>
<p class="card-content">{{{system.description}}}</p>
</div>

View File

@ -1,4 +1,4 @@
<div class="post-item" data-transfer="{{transfer}}">
<div class="post-item">
<h3><b>{{name}}</b></h3>
{{#if img}}
<img class="chat-icon" src="{{img}}" title="{{name}}" />
@ -10,5 +10,4 @@
<span>{{{property}}}</span><br>
{{/each}}
</p>
</div>