death-save / maestro

Audio-focused QOL module for Foundry Virtual Tabletop
GNU General Public License v3.0
18 stars 18 forks source link

Make the item ID retrievable from the roll #189

Open Stefouch opened 1 year ago

Stefouch commented 1 year ago

Is your feature request related to a problem? Please describe. Suggestion to add another generic way to get the item ID when a message is posted.

Describe the solution you'd like

message.rolls[0].options.itemId

Describe alternatives you've considered Maestro's documentation does not explain where to add the data-item-id attribute. Moreover, adding an extra attribute to the <li class="chat-message"> (supposedly where it should be added) is a complex process.

Additional context The solution proposed here is relatively easy as most game systems already reimplement the roll classes for their dice mechanics. A simple one-liner myRoll.options.itemId = item.id can be used.

A simple extra line in Maestro's code can do the trick: https://github.com/death-save/maestro/blob/5a66b986df92026a72ed735fb4ce819cb7c0964d/modules/item-track.js#L91

async _chatMessageHandler(message, html, data) {
        const enabled = game.settings.get(MAESTRO.MODULE_NAME, MAESTRO.SETTINGS_KEYS.ItemTrack.enable);

        if (!enabled || !isFirstGM()) return;

        const itemIdentifier = game.settings.get(MAESTRO.MODULE_NAME, MAESTRO.SETTINGS_KEYS.ItemTrack.itemIdAttribute);
        const itemCard = html.find(`[${itemIdentifier}]`);
        const trackPlayed = message.getFlag(MAESTRO.MODULE_NAME, MAESTRO.DEFAULT_CONFIG.ItemTrack.flagNames.played);

        if(!itemCard || itemCard.length === 0 || trackPlayed) {
            return;
        }

        let itemId = itemCard.attr(itemIdentifier);

        // Changed here:
        if (!itemId) itemId = message.rolls[0]?.options?.itemId;
        if (!itemId) return;
        // etc...
eclarke12 commented 1 year ago

The precedent for retrieving the item-id using <li class="chat-message"> was set by the dnd5e system however I understand not every system developer may choose to use that method.

I will try to keep this issue in mind for a future release.

Stefouch commented 5 months ago

Hi!

Any chance to have this single line added to the code to make our developper's life easier to support Maestro ?

Nevermind. I didn't see that Maestro was dead. I apologize !