refactor: separate recptacle item loading

This commit is contained in:
cha0s 2019-11-03 22:17:45 -06:00
parent 754fde14b5
commit 138de578ab

View File

@ -47,11 +47,9 @@ export class Receptacle extends decorate(Trait) {
// Load items. // Load items.
for (const index in this.params.slots) { for (const index in this.params.slots) {
const slotSpec = this.params.slots[index]; const slotSpec = this.params.slots[index];
this.slotItems[index] = Entity.load(slotSpec.uri).then((item) => { Entity.load(slotSpec.uri).then((item) => {
// Set quantity. // Set quantity.
item.qty = slotSpec.qty; item.qty = slotSpec.qty;
// Set wielder.
item.wielder = this.entity;
// Hydrate the item before adding it to the inventory. // Hydrate the item before adding it to the inventory.
return item.hydrate().then(() => { return item.hydrate().then(() => {
this.entity.addItemToSlot(item, index); this.entity.addItemToSlot(item, index);
@ -196,9 +194,7 @@ export class Receptacle extends decorate(Trait) {
toNetwork(informed) { toNetwork(informed) {
const json = this.toJSON(); const json = this.toJSON();
if (informed !== this.entity) { json.params.slots = {};
json.params.slots = {};
}
return json; return json;
} }
@ -226,6 +222,8 @@ export class Receptacle extends decorate(Trait) {
return this.mergeItem(item); return this.mergeItem(item);
} }
else { else {
// Set wielder.
item.wielder = this.entity;
this.addListenersForItem(item); this.addListenersForItem(item);
this.slotItems[slotIndex] = item; this.slotItems[slotIndex] = item;
this.entity.emit('itemAdded', item, slotIndex); this.entity.emit('itemAdded', item, slotIndex);