- A block is written as its event arrives, from the wait for client events, with the Riot ID and client PUUID signed in at that moment: it builds the Match of that Account whoever signs in before a round gets to it. - A block whose mode nothing tells waits instead of losing its text; only a game known to be of another mode is dropped. - The follower remembers only the game in progress a Provisional Match stands for, and looks at it only when that game has just ended (follow/game_end.rs). - A Match no Season holds is still reported: its block opens its recap. - The client leaving an Arena game is told to the page once: without a block, or with the preference off, it shows the Challenge; a block decided on is not undone. - « Parties » lists the Account signed in to the client, never the pinned one. - Widening the Season for a new Match recomputes the statistics on the worker, to the Match's own Season. - A corrected Placement follows the unfolded player, or folds the details. - One Death Recap read at a time; only the latest waits, and leaving the screen drops it. - A narrow window builds its closed list no more and gives its portraits back. - The game data cache is keyed by the client's locale too, and an icon whose route changed is downloaded again. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0192He3AqGyEbouXkQJJdnQT
100 lines
3.6 KiB
Rust
100 lines
3.6 KiB
Rust
//! The player unfolded in a recap decoded again (a published or corrected Match): a new
|
|
//! Placement may reorder the teams, so the player is found again rather than their place kept.
|
|
|
|
use arena_tracker_core::{MatchRecap, RecapPlayer};
|
|
|
|
/// Where the player at `open` in `old` (teams in order) is in `new`: the Account's player, else
|
|
/// the one player with the same champion, and the same Riot ID when both give one. `None` when
|
|
/// that is not exactly one player: the details fold rather than show someone else's.
|
|
pub(super) fn same_player(old: &MatchRecap, open: usize, new: &MatchRecap) -> Option<usize> {
|
|
let player = players(old).nth(open)?;
|
|
if player.is_account {
|
|
return players(new).position(|p| p.is_account);
|
|
}
|
|
let same = |p: &RecapPlayer| {
|
|
!p.is_account
|
|
&& p.champion_id == player.champion_id
|
|
&& (p.riot_id.is_none() || player.riot_id.is_none() || p.riot_id == player.riot_id)
|
|
};
|
|
let mut found = players(new).enumerate().filter(|(_, p)| same(p));
|
|
let (index, _) = found.next()?;
|
|
found.next().is_none().then_some(index)
|
|
}
|
|
|
|
fn players(recap: &MatchRecap) -> impl Iterator<Item = &RecapPlayer> {
|
|
recap.teams.iter().flat_map(|team| team.players.iter())
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
use arena_tracker_core::{Format, RecapTeam};
|
|
|
|
fn player(champion_id: u32, riot_id: Option<&str>) -> RecapPlayer {
|
|
RecapPlayer {
|
|
champion_id,
|
|
riot_id: riot_id.map(Into::into),
|
|
..RecapPlayer::default()
|
|
}
|
|
}
|
|
|
|
fn recap(teams: Vec<Vec<RecapPlayer>>) -> MatchRecap {
|
|
MatchRecap {
|
|
match_id: "EUW1_1".into(),
|
|
provisional: false,
|
|
format: Format::Arena3x6,
|
|
started_at_ms: 0,
|
|
duration_s: None,
|
|
game_version: None,
|
|
teams: (teams.into_iter())
|
|
.map(|players| RecapTeam {
|
|
placement: None,
|
|
players,
|
|
})
|
|
.collect(),
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn the_player_is_followed_to_their_new_place() {
|
|
let old = recap(vec![
|
|
vec![player(1, Some("A#EUW")), player(2, Some("B#EUW"))],
|
|
vec![player(3, Some("C#EUW")), player(4, Some("D#EUW"))],
|
|
]);
|
|
// Published: the second team is placed first.
|
|
let new = recap(vec![
|
|
vec![player(3, Some("C#EUW")), player(4, Some("D#EUW"))],
|
|
vec![player(1, Some("A#EUW")), player(2, None)],
|
|
]);
|
|
|
|
assert_eq!(same_player(&old, 0, &new), Some(2));
|
|
assert_eq!(same_player(&old, 1, &new), Some(3), "no Riot ID in one");
|
|
assert_eq!(same_player(&old, 3, &new), Some(1));
|
|
}
|
|
|
|
#[test]
|
|
fn the_account_s_player_is_followed_whatever_its_riot_id() {
|
|
let mut alice = player(39, Some("Alice#EUW"));
|
|
alice.is_account = true;
|
|
let old = recap(vec![vec![player(1, None)], vec![alice.clone()]]);
|
|
alice.riot_id = Some("Renamed#EUW".into());
|
|
let new = recap(vec![vec![alice], vec![player(1, None)]]);
|
|
|
|
assert_eq!(same_player(&old, 1, &new), Some(0));
|
|
}
|
|
|
|
#[test]
|
|
fn an_uncertain_match_folds_the_details() {
|
|
let old = recap(vec![vec![player(1, None), player(2, Some("B#EUW"))]]);
|
|
let twice = recap(vec![vec![
|
|
player(1, Some("X#EUW")),
|
|
player(1, Some("Y#EUW")),
|
|
]]);
|
|
let other = recap(vec![vec![player(2, Some("Z#EUW"))]]);
|
|
|
|
assert_eq!(same_player(&old, 0, &twice), None, "two players fit");
|
|
assert_eq!(same_player(&old, 1, &other), None, "another Riot ID");
|
|
assert_eq!(same_player(&old, 5, &other), None, "no such player");
|
|
}
|
|
}
|