consumables chat data

CCalego3/29/2022
@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.
CCalego3/29/2022
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.
UUUnknown User3/29/2022
Message Not Public
Sign In & Join Server To View
CCalego3/29/2022
not actually sure about that
CCalego3/29/2022
innnnteresting
CCalego3/29/2022
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);
CCalego3/29/2022
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
UUUnknown User3/29/2022
Message Not Public
Sign In & Join Server To View
CCalego3/29/2022
veeeerry interesting
UUUnknown User3/29/2022
Message Not Public
Sign In & Join Server To View
CCalego3/29/2022
creating and then deleting the item does feel kinda bad though
UUUnknown User3/29/2022
Message Not Public
Sign In & Join Server To View
CCalego3/29/2022
like why cause 3 database updates for something that should take 1
- create weapon
- create chat card
- delete weapon
UUUnknown User3/29/2022
Message Not Public
Sign In & Join Server To View
CCalego3/29/2022
for that I honestly think a new preparation mode "item" would solve like all the problems
UUUnknown User3/29/2022
Message Not Public
Sign In & Join Server To View
CCalego3/29/2022
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
CCalego3/29/2022
I remember Item5e#roll had issues with rolling an ephemeral item, but displayCard didn't
UUUnknown User3/29/2022
Message Not Public
Sign In & Join Server To View
CCalego3/29/2022
temporary
CCalego3/29/2022
i.e. a Document that doesn't exist in the database
UUUnknown User3/29/2022
Message Not Public
Sign In & Join Server To View
CCalego3/29/2022
Could change the DOM output too to remove the extra stuff like the chat card footer with item details.
CCalego3/29/2022
Hmmm. I might do this in concentration5e.

thanks @Zhell 🙂
LTLLLeo The League Lion3/29/2022
@Calego (ElfFriend) gave :vote: LeaguePoints™ to @Zhell (#217 • 2)
UUUnknown User3/29/2022
Message Not Public
Sign In & Join Server To View
CCalego3/29/2022
is msg the output of displayCard?
UUUnknown User3/29/2022
Message Not Public
Sign In & Join Server To View
CCalego3/29/2022
gotchya
CCalego3/29/2022
the output of displayCard({createMessage: false}) is all the data you'd need to pass into ChatMessage.create()
CCalego3/29/2022
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);
UUUnknown User3/29/2022
2 Messages Not Public
Sign In & Join Server To View
CCalego3/29/2022
I think it depends on the action present, refer to the _onChatCardAction method in Item5e
CCalego3/29/2022
for example if you're rolling an attack, the chatmessage needs all the data to make an item with an attack roll
CCalego3/29/2022
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)
UUUnknown User3/30/2022
5 Messages Not Public
Sign In & Join Server To View
CCalego3/30/2022
Lol amazing
CCalego3/30/2022
Next thing you'll tell me that both of you have made little modules to check if an attack roll his
UUUnknown User3/30/2022
5 Messages Not Public
Sign In & Join Server To View