Fixed bug when moving items within combiner

This commit is contained in:
Mashy 2019-02-18 23:45:59 +10:00
parent 3f147b9fee
commit 1baf5aba10

View File

@ -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;
});
}