fix: qty update
This commit is contained in:
parent
493042b913
commit
92c85e57d3
|
@ -109,8 +109,9 @@ class ItemProxy {
|
|||
instance.clear(this.slot);
|
||||
}
|
||||
else {
|
||||
const difference = qty - instance.slots[this.slot].qty;
|
||||
instance.slots[this.slot].qty = qty;
|
||||
this.Component.markChange(instance.entity, 'qtyUpdated', {[this.slot]: qty});
|
||||
this.Component.markChange(instance.entity, 'qtyUpdated', {[this.slot]: difference});
|
||||
}
|
||||
}
|
||||
get source() {
|
||||
|
@ -138,7 +139,7 @@ export default class Inventory extends Component {
|
|||
}
|
||||
if (qtyUpdated) {
|
||||
for (const slot in qtyUpdated) {
|
||||
slots[slot].qty = qtyUpdated[slot];
|
||||
slots[slot].qty += qtyUpdated[slot];
|
||||
}
|
||||
}
|
||||
if (swapped) {
|
||||
|
@ -187,7 +188,7 @@ export default class Inventory extends Component {
|
|||
for (let slot = 1; slot < 11; ++slot) {
|
||||
if (slots[slot]?.source === stack.source) {
|
||||
slots[slot].qty += stack.qty;
|
||||
Component.markChange(this.entity, 'qtyUpdated', {[slot]: slots[slot].qty});
|
||||
Component.markChange(this.entity, 'qtyUpdated', {[slot]: stack.qty});
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -195,8 +196,8 @@ export default class Inventory extends Component {
|
|||
if (!slots[slot]) {
|
||||
slots[slot] = stack;
|
||||
this.$$items[slot] = new ItemProxy(Component, this, slot);
|
||||
await this.$$items[slot].load(stack.source);
|
||||
Component.markChange(this.entity, 'given', {[slot]: slots[slot]});
|
||||
await this.$$items[slot].load(stack.source);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -233,10 +234,6 @@ export default class Inventory extends Component {
|
|||
mergeDiff(original, update) {
|
||||
const merged = {
|
||||
...original,
|
||||
qtyUpdated: {
|
||||
...original.qtyUpdated,
|
||||
...update.qtyUpdated,
|
||||
},
|
||||
cleared: {
|
||||
...original.cleared,
|
||||
...update.cleared,
|
||||
|
@ -250,6 +247,14 @@ export default class Inventory extends Component {
|
|||
...(update.swapped || []),
|
||||
],
|
||||
};
|
||||
if (update.qtyUpdated) {
|
||||
if (!merged.qtyUpdated) {
|
||||
merged.qtyUpdated = {};
|
||||
}
|
||||
for (const slot in update.qtyUpdated) {
|
||||
merged.qtyUpdated[slot] = (merged.qtyUpdated[slot] ?? 0) + update.qtyUpdated[slot];
|
||||
}
|
||||
}
|
||||
return merged;
|
||||
}
|
||||
static properties = {
|
||||
|
|
Loading…
Reference in New Issue
Block a user