Inventory
The Inventory is a known concept. It can keep track of Items, and display them to the player.
It should also be able to check if you have enough items to perform certain actions.
Requirements
- Keep track of
AbstractItems - Make it easy to gain and lose items of a specific
ItemId - Items can contain optional data
- Drag and drop support
- Allow merging and swapping items
Usage
Implementation
Internally the Inventory uses the InventorySlot class.
It is a simple data class with a few helper methods.
export class InventorySlot {
item: AbstractItem;
amount: number;
isEmpty(): boolean {
};
isFull(): boolean {
};
gainItems(amount: number) {
};
}
Note how it contains the actual AbstractItem, not just a reference to its id.
This allows us to store additional data in items, like durability of a weapon.
Events
onItemGain
Emitted whenever an item is gained.
App.game.features.inventory.onItemGain.subscribe((item, amount) => {
console.log("Something happened", data);
});