Skip to content
This repository was archived by the owner on Sep 18, 2024. It is now read-only.
This repository was archived by the owner on Sep 18, 2024. It is now read-only.

Make the item ID retrievable from the roll #189

@Stefouch

Description

@Stefouch

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
  • When a message is used, it's usually because it's rolled.
  • .rolls is an array (since V10), but extremely immensely rarely has >1 roll, so index [0].
  • roll.options is where roll options/custom data are preserved in Foundry's database.
  • options.itemId is the ID of the item used for the roll, added by the game system.

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:

async _chatMessageHandler(message, html, data) {

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...

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions