refactor: item use context

This commit is contained in:
cha0s 2021-04-20 03:00:30 -05:00
parent dbd6091acc
commit 10289f4c06
2 changed files with 5 additions and 6 deletions

View File

@ -34,6 +34,7 @@ export default (latus) => class Item extends decorate(Trait) {
static dependencies() { static dependencies() {
return [ return [
'Behaved',
'Pictured', 'Pictured',
]; ];
} }
@ -71,10 +72,10 @@ export default (latus) => class Item extends decorate(Trait) {
return this.entity.image(key); return this.entity.image(key);
}, },
use: (context) => { use: () => {
const {cooldown} = this.params; const {cooldown} = this.params;
const {Script} = latus.get('%resources'); 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) { if (cooldown > 0) {
promises.push(new Promise((resolve) => { promises.push(new Promise((resolve) => {
setTimeout(resolve, 1000 * cooldown); setTimeout(resolve, 1000 * cooldown);

View File

@ -96,10 +96,8 @@ export default () => class Wielder extends decorate(Trait) {
return undefined; return undefined;
} }
// Defer until the item actions are finished. // Defer until the item actions are finished.
this.#itemPromise = item.use({ item.context.wielder = this.entity;
entity: item, this.#itemPromise = item.use();
wielder: this.entity,
});
this.#itemPromise.then(() => { this.#itemPromise.then(() => {
this.#itemPromise = undefined; this.#itemPromise = undefined;
}); });