shemetz / roll-from-compendium

FoundryVTT module that adds easy buttons to post things to chat.
MIT License
5 stars 2 forks source link

API call #9

Closed Ikabodo closed 3 years ago

Ikabodo commented 3 years ago

I've come to really love the use of "show in chat" with journals. Is there a way to call the function in a macro?

shemetz commented 3 years ago

I haven't exported the API of the module. I could do that, but I think it'll be easier for you to just create a macro of your own.

I wrote some code for you:

async function showJournalEntry (journalEntryName) {
  const item = game.journal.getName(journalEntryName)
  const img = item.img || item.data.img || 'icons/svg/book.svg'
  const content =
    `<div class="${game.system.id} chat-card item-card">
          <header class="card-header flexrow">
          <img src="${img}" width="36" height="36"/>
          <h3 class="item-name">${item.name}</h3>
          </header>
      </div>
      ${item.data.content}
    `
  return await ChatMessage.create({ content })
}

This function will basically do exactly what this module does, given an input journal name.

Once you have this (copied into the macro or called through a different macro or added to your personal module?), you can have a macro include something like this: showJournalEntry('test entry 1')

image

This is identical to the 'Show in Chat' option this module adds, except the icon should fit a little bit better.

Does that help?

Ikabodo commented 3 years ago

That is beyond helpful. Thank for going above and beyond for this question.