Fixed bug when moving items within combiner
This commit is contained in:
parent
3f147b9fee
commit
1baf5aba10
@ -196,6 +196,19 @@ class ItemList extends Phaser.Scene {
|
|||||||
|
|
||||||
addClickHandlers(vbox) {
|
addClickHandlers(vbox) {
|
||||||
const ws = this.registry.get('ws');
|
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) => {
|
this.input.on('dragstart', (pointer, item) => {
|
||||||
if (!(item instanceof Item)) return false;
|
if (!(item instanceof Item)) return false;
|
||||||
item.clickHandler();
|
item.clickHandler();
|
||||||
@ -214,21 +227,16 @@ class ItemList extends Phaser.Scene {
|
|||||||
if (!(item instanceof Item)) return false;
|
if (!(item instanceof Item)) return false;
|
||||||
item.deselect();
|
item.deselect();
|
||||||
const hitBox = itemCheckHitbox(this, pointer);
|
const hitBox = itemCheckHitbox(this, pointer);
|
||||||
|
deallocate(item);
|
||||||
if (hitBox) {
|
if (hitBox) {
|
||||||
hitBox.itemDeselect();
|
hitBox.itemDeselect();
|
||||||
if (hitBox instanceof CombinerHitBox) {
|
if (hitBox instanceof CombinerHitBox) {
|
||||||
console.log(`Moved ${item.item} into slot ${hitBox.slot}`);
|
|
||||||
hitBox.allocate(item);
|
hitBox.allocate(item);
|
||||||
this.combinerItems[hitBox.slot] = item.index;
|
this.combinerItems[hitBox.slot] = item.index;
|
||||||
console.log(this.combinerItems);
|
} else {
|
||||||
return true;
|
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;
|
return true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user