From 1baf5aba1047c135f85f0e12399d5dfbe7ac21db Mon Sep 17 00:00:00 2001 From: Mashy Date: Mon, 18 Feb 2019 23:45:59 +1000 Subject: [PATCH] Fixed bug when moving items within combiner --- client/src/scenes/item.list.js | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/client/src/scenes/item.list.js b/client/src/scenes/item.list.js index 2aac1e55..dcbef077 100644 --- a/client/src/scenes/item.list.js +++ b/client/src/scenes/item.list.js @@ -196,6 +196,19 @@ class ItemList extends Phaser.Scene { addClickHandlers(vbox) { const ws = this.registry.get('ws'); + + const deallocate = (item) => { + const clearIndex = this.combinerItems.indexOf(item.index); + if (clearIndex !== -1) { + this.children.list.filter(obj => obj instanceof CombinerHitBox) + .forEach((cBox) => { + if (cBox.item === item) cBox.deallocate(); + }); + this.combinerItems[clearIndex] = -1; + } + item.setPosition(item.origX, item.origY); + }; + this.input.on('dragstart', (pointer, item) => { if (!(item instanceof Item)) return false; item.clickHandler(); @@ -214,21 +227,16 @@ class ItemList extends Phaser.Scene { if (!(item instanceof Item)) return false; item.deselect(); const hitBox = itemCheckHitbox(this, pointer); + deallocate(item); if (hitBox) { hitBox.itemDeselect(); if (hitBox instanceof CombinerHitBox) { - console.log(`Moved ${item.item} into slot ${hitBox.slot}`); hitBox.allocate(item); this.combinerItems[hitBox.slot] = item.index; - console.log(this.combinerItems); - return true; + } else { + ws.sendItemUse(vbox.find(li => li.action === item.action).id, hitBox.cryp.id); } - // else ws.sendItemUse(vbox.find(li => li.action === box.action).id, hitBox.cryp.id); } - const clearIndex = this.combinerItems.indexOf(item.index); - if (clearIndex !== -1) this.combinerItems[clearIndex] = -1; - item.setPosition(item.origX, item.origY); - console.log(this.combinerItems); return true; }); }