Stack items in the inventory, closes #29

This commit is contained in:
Yohann D'ANELLO 2020-12-05 13:42:33 +01:00
parent 4d60e95165
commit ca2ae15117
1 changed files with 13 additions and 2 deletions

View File

@ -31,8 +31,19 @@ class StatsDisplay(Display):
self.player.dexterity, self.player.constitution) self.player.dexterity, self.player.constitution)
self.addstr(self.pad, 3, 0, string3) self.addstr(self.pad, 3, 0, string3)
inventory_str = _("Inventory:") + " " + "".join( inventory_str = _("Inventory:") + " "
self.pack[item.name.upper()] for item in self.player.inventory) # Stack items by type instead of displaying each item
item_types = [item.name for item in self.player.inventory]
item_types.sort(key=item_types.count, reverse=True)
printed_items = []
for item in item_types:
if item in printed_items:
continue
count = item_types.count(item)
inventory_str += self.pack[item.upper()]
if count > 1:
inventory_str += f"x{count} "
printed_items.append(item)
self.addstr(self.pad, 8, 0, inventory_str) self.addstr(self.pad, 8, 0, inventory_str)
if self.player.dead: if self.player.dead: