feat(engine): leaderboard screen (press L to toggle)
Press L to open a leaderboard overlay. On open, an async fetch is dispatched against the active SyncProvider. Results cache in LeaderboardResource; the panel rebuilds live when data arrives. Closing during a fetch is safe (ClosedThisFrame flag prevents re-spawning the panel in the same frame as the user's despawn command). Format: ranked table with player name, best score, and fastest win time. Non-authenticated / LocalOnly providers return an empty list gracefully. - solitaire_data: add fetch_leaderboard() to SyncProvider trait (default → Ok([])) and implement in SolitaireServerClient - solitaire_engine: new LeaderboardPlugin with 5 unit tests - solitaire_app: register LeaderboardPlugin Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
use async_trait::async_trait;
|
||||
use solitaire_sync::{SyncPayload, SyncResponse};
|
||||
use solitaire_sync::{LeaderboardEntry, SyncPayload, SyncResponse};
|
||||
use thiserror::Error;
|
||||
|
||||
/// All errors that can arise during sync operations.
|
||||
@@ -33,6 +33,11 @@ pub trait SyncProvider: Send + Sync {
|
||||
async fn mirror_achievement(&self, _id: &str) -> Result<(), SyncError> {
|
||||
Ok(())
|
||||
}
|
||||
/// Fetch the global leaderboard from this backend. Returns an empty list
|
||||
/// for backends that do not support leaderboards (e.g. `LocalOnlyProvider`).
|
||||
async fn fetch_leaderboard(&self) -> Result<Vec<LeaderboardEntry>, SyncError> {
|
||||
Ok(vec![])
|
||||
}
|
||||
}
|
||||
|
||||
/// Blanket impl so `Box<dyn SyncProvider + Send + Sync>` (returned by
|
||||
@@ -54,6 +59,9 @@ impl SyncProvider for Box<dyn SyncProvider + Send + Sync> {
|
||||
async fn mirror_achievement(&self, id: &str) -> Result<(), SyncError> {
|
||||
(**self).mirror_achievement(id).await
|
||||
}
|
||||
async fn fetch_leaderboard(&self) -> Result<Vec<LeaderboardEntry>, SyncError> {
|
||||
(**self).fetch_leaderboard().await
|
||||
}
|
||||
}
|
||||
|
||||
pub mod stats;
|
||||
|
||||
Reference in New Issue
Block a user