Skip to content

Notify players when they break a top score - #52

Merged
bashmohandes merged 3 commits into
masterfrom
codex/add-score-break-notification-feature
Aug 13, 2026
Merged

bashmohandes merged 3 commits into
masterfrom
codex/add-score-break-notification-feature

Conversation

@bashmohandes

Copy link
Copy Markdown
Owner

Motivation

  • Make top-score changes explicit to players by showing a celebratory, accessible notification when a newly recorded result beats the existing leaderboard top score, including the previous vs new score and a link to the relevant Top Scores.
  • Surface the correct leaderboard tab when following a leaderboard link so the notification takes players directly to the affected game.

Description

  • Server: record() in server/accounts.js now queries the current top entry for the game before inserting the new result and returns a topScore object when the new score beats the previous top (includes game, previousScore, newScore, and previousHolder).
  • Client: arcade.js adds showTopScore() with rotating congratulations messages and an accessible toast UI, and window.Arcade.record now invokes showTopScore(recorded.topScore) when a record-breaking result is returned.
  • Styles: added .top-score-toast styles and reduced-motion support to arcade.css for responsive, animated presentation and a dismissal control.
  • UX: profile.js will pre-select the leaderboard tab when ?game= is present in the URL so leaderboard links open the correct game tab.
  • Tests: added a regression test in tests/accounts.test.js verifying initial, lower, and record-breaking scores and that a record-breaking response contains the correct previous/new score and prior holder.

Testing

  • Ran npm test (node --test) and all tests passed: 93 passed, 0 failed.
  • Ran npm run check and static checks passed without errors.
  • Ran git diff --check and no check issues were reported.

Codex Task

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e2f8195199

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread server/accounts.js Outdated
Comment on lines +104 to +106
const topScore = previousTop && score > previousTop.score
? { game, previousScore: previousTop.score, newScore: score, previousHolder: previousTop.gamertag }
: null;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Treat leaderboard tie-breakers as record changes

When a result matches the current high score but has a faster time, Accounts.leaderboard() ranks it first using seconds as a tie-breaker, yet this strict score comparison returns null. This is especially common in Pong, where scores are highly repetitive, and means the leaderboard can acquire a new leader without showing the notification this change is intended to provide. Compare the complete leaderboard ordering rather than only score.

Useful? React with 👍 / 👎.

Comment thread arcade.js
user: () => currentUser,
signIn: () => dialog.showModal(),
record: async result => { if (!currentUser) return null; const recorded = await api('/api/results', { method: 'POST', body: JSON.stringify(result) }); showUnlocks(recorded.unlocked || []); return recorded; },
record: async result => { if (!currentUser) return null; const recorded = await api('/api/results', { method: 'POST', body: JSON.stringify(result) }); showTopScore(recorded.topScore); showUnlocks(recorded.unlocked || []); return recorded; },

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Queue top-score and achievement notifications together

When a record-breaking result also unlocks an achievement, this line immediately displays both notifications. Both toasts are fixed at the same bottom-right coordinates in arcade.css, and the new top-score toast has the higher z-index, so it covers the achievement toast until that toast expires after 5.2 seconds. Route the top-score notification through the existing queue or otherwise offset/sequence the two notifications.

Useful? React with 👍 / 👎.

@bashmohandes
bashmohandes merged commit 4c2178a into master Aug 13, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant