Skip to content

Commit

Permalink
Add climb portal badges
Browse files Browse the repository at this point in the history
  • Loading branch information
oldnapalm committed Dec 11, 2023
1 parent 1e00d9a commit e59390b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pyinstaller.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: pyinstaller
on:
push:
branches:
- master
- achievements

jobs:
build:
Expand Down
23 changes: 21 additions & 2 deletions zwift_offline.py
Original file line number Diff line number Diff line change
Expand Up @@ -3426,8 +3426,23 @@ def achievement_loadPlayerAchievements():
converted.achievements.add().id = ach_id
with open(achievements_file, 'wb') as f:
f.write(converted.SerializeToString())
achievements = profile_pb2.Achievements()
with open(achievements_file, 'rb') as f:
return f.read(), 200
achievements.ParseFromString(f.read())
climbs = SegmentResult.query.filter(SegmentResult.player_id == current_user.player_id, SegmentResult.segment_id.between(10000, 11000)).count()
if climbs:
current = []
for achievement in achievements.achievements:
current.append(achievement.id)
if not 211 in current:
achievements.achievements.add().id = 211 # Portal Climber
if climbs >= 10 and not 212 in current:
achievements.achievements.add().id = 212 # Climb Portal Pro
if climbs >= 25 and not 213 in current:
achievements.achievements.add().id = 213 # Legs of Steel
with open(achievements_file, 'wb') as f:
f.write(achievements.SerializeToString())
return achievements.SerializeToString(), 200

@app.route('/api/achievement/unlock', methods=['POST'])
@jwt_to_session_cookie
Expand All @@ -3442,8 +3457,12 @@ def achievement_unlock():
if os.path.isfile(achievements_file):
with open(achievements_file, 'rb') as f:
achievements.ParseFromString(f.read())
current = []
for achievement in achievements.achievements:
current.append(achievement.id)
for achievement in new.achievements:
achievements.achievements.add().id = achievement.id
if not achievement.id in current:
achievements.achievements.add().id = achievement.id
with open(achievements_file, 'wb') as f:
f.write(achievements.SerializeToString())
return '', 202
Expand Down

0 comments on commit e59390b

Please sign in to comment.