Merge branch 'stack-items' into 'master'
Stack items in the inventory Closes #29 See merge request ynerant/squirrel-battle!37
This commit is contained in:
commit
3985751bd1
|
@ -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:
|
||||||
|
|
Loading…
Reference in New Issue