Skip to content

Commit 6837ef3

Browse files
FEAT: Add platform breakdowns to icon distributions in ./main.py
1 parent 8149b58 commit 6837ef3

1 file changed

Lines changed: 34 additions & 4 deletions

File tree

Games Collection Manager/main.py

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,32 @@ def compute_console_counters(games: list) -> tuple:
626626
return owned, total # Return computed counters as a tuple
627627

628628

629+
def build_icon_platform_breakdown(sections: list, icon: str) -> str:
630+
"""
631+
Build a platform breakdown string for a specific icon.
632+
633+
:param sections: List of console section dictionaries with game lists.
634+
:param icon: Icon string to count across sections.
635+
:return: Formatted breakdown string, or empty string when no matches exist.
636+
"""
637+
638+
try: # Wrap breakdown formatting to ensure safe execution
639+
platform_parts = [] # Collect non-zero platform counts in display order
640+
641+
for section in sections: # Iterate each console section in sorted order
642+
icon_count = sum(1 for line in section["games"] if icon in parse_game_icons(line)) # Count matching icon occurrences in the current section
643+
if icon_count > 0: # Include only platforms with a non-zero count
644+
platform_parts.append(f"{section['name']} {icon_count}") # Record platform name and count
645+
646+
if not platform_parts: # Return empty string when the icon is not present anywhere
647+
return "" # No breakdown needed for zero-count lines
648+
649+
return f" ({' + '.join(platform_parts)})" # Return formatted platform breakdown
650+
651+
except Exception: # Catch unexpected formatting errors
652+
return "" # Return empty string on failure
653+
654+
629655
def format_txt_output(sections: list) -> str:
630656
"""
631657
Format a list of parsed console sections into the canonical TXT output string.
@@ -684,10 +710,14 @@ def format_txt_output(sections: list) -> str:
684710
output_lines.append("") # Insert blank line between total counters and icon distribution block
685711
output_lines.append(f"-- Icons Distributions:")
686712
output_lines.append(f"- Owned - {ICON_OWNED}: {total_owned_icon}.")
687-
output_lines.append(f"- Owned - DVD Box Cleaning - {ICON_NEEDS_CLEANING}: {total_needs_cleaning_icon}.")
688-
output_lines.append(f"- Owned - DVD Box Cover - {ICON_DAMAGED}: {total_damaged_icon}.")
689-
output_lines.append(f"- Owned - Box Damaged - {ICON_BOX_DAMAGED}: {total_box_damaged_icon}.")
690-
output_lines.append(f"- Unsure is Owned - {ICON_MAYBE}: {total_unsure_icon}.")
713+
cleaning_breakdown = build_icon_platform_breakdown(sorted_sections, ICON_NEEDS_CLEANING) # Build platform breakdown for cleaning icon
714+
damaged_breakdown = build_icon_platform_breakdown(sorted_sections, ICON_DAMAGED) # Build platform breakdown for damaged cover icon
715+
box_damaged_breakdown = build_icon_platform_breakdown(sorted_sections, ICON_BOX_DAMAGED) # Build platform breakdown for damaged box icon
716+
unsure_breakdown = build_icon_platform_breakdown(sorted_sections, ICON_MAYBE) # Build platform breakdown for unsure-owned icon
717+
output_lines.append(f"- Owned - DVD Box Cleaning - {ICON_NEEDS_CLEANING}: {total_needs_cleaning_icon}{cleaning_breakdown}.")
718+
output_lines.append(f"- Owned - DVD Box Cover - {ICON_DAMAGED}: {total_damaged_icon}{damaged_breakdown}.")
719+
output_lines.append(f"- Owned - Box Damaged - {ICON_BOX_DAMAGED}: {total_box_damaged_icon}{box_damaged_breakdown}.")
720+
output_lines.append(f"- Unsure is Owned - {ICON_MAYBE}: {total_unsure_icon}{unsure_breakdown}.")
691721

692722
output_lines.append("")
693723
output_lines.extend(FIXED_METADATA_BLOCK) # Append fixed non-console metadata block in deterministic order

0 commit comments

Comments
 (0)