Animate the Challenge after a live Match ends (#89)

This commit is contained in:
nessar authored and nessar committed 2026-11-22 15:16:04 +01:00
1 parent aac2f4212c
commit 126912fd09
13 files changed
+687 -86

No files matched your search

+15 -2
View File
@@ -223,6 +223,18 @@ impl Tracker {
fallback_riot_id: Option<&str>,
snapshot: &ClientSnapshot,
on_progress: &mut dyn FnMut(SyncProgress),
) -> bool {
self.follow_client_reporting(now_ms, fallback_riot_id, snapshot, on_progress, &mut |_| {})
}
/// Reports only newly inserted Matches identified by the live gameflow.
pub fn follow_client_reporting(
&self,
now_ms: i64,
fallback_riot_id: Option<&str>,
snapshot: &ClientSnapshot,
on_progress: &mut dyn FnMut(SyncProgress),
on_match: &mut dyn FnMut(crate::FollowedMatch),
) -> bool {
let before = self.status();
let mut added = 0;
@@ -285,7 +297,7 @@ impl Tracker {
due.dedup();
for game_id in due {
let (found, over) = match &account {
Some(account) => self.look_for_match(account, game_id, on_progress),
Some(account) => self.look_for_match(account, game_id, on_progress, on_match),
None => (0, false),
};
added += found;
@@ -467,6 +479,7 @@ impl Tracker {
account: &Account,
game_id: Option<u64>,
on_progress: &mut dyn FnMut(SyncProgress),
on_match: &mut dyn FnMut(crate::FollowedMatch),
) -> (usize, bool) {
let platform = self.platform_of(&account.puuid).ok().flatten();
let Some(match_id) = game_id.zip(platform).map(|(id, p)| format!("{p}_{id}")) else {
@@ -474,7 +487,7 @@ impl Tracker {
let added = self.update(&account_riot_id(account), on_progress);
return (added.map_or(0, |report| report.added), false);
};
match self.fetch_and_store(&account.puuid, &match_id) {
match self.fetch_and_store(&account.puuid, &match_id, Some(on_match)) {
Ok(fetched) => {
let added = usize::from(fetched == Fetched::Added);
self.clear_problem(added);
+1 -1
View File
@@ -27,7 +27,7 @@ pub use follow::{
same_riot_id,
};
pub use league_client::{LeagueClient, decode_gameflow};
pub use model::{Account, Format, Match, SyncProgress, SyncReport};
pub use model::{Account, FollowedMatch, Format, Match, MatchEnd, SyncProgress, SyncReport};
pub use riot::RiotApi;
pub use seasons::{Season, default_seasons, load_seasons};
pub use splash::{BannerFrame, Splash, SplashFocus};
+17
View File
@@ -51,6 +51,23 @@ pub struct Match {
pub started_at_ms: i64,
}
/// The strongest milestone gained when a followed Match is first stored.
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
pub enum MatchEnd {
Nothing,
Mark,
Completion,
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct FollowedMatch {
pub puuid: String,
pub season: String,
pub champion_id: u32,
pub started_at_ms: i64,
pub end: MatchEnd,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct SyncProgress {
pub fetched: usize,
+44 -7
View File
@@ -3,6 +3,7 @@ use std::path::{Path, PathBuf};
use std::sync::{Arc, Mutex, MutexGuard, PoisonError};
use std::thread;
use crate::{FollowedMatch, MatchEnd};
use rusqlite::{Connection, OptionalExtension, Row, params};
use serde::Deserialize;
@@ -179,7 +180,7 @@ impl Tracker {
let mut added = 0;
for (i, match_id) in to_fetch.iter().enumerate() {
// Stored at once, so an interrupted import loses nothing.
if self.fetch_and_store(&account.puuid, match_id)? == Fetched::Added {
if self.fetch_and_store(&account.puuid, match_id, None)? == Fetched::Added {
added += 1;
}
on_progress(SyncProgress {
@@ -205,7 +206,12 @@ impl Tracker {
/// Fetches one Match by id and stores it. A Match Riot does not have or that cannot be
/// read is skipped rather than failing the caller: one bad id must not block the rest.
pub(crate) fn fetch_and_store(&self, puuid: &str, match_id: &str) -> Result<Fetched, Error> {
pub(crate) fn fetch_and_store(
&self,
puuid: &str,
match_id: &str,
report: Option<&mut dyn FnMut(FollowedMatch)>,
) -> Result<Fetched, Error> {
let raw = match with_retry(|| self.history.fetch_match(match_id)) {
Ok(raw) => raw,
Err(SourceError::NotFound) => return Ok(Fetched::NotFound),
@@ -214,12 +220,43 @@ impl Tracker {
let Ok(Some((m, queue_id))) = decode_match(&raw, puuid) else {
return Ok(Fetched::Ignored);
};
let inserted = insert_match(&self.db(), puuid, &m, queue_id, &raw)?;
Ok(if inserted {
Fetched::Added
let db = self.db();
let event = if report.is_some()
&& let Some(season) = self.current_season(m.started_at_ms)
{
let range = crate::seasons::period(&self.seasons, &season.name).expect("known Season");
let (played, won, completed): (bool, bool, bool) = db.query_row(
"SELECT count(*) > 0, coalesce(max(win), 0), coalesce(min(placement) = 1, 0)
FROM matches WHERE puuid = ?1 AND champion_id = ?2
AND started_at_ms >= ?3 AND started_at_ms < ?4",
params![puuid, m.champion_id, range.start, range.end],
|row| Ok((row.get(0)?, row.get(1)?, row.get(2)?)),
)?;
let end = if !completed && m.placement == 1 {
MatchEnd::Completion
} else if !played || (!completed && !won && m.win) {
MatchEnd::Mark
} else {
MatchEnd::Nothing
};
Some(FollowedMatch {
puuid: puuid.into(),
season: season.name,
champion_id: m.champion_id,
started_at_ms: m.started_at_ms,
end,
})
} else {
Fetched::Known
})
None
};
if !insert_match(&db, puuid, &m, queue_id, &raw)? {
return Ok(Fetched::Known);
}
drop(db);
if let (Some(report), Some(event)) = (report, event) {
report(event);
}
Ok(Fetched::Added)
}
pub fn accounts(&self) -> Result<Vec<Account>, Error> {