import Schema from '@/ecs/schema.js'; export default function(Component) { return class Inventory extends Component { instanceFromSchema() { const Instance = super.instanceFromSchema(); Instance.prototype.item = function (slot) { const {slots} = this; for (const {slotIndex, source} of this.slots) { if (slot === slotIndex) { return source; } } }; return Instance; } static schema = new Schema({ type: 'object', properties: { slots: { type: 'array', subtype: { type: 'object', properties: { quantity: {type: 'uint16'}, slotIndex: {type: 'uint16'}, source: {type: 'string'}, }, }, }, }, }); } }