refactor: defaults

This commit is contained in:
cha0s 2021-04-01 17:14:48 -05:00
parent db1883dc98
commit 2ed4eed036

View File

@ -1,6 +1,5 @@
import {Actions, buildInvoke, compile} from '@avocado/behavior';
import {Property} from '@avocado/core';
import {Image} from '@avocado/graphics';
import {StateProperty, Trait} from '@avocado/traits';
import {compose} from '@latus/core';
@ -18,11 +17,6 @@ const decorate = compose(
export default (latus) => class Item extends decorate(Trait) {
constructor() {
super();
this._slotImageUris = {};
}
static defaultParams() {
return {
cooldown: 0,
@ -31,7 +25,7 @@ export default (latus) => class Item extends decorate(Trait) {
expressions: [],
},
slotImageUris: {
default: '/question-mark.png',
default: 'default',
},
};
}
@ -42,6 +36,12 @@ export default (latus) => class Item extends decorate(Trait) {
};
}
static dependencies() {
return [
'Pictured',
];
}
static children() {
return {
decrementQuantity: {
@ -69,13 +69,6 @@ export default (latus) => class Item extends decorate(Trait) {
await super.load(json);
const itemActions = this._processedItemActions();
this._itemActions = new Actions(compile(itemActions, latus));
if ('client' === process.env.SIDE) {
await Promise.all(Object.entries(this.params.slotImageUris)
.map(async ([slotIndex, uri]) => {
const image = await Image.load(uri);
this._slotImageUris[slotIndex] = image;
}));
}
}
methods() {
@ -86,8 +79,10 @@ export default (latus) => class Item extends decorate(Trait) {
},
imageForSlot: () => {
const {slotImageUris} = this.params;
const {qty} = this.entity;
return this._slotImageUris[this._slotImageUris[qty] ? qty : 'default'];
const key = slotImageUris[slotImageUris[qty] ? qty : 'default'];
return this.entity.image(key);
},
};