kgar / foundry-vtt-tidy-5e-sheets

D&D 5e sheet layouts for Foundry VTT, focused on a clean UI, user ergonomics, and extensibility.
https://kgar.github.io/foundry-vtt-tidy-5e-sheets/
MIT License
42 stars 14 forks source link

bug: Similar consumables dropped into a container do not stack #827

Closed kgar closed 2 weeks ago

kgar commented 2 weeks ago

When dropping a potion of healing into a container, it does not stack with an existing potion of healing entry.

Update containers and the App V2 Tidy framework to handle this so that further sheets brought into App V2 will work as intended.

kgar commented 2 weeks ago

This is the code change that clued me into the issue on my sheets: https://github.com/foundryvtt/dnd5e/compare/release-4.0.4...release-4.1.0#diff-97c9784c2366bb6f9f0b308d2cc47f3971e354e7147530eaf7076af7f6b3d580R41

  _onDropStackConsumables(itemData, { container=null }={}) {
    const droppedSourceId = itemData._stats?.compendiumSource ?? itemData.flags.core?.sourceId;
    if ( itemData.type !== "consumable" || !droppedSourceId ) return null;
    const similarItem = this.actor.sourcedItems.get("Compendium.dnd5e.items.Item.ytlsBjYsZ7OBSEBs", { legacy: false })
      ?.filter(i => (i.system.container === container) && (i.name === itemData.name))?.first();

  // etc.
kgar commented 2 weeks ago

The default container calls the drop stack function like this:

  async _onDropSingleItem(itemData, { container, depth, event }) {
    if ( itemData.type === "spell" ) {
      const scroll = await Item5e.createScrollFromSpell(itemData);
      return scroll?.toObject?.() ?? false;
    }

    if ( this.item.actor && (container === this.item.id) ) {
      const result = await this.item.actor.sheet._onDropStackConsumables(itemData, { container });
      if ( result ) return false;
    }

    return itemData;
  }