[cli,core] Move achievement classification into LegendaryCore

There's no need for iterating twice
This commit is contained in:
Stelios Tsampas 2025-12-22 00:36:38 +02:00
parent 048a560b46
commit 6c9dc3945d
2 changed files with 18 additions and 19 deletions

View file

@ -2653,22 +2653,8 @@ class LegendaryCLI:
print(f' Player XP: {achievements["user_xp"]}')
print(f' Player awards: {achievements["user_awards"]}')
completed = []
in_progress = []
uninitiated = []
hidden = []
for ach in achievements['achievements']:
if ach['unlocked']:
completed.append(ach)
elif 0.0 < ach['progress'] < 1.0:
in_progress.append(ach)
elif not ach['hidden'] and ach['progress'] == 0.0:
uninitiated.append(ach)
elif ach['hidden']:
hidden.append(ach)
for group, title in zip(
(completed, in_progress, uninitiated),
(achievements['completed'], achievements['in_progress'], achievements['uninitiated']),
('Completed', 'In progress', 'Uninitiated')
):
print(f'* {title}')
@ -2677,10 +2663,12 @@ class LegendaryCLI:
if args.show_hidden:
print('* Hidden')
for a in hidden:
for a in achievements['hidden']:
print(' - {display_name} | {xp}XP | {description} | Progress: {progress:.1%} | Completed on: {unlock_date}'.format(**a))
count = sum(map(len, (completed, in_progress, uninitiated, hidden)))
count = sum(
map(len, (achievements['completed'], achievements['in_progress'], achievements['uninitiated'], achievements['hidden']))
)
logger.info(f'Found {count} achievements')
return

View file

@ -346,7 +346,10 @@ class LegendaryCore:
'total_product_xp': game_achievements.total_product_xp,
'achievement_sets': game_achievements.achievement_sets,
'platinum_rarity': game_achievements.platinum_rarity,
'achievements': []
'completed': [],
'in_progress': [],
'uninitiated': [],
'hidden': [],
}
achievements.update({
'user_unlocked': user_achievements['totalUnlocked'] if user_achievements else 0,
@ -384,7 +387,15 @@ class LegendaryCore:
'tier': game_ach['tier'],
'rarity': game_ach['rarity'],
}
achievements['achievements'].append(data)
if data['unlocked']:
achievements['completed'].append(data)
elif 0.0 < data['progress'] < 1.0:
achievements['in_progress'].append(data)
elif not data['hidden'] and data['progress'] == 0.0:
achievements['uninitiated'].append(data)
elif data['hidden']:
achievements['hidden'].append(data)
return achievements