consumables chat data

@Zhell
So that's odd. How come consumables work different and all other item types get a non-functional save button when they no longer exist on the actor?
This is interesting and worth being in the history here. Only consumables have the assumption that they will need functional chat buttons after the item has been destroyed. As such they automatically put the item data into the chat message flags, and use that information when the buttons are interacted with.
C
Calego772d ago
Normally, it's expected that the item still exists on the actor that rolled the item. But since consumables have the "Destroy when empty" logic built in, they have the special handling built in.
Z
Zhell772d ago
And this is only consumables, and I'm guessing modifying a different item's chat message to contain the itemData as well will do nothing?
C
Calego772d ago
not actually sure about that
C
Calego772d ago
GitLab
module/item/entity.js · master · Foundry Network / Foundry VTT 5th ...
An implementation of the Dungeons & Dragons 5th Edition game system for Foundry Virtual Tabletop (http://foundryvtt.com). This work is permitted under the Open...
C
Calego772d ago
innnnteresting so looks like if there is itemData in the flags, it'll prefer that always
const item = storedData ? new this(storedData, {parent: actor}) : actor.items.get(card.dataset.itemId);
const item = storedData ? new this(storedData, {parent: actor}) : actor.items.get(card.dataset.itemId);
C
Calego772d ago
So in my wee concentration module, I could not use consumable for the card displayed to prompt for checks. I would need to create the chatcard myself though? Think so. the displayCard method only populates the itemData automatically for consumables. https://gitlab.com/foundrynet/dnd5e/-/blob/master/module/item/entity.js#L745
GitLab
module/item/entity.js · master · Foundry Network / Foundry VTT 5th ...
An implementation of the Dungeons & Dragons 5th Edition game system for Foundry Virtual Tabletop (http://foundryvtt.com). This work is permitted under the Open...
Z
Zhell772d ago
Just tried slapping a weapon (toObject()) into the same flag. It works.
C
Calego772d ago
veeeerry interesting
Z
Zhell772d ago
I.e., weapon with con save, roll it, update the message.content with 'flags.dnd5e.itemData': weapon.toObject(), then delete the weapon from the actor. Con save still works
C
Calego772d ago
creating and then deleting the item does feel kinda bad though
Z
Zhell772d ago
(and after refresh as well, just to make sure)
C
Calego772d ago
like why cause 3 database updates for something that should take 1 - create weapon - create chat card - delete weapon
Z
Zhell772d ago
This could be interesting for magic items with spells. 🤔
C
Calego772d ago
for that I honestly think a new preparation mode "item" would solve like all the problems
Z
Zhell772d ago
True but some don't like the clutter. Anyway, can't one just manually edit the message with the appropriate data before creating a chat card, no item needed?
C
Calego772d ago
Yeah true. I guess you could make a temporary item, call displayCard with createMessage: false in the args, then modify the output to include the data of the temporary item I remember Item5e#roll had issues with rolling an ephemeral item, but displayCard didn't
Z
Zhell772d ago
ephemeral?
C
Calego772d ago
temporary i.e. a Document that doesn't exist in the database
Z
Zhell772d ago
Right
C
Calego772d ago
Could change the DOM output too to remove the extra stuff like the chat card footer with item details. Hmmm. I might do this in concentration5e. thanks @Zhell 🙂
LTL
Leo The League Lion772d ago
@calego gave vote LeaguePoints™ to @Zhell (#217 • 2)
Z
Zhell772d ago
Something like ChatMessage.create(msg.toObject()) does work. 🤔 and that's not a lot of data tbh.
C
Calego772d ago
is msg the output of displayCard?
Z
Zhell772d ago
(where msg is a message that works...)
C
Calego772d ago
gotchya the output of displayCard({createMessage: false}) is all the data you'd need to pass into ChatMessage.create() so I envision something like this:
const fakeItem = new Item5e(someItemData, {temporary: true, parent: someActor});

const messageData = fakeItem.displayCard({createMessage: false});

messageData.flags['dnd5e.itemData'] = fakeItem.toObject();

ChatMessage.create(message);
const fakeItem = new Item5e(someItemData, {temporary: true, parent: someActor});

const messageData = fakeItem.displayCard({createMessage: false});

messageData.flags['dnd5e.itemData'] = fakeItem.toObject();

ChatMessage.create(message);
Z
Zhell772d ago
I wonder just how little data you need to do this. I'm gonna strip it down until it breaks.
C
Calego772d ago
I think it depends on the action present, refer to the _onChatCardAction method in Item5e for example if you're rolling an attack, the chatmessage needs all the data to make an item with an attack roll for a save though, it really only needs enough to make a valid item (name and type), since all the rest comes from the chat message DOM (for better or worse... bleh)
Z
Zhell772d ago
Item5e is undefined, and just Item doesn't have a displayCard function. >_>
const itemData = {data: {actionType: "save", save: {ability: 'con', dc: 20, scaling: 'flat'}}, name: "Steve", type: "loot"};
let fakeItem = new Item.implementation(itemData, {temporary: true, parent: token.actor});
let messageData = await fakeItem.displayCard({createMessage: false});
messageData.flags['dnd5e.itemData'] = fakeItem.toObject();
messageData.content = `<div class="dnd5e chat-card item-card" data-actor-id="stSaie8MWAdB4hUG">
<header class="card-header flexrow">
<img src="icons/svg/item-bag.svg" title="Steve" width="36" height="36"/>
<h3 class="item-name">Steve</h3>
</header>
<div class="card-content">
Text goes here.
</div>
<div class="card-buttons">
<button data-action="save" data-ability="con">
Saving Throw
</button>
</div>`;
ChatMessage.create(messageData);
const itemData = {data: {actionType: "save", save: {ability: 'con', dc: 20, scaling: 'flat'}}, name: "Steve", type: "loot"};
let fakeItem = new Item.implementation(itemData, {temporary: true, parent: token.actor});
let messageData = await fakeItem.displayCard({createMessage: false});
messageData.flags['dnd5e.itemData'] = fakeItem.toObject();
messageData.content = `<div class="dnd5e chat-card item-card" data-actor-id="stSaie8MWAdB4hUG">
<header class="card-header flexrow">
<img src="icons/svg/item-bag.svg" title="Steve" width="36" height="36"/>
<h3 class="item-name">Steve</h3>
</header>
<div class="card-content">
Text goes here.
</div>
<div class="card-buttons">
<button data-action="save" data-ability="con">
Saving Throw
</button>
</div>`;
ChatMessage.create(messageData);
🥳 Got rid of the footer in a messy way but eh
Z
Zhell772d ago
No description
K
kaelad772d ago
Man, are we all writing our own concentrators? I do the same trick with mine, creating a temporary item then adding it to the chat message's flag so the saving throw button works. https://github.com/kaelad02/concentrator/blob/main/src/concentrator.js#L252
GitHub
concentrator/concentrator.js at main · kaelad02/concentrator
Foundry module to manage concentration. Contribute to kaelad02/concentrator development by creating an account on GitHub.
C
Calego772d ago
Lol amazing Next thing you'll tell me that both of you have made little modules to check if an attack roll his
K
kaelad772d ago
Not yet
K
kaelad772d ago
The only other unpublished module I have adds two features onto Convenient Effects: 1. Auto apply Dead, Unconscious, and Wounded status 2. Add a button on item cards to "Add Convenient Effect" if you use a feature that has a matching convenient effect https://github.com/kaelad02/convenient-effects-ext
GitHub
GitHub - kaelad02/convenient-effects-ext: Foundry module that adds ...
Foundry module that adds some extensions to the CE module - GitHub - kaelad02/convenient-effects-ext: Foundry module that adds some extensions to the CE module
Z
Zhell772d ago
I'm told this means we have to duel at noon...? 🤔 I have thought about it... 😬 Definitely just a DM-only script though.
K
kaelad772d ago
I immediately started humming this: https://youtu.be/PYI09PMNazw
Cinema Hotel Studios
YouTube
The Ecstasy of Gold - Ennio Morricone ( The Good, the Bad and the U...
"The Ecstasy of Gold" (Italian title "L' Estasi dell'Oro"), is one of the Western compositions that most represent the genius of Ennio Morricone. Composed for the movie: "The Good, The Bad and The Ugly", directed by Sergio Leone, the Western theme simply became one of the most iconic music masterpiece in Cinema's history. The legendary music of ...
Want results from more Discord servers?
Add your server
More Posts
ilthid stop dragActually, would it be possible to modify the core function that allows people to click and drag toke1.6.x mid-milestone update@dnd5e - **No Action Required** Milestone 1.6.0 is 69% Complete (_nice_) <https://gitlab.com/foundPlugin ContributorsI'm very proud to be the maintainer of a module (Export Sheet to PDF) that is getting many, many conmore-hooks-itemroll-hooksFor those of you interested in such things, I have hacked together a way to inject hooks into the mipreHooks5eJSON.stringify jankI discovered that the problem is JSON.stringify, not parselayersTIL about CSS Layers. https://developer.mozilla.org/en-US/docs/Web/CSS/@layer ```css @layer utilitiHitDice hooks MRI just added my first merge request 😄 <https://gitlab.com/foundrynet/dnd5e/-/merge_requests/495>advantage shennaneginsdevmode extension brainstormhttps://github.com/mdn/webextensions-examples/tree/master/devtools-panelsSaving Functions as module settings@wasp I remember you asked about saving functions as settings (which quickly turned into stringifyinnew consumable typesTried adding localization strings for some new consumable types, but keep getting this ("`DND5E.Consspell-compendium-5e alpha1Overriding onDropItem & onSortItemYou'd override them in your sheet class.getter & setter wrapper for settingsI'm trying to use a getter & setter pair as an interface for `game.settings.get` and `game.settings.scrollable tab contentsIt is possible, and you're firmly in the css and DOM structure side of development with this line ofJr devI'm cleaning out my bookmarks and accidentally came back to this article. Potentially useful startinHTCPackage: `hero-creation-tool`System Specific CSSI'm not 100% about this, but it is worth watching out that your solution doesn't actually end up beiadvancement-wip