feat(engine): fetch daily-challenge seed from server on startup
- Add fetch_daily_challenge() to SyncProvider trait (default: Ok(None)) - SolitaireServerClient calls GET /api/daily-challenge (public endpoint) and returns the ChallengeGoal; non-2xx responses return Ok(None) so callers fall back to the local date-hash seed - DailyChallengePlugin spawns an async task on Startup (only when SyncProviderResource is present) and polls it in Update; on success it overwrites DailyChallengeResource.seed with the server's seed, ensuring all players worldwide get the same deal on a given date 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::{LeaderboardEntry, SyncPayload, SyncResponse};
|
||||
use solitaire_sync::{ChallengeGoal, LeaderboardEntry, SyncPayload, SyncResponse};
|
||||
use thiserror::Error;
|
||||
|
||||
/// All errors that can arise during sync operations.
|
||||
@@ -36,6 +36,11 @@ pub trait SyncProvider: Send + Sync {
|
||||
async fn fetch_leaderboard(&self) -> Result<Vec<LeaderboardEntry>, SyncError> {
|
||||
Ok(vec![])
|
||||
}
|
||||
/// Fetch today's daily challenge from the server. Returns `None` for
|
||||
/// backends that don't support it, or on any non-fatal network failure.
|
||||
async fn fetch_daily_challenge(&self) -> Result<Option<ChallengeGoal>, SyncError> {
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
|
||||
/// Blanket impl so `Box<dyn SyncProvider + Send + Sync>` (returned by
|
||||
@@ -60,6 +65,9 @@ impl SyncProvider for Box<dyn SyncProvider + Send + Sync> {
|
||||
async fn fetch_leaderboard(&self) -> Result<Vec<LeaderboardEntry>, SyncError> {
|
||||
(**self).fetch_leaderboard().await
|
||||
}
|
||||
async fn fetch_daily_challenge(&self) -> Result<Option<ChallengeGoal>, SyncError> {
|
||||
(**self).fetch_daily_challenge().await
|
||||
}
|
||||
}
|
||||
|
||||
pub mod stats;
|
||||
|
||||
Reference in New Issue
Block a user