KageJittai / lets-trade-5e

A Foundry VTT module which allows you to send and receive items from other players.
MIT License
11 stars 14 forks source link

Add Context Menu support to DND5e 2.1.2 #41

Closed szefo09 closed 1 year ago

szefo09 commented 1 year ago

Hi! In DND5e System 2.12 there is a right click context menu on items. I would like to ask You to add a Let's Trade button to the context menu. I've drafted a code that should work, if added to Hook.once("setup") in L12 here, but feel free to implement it however You think is best!

https://github.com/KageJittai/lets-trade-5e/blob/fae2a058ab17ec2f511bf0dcfc7e3614ba7d4df2/src/main.js#L8-L12

Hooks.on("dnd5e.getItemContextOptions", (item, contextOptions)=>{
 if (item.actor?.isOwner && !['feat','background','class','subclass','spell'].includes(item.type)) {
    contextOptions.push({
        name: `${game.i18n.localize("LetsTrade5E.Send")}`,
        icon: `<i class="fas fa-balance-scale-right"></i>`,
        callback: ()=>{openItemTrade(item.actor.id, item.id)}
        })
    }
});

This should also work with upcoming update to Tidy5e Sheet for 2.1, however Tidy5e has a compatibility change from ul. to ol. here: https://github.com/KageJittai/lets-trade-5e/blob/fae2a058ab17ec2f511bf0dcfc7e3614ba7d4df2/src/compatibility.js#L19 image