refactor: separate recptacle item loading
This commit is contained in:
parent
754fde14b5
commit
138de578ab
|
@ -47,11 +47,9 @@ export class Receptacle extends decorate(Trait) {
|
|||
// Load items.
|
||||
for (const index in this.params.slots) {
|
||||
const slotSpec = this.params.slots[index];
|
||||
this.slotItems[index] = Entity.load(slotSpec.uri).then((item) => {
|
||||
Entity.load(slotSpec.uri).then((item) => {
|
||||
// Set quantity.
|
||||
item.qty = slotSpec.qty;
|
||||
// Set wielder.
|
||||
item.wielder = this.entity;
|
||||
// Hydrate the item before adding it to the inventory.
|
||||
return item.hydrate().then(() => {
|
||||
this.entity.addItemToSlot(item, index);
|
||||
|
@ -196,9 +194,7 @@ export class Receptacle extends decorate(Trait) {
|
|||
|
||||
toNetwork(informed) {
|
||||
const json = this.toJSON();
|
||||
if (informed !== this.entity) {
|
||||
json.params.slots = {};
|
||||
}
|
||||
return json;
|
||||
}
|
||||
|
||||
|
@ -226,6 +222,8 @@ export class Receptacle extends decorate(Trait) {
|
|||
return this.mergeItem(item);
|
||||
}
|
||||
else {
|
||||
// Set wielder.
|
||||
item.wielder = this.entity;
|
||||
this.addListenersForItem(item);
|
||||
this.slotItems[slotIndex] = item;
|
||||
this.entity.emit('itemAdded', item, slotIndex);
|
||||
|
|
Loading…
Reference in New Issue
Block a user