Skip to content

feat: ScoreKeeper leaderboard helper#40

Merged
BCook98 merged 1 commit into
mainfrom
scorekeeper
Jun 15, 2026
Merged

feat: ScoreKeeper leaderboard helper#40
BCook98 merged 1 commit into
mainfrom
scorekeeper

Conversation

@BCook98

@BCook98 BCook98 commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

What

Adds kit.ScoreKeeper, a small timer-free helper that standardises the three ways a game posts to the leaderboard. This is the foundation for making every game record scores and survive disconnects (games + platform changes ride on top in separate PRs).

API

  • Record(r, p, metric) — post live per a Cadence (OnImprove posts only on a new high, for monotonic boards; OnChange on any change).
  • FlushLeave(r, p, status) — post the player's current metric on disconnect (call from OnLeave); no-op if untracked.
  • FlushAll(r, status) — re-post all tracked players in deterministic AccountID order; continuous games call this from OnWake on a throttled interval so an abandoned, still-ticking world keeps recording.
  • PersistBest / PersistWallet — KV resume sugar (MergeMax / MergeSum), folding the duplicated per-game persistWallet/persistBest helpers into one place.

Notes

  • Pure SDK addition over the existing Room.Post + KV surface — no wire/ABI change. Holds no goroutines/timers, so behaviour stays deterministic under hibernation/replay.
  • A .changeset/ entry marks this a minor bump (next release ≈ v2.11.0).
  • FlushLeave docs the lower-is-better caveat: the platform reader ranks DNF rows like finished ones, so callers must pass a fair full-run metric (e.g. par-extrapolated) on lower-better boards.

Test

6 new tests via kittest covering cadence, DNF flush + no-op-after-leave, deterministic FlushAll, and KV merge rules. go test ./..., go build ./..., go vet ./... all clean.

🤖 Generated with Claude Code

Timer-free helper standardising live (Record), disconnect (FlushLeave), and
periodic (FlushAll) leaderboard posting, plus PersistBest/PersistWallet KV
sugar. Pure SDK addition over Room.Post + KV — no wire/ABI change.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@BCook98
BCook98 merged commit 49b4a42 into main Jun 15, 2026
6 of 7 checks passed
@BCook98
BCook98 deleted the scorekeeper branch June 15, 2026 11:39
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.

1 participant