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() {
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);

View File

@ -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;
});