Skip to content

Commit

Permalink
Fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
Haxxer committed Oct 19, 2023
1 parent b2252fd commit b77ef83
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,11 @@
.map(item => {
return {
_id: item.id,
quantity: settings.getUpdates && item.quantity ? Math.min(item.quantity, item.currentQuantity - item.quantity) : item.currentQuantity
quantity: settings.getUpdates && item.quantity
? item.currentQuantity - item.quantity
: item.currentQuantity
}
})
});
const itemsToCreate = items
.filter(item => item.currentQuantity && item.create)
Expand Down
7 changes: 7 additions & 0 deletions src/helpers/compendium-utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,10 @@ export async function findOrCreateItemInCompendium(itemData) {
COMPENDIUM_CACHE[compendiumItem.uuid] = itemData;
return compendiumItem;
}

export function findSimilarItemInCompendiumSync(itemToFind) {
return Object.values(COMPENDIUM_CACHE).find(compendiumItem => {
return compendiumItem.name === itemToFind.name
&& compendiumItem.type === itemToFind.type;
}) ?? false;
}
12 changes: 8 additions & 4 deletions src/stores/pile-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import CONSTANTS from "../constants/constants.js";
import * as Helpers from "../helpers/helpers.js";
import { Plugins } from "../plugins/main.js";
import { SYSTEMS } from "../systems.js";
import * as CompendiumUtilities from "../helpers/compendium-utilities.js";
import { findSimilarItemInCompendiumSync } from "../helpers/compendium-utilities.js";

class PileBaseItem {

Expand Down Expand Up @@ -63,8 +65,9 @@ export class PileItem extends PileBaseItem {
this.currentQuantity.set(Math.min(get(this.currentQuantity), get(this.quantityLeft), get(this.quantity)));
this.id = this.item.id;
this.type = this.item.type;
this.name = writable(this.item.name);
this.img = writable(this.item.img);
const itemData = CompendiumUtilities.findSimilarItemInCompendiumSync(this.item);
this.name = writable(itemData?.name ?? this.item.name);
this.img = writable(itemData?.img ?? this.item.img);
this.abbreviation = writable("");
this.identifier = randomID();
this.itemFlagData = writable(PileUtilities.getItemFlagData(this.item));
Expand All @@ -91,8 +94,9 @@ export class PileItem extends PileBaseItem {

this.subscribeTo(this.itemDocument, () => {
const { data } = this.itemDocument.updateOptions;
this.name.set(this.item.name);
this.img.set(this.item.img);
const itemData = CompendiumUtilities.findSimilarItemInCompendiumSync(this.item);
this.name = writable(itemData?.name ?? this.item.name);
this.img = writable(itemData?.img ?? this.item.img);
this.similarities = Utilities.setSimilarityProperties({}, this.item);
if (PileUtilities.canItemStack(this.item, this.store.actor) && Utilities.hasItemQuantity(data)) {
this.quantity.set(Utilities.getItemQuantity(data));
Expand Down

0 comments on commit b77ef83

Please sign in to comment.