refactor: Q+D proxy
This commit is contained in:
parent
0c06dd7b83
commit
62a613ce80
|
@ -6,9 +6,22 @@ export default function(Component) {
|
|||
const Instance = super.instanceFromSchema();
|
||||
Instance.prototype.item = function (slot) {
|
||||
const {slots} = this;
|
||||
for (const {slotIndex, source} of this.slots) {
|
||||
if (slot === slotIndex) {
|
||||
return source;
|
||||
const instance = this;
|
||||
for (const index in slots) {
|
||||
const item = slots[index];
|
||||
if (slot === item.slotIndex) {
|
||||
const proxy = new Proxy(item, {
|
||||
set(target, property, value) {
|
||||
const newSlots = [...slots];
|
||||
newSlots[index] = {
|
||||
...target,
|
||||
[property]: value,
|
||||
};
|
||||
instance.slots = newSlots;
|
||||
return true;
|
||||
},
|
||||
});
|
||||
return proxy;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -114,7 +114,7 @@ export default class Engine {
|
|||
Inventory: {
|
||||
slots: [
|
||||
{
|
||||
qty: 10,
|
||||
qty: 500,
|
||||
slotIndex: 0,
|
||||
source: '/assets/potion',
|
||||
}
|
||||
|
@ -236,11 +236,11 @@ export default class Engine {
|
|||
case 'use': {
|
||||
if (payload.value) {
|
||||
const item = Inventory.item(Wielder.activeSlot);
|
||||
this.server.readAsset(item + '/start.js')
|
||||
this.server.readAsset(item.source + '/start.js')
|
||||
.then((response) => response.text())
|
||||
.then((code) => {
|
||||
Ticking.addTickingPromise(
|
||||
Script.tickingPromise(code, {console, wielder: entity}),
|
||||
Script.tickingPromise(code, {item, wielder: entity}),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,7 +1,2 @@
|
|||
wielder.Health.health += 10
|
||||
wielder.Inventory.slots = [
|
||||
{
|
||||
...wielder.Inventory.slots[0],
|
||||
qty: wielder.Inventory.slots[0].qty - 1,
|
||||
}
|
||||
]
|
||||
item.qty -= 1
|
||||
|
|
Loading…
Reference in New Issue
Block a user