jdungeon
jdungeon copied to clipboard
Item stacking (again)
When an item is added, it will attempt to stack it onto another item whose amount does not match or exceed Item.amount_max.
Refactored Item.use() and related functions to no longer forcibly remove used items, now it depends on the item being used and the amount remaining.
Consumables remove a single unit from their stack on use (and get fully removed when the last one is used).
Equipment is removed from the inventory directly, but their amount does not change (this allows for weapons that use the "amount" property, like throwing knives or something).
The amount of an item is now displayed in their InventoryPanel, unless there is only 1 item left in the stack. (Values of 0 and lower values are still drawn to make bugs easier to spot)
This PR also comes with a new "InventorySynchronizerComponent.update_inventory()" function that updates all panels as performantly as possible by reading the inventory directly. This should be considerably faster than adding/removing items individually since it only combs trough the panels once for all of the items.
If this method can be queued to run once per frame once the inventory changes ( similar to queue_redraw() ), it should be a considerable speed up (and more reliable) for most inventory-related operations.
All items have an amount_max of 1 right now, except for potions who have a value of 6.