From 0cdabd0858e3d9539e4d7b7899a13d18c28ca72b Mon Sep 17 00:00:00 2001 From: cha0s Date: Sun, 29 Sep 2024 06:32:06 -0500 Subject: [PATCH] refactor: distribution --- app/ecs/components/inventory.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/app/ecs/components/inventory.js b/app/ecs/components/inventory.js index e7c7c8f..8967768 100644 --- a/app/ecs/components/inventory.js +++ b/app/ecs/components/inventory.js @@ -208,18 +208,25 @@ export default class Inventory extends Component { } } const {qty} = slots[slot]; - slots[slot].qty = 0; + slots[slot].qty -= qty; for (let i = 0; i < qty; ++i) { const [entityId, destination] = destinations[i % destinations.length]; const {Inventory} = ecs.get(entityId); const {slots} = Inventory; slots[destination].qty += 1; } - if (!destinations.find(([entityId, destination]) => { - return entityId == this.entity && destination === slot; - })) { + if (0 === slots[slot].qty) { this.clear(slot); } + else { + if ( + !destinations.find(([entityId, destination]) => { + return entityId == this.entity && destination === slot; + }) + ) { + Component.markChange(this.entity, 'qtyUpdated', {[slot]: -qty}); + } + } for (const [entityId, destination] of given) { const {Inventory} = ecs.get(entityId); const {slots} = Inventory;