From 10289f4c06e6660c493f676f6b6b0cd0c71cb220 Mon Sep 17 00:00:00 2001 From: cha0s Date: Tue, 20 Apr 2021 03:00:30 -0500 Subject: [PATCH] refactor: item use context --- packages/core/src/traits/item.js | 5 +++-- packages/inventory/src/traits/wielder.js | 6 ++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/packages/core/src/traits/item.js b/packages/core/src/traits/item.js index f91d299..12df528 100644 --- a/packages/core/src/traits/item.js +++ b/packages/core/src/traits/item.js @@ -34,6 +34,7 @@ export default (latus) => class Item extends decorate(Trait) { static dependencies() { return [ + 'Behaved', 'Pictured', ]; } @@ -71,10 +72,10 @@ export default (latus) => class Item extends decorate(Trait) { return this.entity.image(key); }, - use: (context) => { + use: () => { const {cooldown} = this.params; const {Script} = latus.get('%resources'); - const promises = [Script.loadTickingPromise(this.params.useScript, context)]; + const promises = [Script.loadTickingPromise(this.params.useScript, this.entity.context)]; if (cooldown > 0) { promises.push(new Promise((resolve) => { setTimeout(resolve, 1000 * cooldown); diff --git a/packages/inventory/src/traits/wielder.js b/packages/inventory/src/traits/wielder.js index b2bf13b..11a2869 100644 --- a/packages/inventory/src/traits/wielder.js +++ b/packages/inventory/src/traits/wielder.js @@ -96,10 +96,8 @@ export default () => class Wielder extends decorate(Trait) { return undefined; } // Defer until the item actions are finished. - this.#itemPromise = item.use({ - entity: item, - wielder: this.entity, - }); + item.context.wielder = this.entity; + this.#itemPromise = item.use(); this.#itemPromise.then(() => { this.#itemPromise = undefined; });