refactor: targeted receptacle events

This commit is contained in:
cha0s 2019-10-15 02:15:47 -05:00
parent 5af4fcf6a5
commit 727e29a99c

View File

@ -229,6 +229,7 @@ export class Receptacle extends decorate(Trait) {
else { else {
this.addListenersForItem(item); this.addListenersForItem(item);
this.slotItems[slotIndex] = item; this.slotItems[slotIndex] = item;
this.entity.emit('itemAdded', item, slotIndex);
if (AVOCADO_SERVER) { if (AVOCADO_SERVER) {
this.packetUpdates.push(new TraitUpdateReceptacleItemFullPacket({ this.packetUpdates.push(new TraitUpdateReceptacleItemFullPacket({
slotIndex, slotIndex,
@ -247,6 +248,7 @@ export class Receptacle extends decorate(Trait) {
} }
this.removeListenersForItem(item); this.removeListenersForItem(item);
delete this.slotItems[slotIndex]; delete this.slotItems[slotIndex];
this.entity.emit('itemRemoved', item, slotIndex);
if (AVOCADO_SERVER) { if (AVOCADO_SERVER) {
this.packetUpdates.push(new TraitUpdateReceptacleItemSwapPacket({ this.packetUpdates.push(new TraitUpdateReceptacleItemSwapPacket({
firstSlotIndex: slotIndex, firstSlotIndex: slotIndex,
@ -282,6 +284,13 @@ export class Receptacle extends decorate(Trait) {
this.slotItems[rightIndex] = leftItem; this.slotItems[rightIndex] = leftItem;
this.addListenersForItem(leftItem); this.addListenersForItem(leftItem);
this.addListenersForItem(rightItem); this.addListenersForItem(rightItem);
this.entity.emit(
'itemsSwapped',
leftIndex,
rightIndex,
leftItem,
rightItem
);
}, },
}; };