Skip to content

feat(game-center): centre leaderboard slice on local player rank (closes #140) - #146

Merged
wei18 merged 2 commits into
mainfrom
feat/issue-140-around-player
May 26, 2026
Merged

wei18 merged 2 commits into
mainfrom
feat/issue-140-around-player

Conversation

@wei18

@wei18 wei18 commented May 26, 2026

Copy link
Copy Markdown
Owner

Summary

Closes #140. `GKLeaderboardLoader` now honors `around: PlayerID?` by centring the slice on `GKLocalPlayer.local` when non-nil.

Approach (per Leader's pre-research, baked into dispatch)

  • Protocol takes `around: PlayerID?` (teamPlayerID string), but GameKit's `loadEntries(for: [GKPlayer], timeScope:)` requires `GKPlayer` instances
  • Converting teamPlayerID → GKPlayer requires gamePlayerID + an async lookup, non-trivial
  • CompletionView (only production consumer of `around`) always means "centre on local player", so substitution is `GKLocalPlayer.local` when `around != nil`. Documented inline + impl-notes.

Implementation

  • Two-step `loadEntries`: first call gets local player rank, second fetches the range
  • Pure helper `makeRange(centeredOnRank:limit:)` extracted as internal static — testable without GameKit dep
  • Fall back to top-N when local player not found in scope (per GameKit semantics)
  • Window = `limit / 2`

3 files, +115/-12.

CR verdict: APPROVE-WITH-NITS

0 must-fix. 3 should-considers (Leader will inline-apply S1+S2 pre-merge; S3 = follow-up issue):

  • S1: Update `LeaderboardLoader.loadSlice` protocol doc in `Slice.swift` to document the live narrowing ("non-local teamPlayerIDs not supported"). 2-line doc edit.
  • S2: Add boundary test `rank=1, limit=8 → (1, 8)` to lock the top-anchor case.
  • S3: File follow-up issue for non-local player centring support.

CR praise

  • Clean `makeRange` extraction — right test seam, no over-abstraction
  • Tuple-arity correction (2-tuple, not 3-tuple) shows actual GameKit headers verified
  • Removed `_ = (player)` discard + TODO in same commit

Test plan

  • Verify CR S1+S2 inline-applied before merge
  • After merge: file S3 follow-up issue

🤖 Generated with Claude Code

wei18 and others added 2 commits May 26, 2026 13:08
 #140)

When `around != nil`, `GKLeaderboardLoader` now performs a two-step
`GKLeaderboard` call: first `loadEntries(for: [GKLocalPlayer.local], timeScope:)`
to discover the local player's rank, then `loadEntries(for:timeScope:range:)`
with a window of `limit` centred on that rank (clamped to location >= 1).

Scope narrowing: the `around: String?` parameter carries a teamPlayerID,
which cannot be cheaply converted to a `GKPlayer`
(`GKPlayer.loadPlayers(forIdentifiers:)` accepts gamePlayerID, not
teamPlayerID). The realistic production use case (CompletionView) is
"centre on the local player", so `GKLocalPlayer.local` is used as the
rank source whenever `around` is non-nil. A follow-up issue can be filed
if any future feature needs centring on a different player.

Range arithmetic is extracted to a pure static helper
`GKLeaderboardLoader.makeRange(centeredOnRank:limit:)` and unit tested
directly; the live `GKLeaderboard` calls remain exercised by Phase 10
manual device validation (consistent with the file's COMPILE-ONLY stance).

- `around == nil` path unchanged (existing 3 wiring tests still pass)
- 3 new tests cover: centring at rank 50, clamp-to-1 at low rank, nil-rank fallback to top-N
- S1: doc-comment the scope-narrowing on `LeaderboardLoader.loadSlice`
  protocol — `around != nil` is currently honoured only as "centre on
  local player", non-local teamPlayerIDs not supported in live impl.
- S2: add `locksTopAnchorWhenRankIsOne` boundary test asserting
  rank=1 → (location: 1, length: 8) without underflow.

S3 (follow-up issue for non-local player centring) — will file via gh
issue create separately; if the issue is created the doc-comment
above should point at its number.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
@wei18
wei18 merged commit c4a8980 into main May 26, 2026
@wei18
wei18 deleted the feat/issue-140-around-player branch May 26, 2026 05:59
wei18 added a commit that referenced this pull request May 26, 2026
…tformat note (#162)

* docs: add wiki-migration backlog + 2026-05-26 session log + obsolete swiftformat-option-b note

- foundations.md §Backlog: docs/+meetings/ → GitHub Wiki migration (2 options)
- meetings/2026-05-26_session-log.md: today's PRs (#146-#161) + module-split status
  + tooling SSOT recap + operational learnings (CR OR rule, NO-VERIFY, surgical
  per-file analysis)
- swiftformat-option-b.impl-notes.md: OBSOLETED banner (full swiftformat purge
  same day; decision preserved as history)

Co-Authored-By: Claude Opus 4.7 <[email protected]>

* docs(meetings): include #144/#145 spillover rows (CR #162 nit)

Co-Authored-By: Claude Opus 4.7 <[email protected]>

---------

Co-authored-by: Claude Opus 4.7 <[email protected]>
wei18 added a commit that referenced this pull request Jun 3, 2026
…ing (#150) (#285)

PR #146's loadSlice(around: PlayerID?) silently substituted GKLocalPlayer.local
for any passed id — a dishonest contract (CR S3). True non-local centring isn't
reachable via public GameKit API (teamPlayerID->GKPlayer has no mapping). Make
the signature honest (aroundLocalPlayer: Bool); update Live/GK/Fake impls + doc,
drop the narrowing note. Real non-local centring deferred to a friends feature.

Co-authored-by: Claude Opus 4.8 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(game-center): centre LeaderboardSliceService range on player rank (#64 N-1 follow-up)

1 participant