Tell why the home has no cards yet and tidy the cards code after review (#72)

Without statistics the home said « Aucun champion trouvé » under a count of
0; it now shows the same notice as the champ select (loading, no Account),
from a small StatsNotice enum instead of compared strings.

Also from the review: a structural test that hovering or scrolling
« Autres champions » recomputes no statistics, as docs/performance.md says;
English comments; one card aspect (core's CARD_ASPECT) and one cards_dir;
one builder for the champ select cards, one count badge, one test temp dir;
clearer names (with_cards_behaviour, home_has_own_scope).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
nessarandClaude Opus 5.5 committed 2026-11-21 02:26:14 +01:00
1 parent 213d693ab8
commit 72f7a239c0
8 files changed
+303 -106

No files matched your search

+2 -2
View File
@@ -11,8 +11,8 @@ use gpui_kit::*;
use crate::text::{ordinal, thousands};
/// Width over height.
pub const ASPECT: f32 = 0.68;
/// Width over height: the ratio the stored portraits are cropped to.
pub const ASPECT: f32 = arena_tracker_core::CARD_ASPECT as f32;
const RADIUS: f32 = 10.;
/// The border is inside the radius: the layers it holds are rounded one pixel less.
const INNER_RADIUS: f32 = RADIUS - 1.;
+8 -3
View File
@@ -322,7 +322,12 @@ impl CardGrid {
impl CardGrid {
/// The grid's key context, its portraits and what it reacts to besides its cards.
fn wired(&self, root: Div, images: Entity<CardImages>, cx: &mut Context<Self>) -> Div {
fn with_cards_behaviour(
&self,
root: Div,
images: Entity<CardImages>,
cx: &mut Context<Self>,
) -> Div {
card_images::provide(root, images)
.key_context(CONTEXT)
// A wheel scroll moves cards under a still pointer without a hover event: the
@@ -370,11 +375,11 @@ impl Render for CardGrid {
.map(|ix| self.row(ix, metrics, window, cx))
.collect();
return self
.wired(div().v_flex().w_full(), images, cx)
.with_cards_behaviour(div().v_flex().w_full(), images, cx)
.children(rows)
.into_any_element();
}
self.wired(div().relative().size_full(), images, cx)
self.with_cards_behaviour(div().relative().size_full(), images, cx)
.debug_selector(|| "card-list".into())
.child(
uniform_list(
+182 -43
View File
@@ -136,9 +136,6 @@ pub struct Page {
champ_select_account: Option<String>,
/// The Riot ID `champ_select_account` was resolved for.
champ_select_riot_id: Option<String>,
/// What the Anvil champions area says while the statistics are missing, else empty; prepared
/// when the champ select, the statistics or the status change.
champ_select_notice: SharedString,
accounts: Vec<Account>,
last_active: Option<Account>,
/// The Account the user picked instead of following the one being updated.
@@ -381,7 +378,6 @@ impl Page {
champ_select: None,
champ_select_account: None,
champ_select_riot_id: None,
champ_select_notice: SharedString::default(),
accounts: Vec::new(),
last_active: None,
pinned: None,
@@ -519,6 +515,33 @@ impl Page {
}
}
/// Why the home has no statistics to show yet, if it has none: the same for the Défi tab
/// and the champ select. Cheap enough to ask at each render.
fn stats_notice(&self) -> Option<home::StatsNotice> {
use home::StatsNotice;
if self.error().is_some() {
return Some(StatsNotice::Error);
}
if self.home_statistics().is_some() {
return None;
}
if self.home_season.is_none() {
return Some(StatsNotice::NoSeason);
}
// During a champ select the Account is the one signed in to the client, known by the
// follower's status; else it is the one viewed.
let no_account = if self.in_champ_select() {
self.status.updating.is_none()
} else {
self.viewed().is_none()
};
Some(if no_account {
StatsNotice::NoAccount
} else {
StatsNotice::Loading
})
}
/// The tab's own statistics error: the home may have computed its own.
fn error(&self) -> Option<&String> {
match (self.tab, &self.home_scope) {
@@ -1004,32 +1027,20 @@ impl Page {
self.champ_select.as_ref().map(|(_, pick)| pick)
}
/// What the Anvil champions area shows: the row's cards, or the notice that stands in
/// for them. For when the champ select, the statistics or the status change.
/// The cards of the Anvil champions row (`stats_notice` says why there are none when the
/// statistics are missing). For when the champ select, the statistics or the status change.
fn prepare_champ_select(&mut self, cx: &mut Context<Self>) {
// Statistics are missing rather than absent when they are still on their way.
self.champ_select_notice = match (&self.stats_error, self.stats.is_some()) {
(Some(error), _) => error.clone().into(),
(None, true) => SharedString::default(),
(None, false) if self.current_season.is_none() => home::NO_SEASON.into(),
(None, false) if self.status.updating.is_none() => "Compte indisponible".into(),
(None, false) => "Chargement des statistiques…".into(),
};
// The same rows in the same order as the home grid (`ordered_rows`): the
// cards keep their place whatever the champ select does. An id the rows do not know is
// skipped.
let cards: Rc<[Card]> = match self.live_champ_select() {
Some(pick) => {
let anvil = pick.anvil_champions.as_deref().unwrap_or_default();
self.ordered_rows()
.filter(|row| anvil.contains(&row.champion.id))
.map(|row| {
Card::from_row(row).with_unpickable(pick.unpickable(row.champion.id))
})
.collect()
}
None => Rc::new([]),
};
let anvil = self
.live_champ_select()
.and_then(|pick| pick.anvil_champions.as_deref())
.unwrap_or_default();
let cards = self.champ_select_cards(
self.ordered_rows()
.filter(|row| anvil.contains(&row.champion.id)),
);
self.anvil_count = cards.len().to_string().into();
let shown = (0..cards.len()).collect();
self.anvil_grid.update(cx, |grid, cx| {
@@ -1039,6 +1050,17 @@ impl Page {
self.prepare_others(cx);
}
/// The cards of `rows` during the champ select, each with the reasons it cannot be picked;
/// none outside a champ select.
fn champ_select_cards<'a>(&self, rows: impl Iterator<Item = &'a ChampionRow>) -> Rc<[Card]> {
match self.live_champ_select() {
Some(pick) => rows
.map(|row| Card::from_row(row).with_unpickable(pick.unpickable(row.champion.id)))
.collect(),
None => Rc::new([]),
}
}
/// The rows of « Autres champions »: those whose id is not an Anvil one, in the master
/// order; all of them when the client gave no list.
fn other_rows(&self) -> impl Iterator<Item = &ChampionRow> {
@@ -1055,13 +1077,7 @@ impl Page {
if !self.others_open {
return;
}
let cards: Rc<[Card]> = match self.live_champ_select() {
Some(pick) => self
.other_rows()
.map(|row| Card::from_row(row).with_unpickable(pick.unpickable(row.champion.id)))
.collect(),
None => Rc::new([]),
};
let cards = self.champ_select_cards(self.other_rows());
self.others_grid
.update(cx, |grid, cx| grid.set_cards(cards, cx));
self.refresh_others(cx);
@@ -1771,6 +1787,83 @@ mod tests {
});
}
/// Without statistics the home says why there is nothing, rather than count « 0 » champions
/// above a grid that says none matches.
fn assert_home_says(window: &mut VisualTestContext, notice: super::home::StatsNotice) {
draw(window);
assert_eq!(
window.debug_bounds("home-notice").is_some(),
!matches!(notice, super::home::StatsNotice::Error)
);
assert!(window.debug_bounds("home-tools").is_none());
assert!(window.debug_bounds("card-list").is_none());
assert!(window.debug_bounds("no-champion").is_none());
}
#[gpui::test]
fn the_home_says_why_it_has_no_cards_until_the_statistics_arrive(cx: &mut TestAppContext) {
use super::home::StatsNotice;
// A Season but no Account at all.
let (page, cx) = open_page_in_season(cx);
let cx = &mut { cx };
page.read_with(cx, |p, _| {
assert_eq!(p.stats_notice(), Some(StatsNotice::NoAccount));
assert_eq!(
p.anvil_line().as_deref(),
Some("Compte indisponible"),
"the champ select says it the same way"
);
});
assert_home_says(cx, StatsNotice::NoAccount);
// The statistics arrive: the heading and the grid show, and the notice goes.
show(&page, cx, statistics(0, 3, champions(3)));
draw(cx);
page.read_with(cx, |p, _| assert_eq!(p.stats_notice(), None));
assert!(cx.debug_bounds("home-notice").is_none());
assert!(cx.debug_bounds("home-tools").is_some());
assert!(cx.debug_bounds("card-1").is_some());
assert!(cx.debug_bounds("no-champion").is_none());
}
#[gpui::test]
async fn the_home_says_the_statistics_are_loading(cx: &mut TestAppContext) {
use super::home::StatsNotice;
cx.executor().allow_parking();
let (page, mut window) = open_page_with_tracker(cx, joueur_tracker());
cx.condition(&page, |p, _| p.stats.is_some()).await;
// The job of an Account is running: nothing is there yet.
window.update(|_, cx| {
page.update(cx, |p, cx| {
p.stats = None;
p.stats_error = None;
p.prepare_home_cards(cx);
cx.notify();
})
});
page.read_with(&window, |p, _| {
assert!(p.home_season.is_some());
assert_eq!(p.stats_notice(), Some(StatsNotice::Loading));
assert_eq!(
p.stats_notice().map(|n| n.label(None)).as_deref(),
Some("Chargement des statistiques…")
);
});
assert_home_says(&mut window, StatsNotice::Loading);
// Its error is the banner's alone.
window.update(|_, cx| {
page.update(cx, |p, cx| {
p.stats_error = Some("Statistiques indisponibles : disque plein".into());
cx.notify();
})
});
page.read_with(&window, |p, _| {
assert_eq!(p.stats_notice(), Some(StatsNotice::Error));
});
assert_home_says(&mut window, StatsNotice::Error);
}
#[gpui::test]
fn the_counter_keeps_its_total_while_a_search_and_a_filter_reduce_the_list(
cx: &mut TestAppContext,
@@ -2607,14 +2700,10 @@ mod tests {
let tracker = Tracker::open(Path::new(":memory:"), Box::new(JoueurHistory))
.unwrap()
.with_seasons(vec![season("Saison", 2020)]);
// One folder per tracker: the tests run in parallel.
static TRACKERS: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0);
let n = TRACKERS.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
let portraits =
std::env::temp_dir().join(format!("arena-tracker-74-{}-{n}", std::process::id()));
let tracker = tracker.with_champions(Box::new(Catalog), portraits.clone());
// One folder per tracker (the tests run in parallel), removed once the catalog is stored.
let portraits = crate::card_images::tests::TestDir::new("page-tracker");
let tracker = tracker.with_champions(Box::new(Catalog), portraits.path().to_path_buf());
tracker.refresh_champions().unwrap();
let _ = std::fs::remove_dir(portraits);
if mastery {
tracker.sync("Autre#EUW", &mut |_| {}).unwrap();
// Without a client, a round adopts the Riot ID it is given, then asks for the points.
@@ -2911,7 +3000,7 @@ mod tests {
page.read_with(&window, |p, _| {
assert_eq!(p.anvil_line().as_deref(), Some(line))
});
// No row, and no champion is presented as « sans enclume ».
// No row, and no champion is presented as without an anvil.
assert!(anvil_cards(&page, &mut window).is_empty());
assert!(window.debug_bounds("anvil-notice").is_some());
assert!(window.debug_bounds("anvil-row").is_none());
@@ -2928,7 +3017,7 @@ mod tests {
send(&page, &mut window, &frames()[0]);
draw(&mut window);
page.read_with(&window, |p, _| {
assert_eq!(p.champ_select_notice, "Aucune Saison en cours");
assert_eq!(p.stats_notice(), Some(super::home::StatsNotice::NoSeason));
});
assert!(window.debug_bounds("no-season").is_some());
assert!(window.debug_bounds("anvil-notice").is_none());
@@ -3110,6 +3199,56 @@ mod tests {
assert_eq!(ids(&anvil_cards(&page, &mut window)), [233]);
}
// As the home grid's test: hovering the cards of « Autres champions » or scrolling it notifies
// the grid, and costs no statistics and no cards. (The capture's catalog is too short for
// the list to scroll: the wheel still reaches the grid, which is what clears its hover.)
#[gpui::test]
async fn hovering_or_scrolling_others_does_not_recompute_the_statistics(
cx: &mut TestAppContext,
) {
let (page, mut window) = page_in_champ_select(cx, &frames()[0]).await;
click_others(&mut window);
let cx = &mut window;
let grid = page.read_with(cx, |p, _| p.others_grid.clone());
let generation = page.read_with(cx, |p, _| p.stats_generation);
let set_cards = grid.read_with(cx, |grid, _| grid.set_cards_calls);
let renders = grid.read_with(cx, |grid, _| grid.renders);
assert!(set_cards > 0 && renders > 0);
let hovers = Rc::new(Cell::new(0));
let _subscription = cx.update(|_, cx| {
let hovers = hovers.clone();
cx.observe(&grid, move |_, _| hovers.set(hovers.get() + 1))
});
for id in ["card-103", "card-12", "card-103"] {
let card = center(cx, id);
cx.simulate_mouse_move(card, None, Modifiers::none());
draw(cx);
}
assert!(hovers.get() > 0, "no card was hovered");
assert!(grid.read_with(cx, |grid, _| grid.renders) > renders);
let over = center(cx, "card-103");
cx.simulate_event(ScrollEvent {
position: over,
delta: ScrollDelta::Pixels(point(px(0.), px(-400.))),
..Default::default()
});
draw(cx);
assert_eq!(
grid.read_with(cx, |grid, _| grid.set_cards_calls),
set_cards,
"the cards were built again"
);
assert_eq!(
page.read_with(cx, |p, _| p.stats_generation),
generation,
"the statistics were computed again"
);
assert!(!page.read_with(cx, |p, _| p.stats_job.running()));
}
#[gpui::test]
async fn the_search_of_others_filters_only_that_section(cx: &mut TestAppContext) {
let (page, mut window) = page_in_champ_select(cx, &frames()[0]).await;
@@ -3517,7 +3656,7 @@ mod tests {
});
draw(&mut window);
page.read_with(&window, |p, _| {
assert_eq!(p.champ_select_notice, error);
assert_eq!(p.stats_notice(), Some(super::home::StatsNotice::Error));
assert_eq!(p.error().map(String::as_str), Some(error));
});
// The banner says it; the area says nothing and offers nothing to browse.
+92 -49
View File
@@ -23,6 +23,60 @@ pub(super) const FILTERS: [(&str, StateFilter); 3] = [
/// same cause.
pub(super) const NO_SEASON: &str = "Aucune Saison en cours";
/// Why the home has no statistics to browse yet. The home and the champ select say it the same
/// way (`label`).
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub(super) enum StatsNotice {
/// There is no Season to read: the header already says so.
NoSeason,
/// No Account to read.
NoAccount,
/// The statistics job has not returned yet.
Loading,
/// The job failed: the banner already says so.
Error,
}
impl StatsNotice {
/// The French text, `error` being the statistics' error for `Error`.
pub(super) fn label(self, error: Option<&str>) -> SharedString {
match self {
Self::NoSeason => NO_SEASON.into(),
Self::NoAccount => "Compte indisponible".into(),
Self::Loading => "Chargement des statistiques…".into(),
Self::Error => error.unwrap_or_default().to_string().into(),
}
}
/// Whether something else on the page already says it: the notice stays silent then.
fn said_elsewhere(self) -> bool {
matches!(self, Self::NoSeason | Self::Error)
}
}
/// A sober line in muted text, for what stands in place of the cards.
fn notice_line(selector: &'static str, text: SharedString, muted: Hsla) -> AnyElement {
div()
.text_sm()
.text_color(muted)
.debug_selector(move || selector.into())
.child(text)
.into_any_element()
}
/// The small bordered count beside a heading.
fn count_badge(count: SharedString, muted: Hsla, border: Hsla) -> impl IntoElement {
div()
.px(px(7.))
.py(px(2.))
.border_1()
.border_color(border)
.rounded(px(6.))
.text_xs()
.text_color(muted)
.child(count)
}
impl Page {
/// Under the banners: the Season and its counter, then the heading with the filters and
/// search, and the cards. It holds no chart (#71): the cached charts row only belongs to the
@@ -47,7 +101,7 @@ impl Page {
column = column.child(self.anvil_area(cx));
}
// With the statistics missing there is nothing to browse: the notice stands alone.
if shown("others") && self.champ_select_notice.is_empty() {
if shown("others") && self.stats_notice().is_none() {
column = column.child(self.others_area(window.viewport_size().width, cx));
}
return vec![
@@ -58,17 +112,33 @@ impl Page {
];
}
if self.home_season.is_some() {
if shown("home-tools") {
column = column.child(self.home_heading(cx));
}
if shown("cards") {
// Cached: only a change to the cards, the filter, the search or a hover or
// scroll over them draws the grid again. Its size comes from this style.
column = column.child(
self.home_grid
.clone()
.cached(StyleRefinement::default().w_full().flex_1().min_h(px(240.))),
);
match self.stats_notice() {
None => {
if shown("home-tools") {
column = column.child(self.home_heading(cx));
}
if shown("cards") {
// Cached: only a change to the cards, the filter, the search or a hover
// or scroll over them draws the grid again. Its size comes from this
// style.
column =
column.child(self.home_grid.clone().cached(
StyleRefinement::default().w_full().flex_1().min_h(px(240.)),
));
}
}
// Without statistics the heading would count « 0 » and the grid would say no
// champion matches: say why there are no cards instead (the banner has the
// error, the header the missing Season).
Some(notice) if notice.said_elsewhere() => {}
Some(notice) => {
let muted = cx.theme().muted_foreground;
column = column.child(notice_line(
"home-notice",
notice.label(self.error().map(String::as_str)),
muted,
));
}
}
}
vec![column.into_any_element()]
@@ -94,11 +164,11 @@ impl Page {
}
/// What stands in place of the Anvil champions row, if anything: the statistics are missing,
/// or the client gave no list (which does not make any champion « sans enclume »), or an
/// or the client gave no list (which does not make any champion without an anvil), or an
/// empty one.
pub(super) fn anvil_line(&self) -> Option<SharedString> {
if !self.champ_select_notice.is_empty() {
return Some(self.champ_select_notice.clone());
if let Some(notice) = self.stats_notice() {
return Some(notice.label(self.error().map(String::as_str)));
}
match &self.live_champ_select()?.anvil_champions {
None => Some("Champions de l'Enclume non communiqués par le client".into()),
@@ -114,6 +184,7 @@ impl Page {
let theme = cx.theme();
let (muted, border) = (theme.muted_foreground, theme.border);
let row = self.anvil_line();
let said_elsewhere = self.stats_notice().is_some_and(StatsNotice::said_elsewhere);
div()
.v_flex()
.gap_3()
@@ -137,17 +208,7 @@ impl Page {
.child("Champions de l'Enclume"),
)
.when(row.is_none(), |heading| {
heading.child(
div()
.px(px(7.))
.py(px(2.))
.border_1()
.border_color(border)
.rounded(px(6.))
.text_xs()
.text_color(muted)
.child(self.anvil_count.clone()),
)
heading.child(count_badge(self.anvil_count.clone(), muted, border))
}),
)
.child(self.sort_selector(cx)),
@@ -155,16 +216,8 @@ impl Page {
.children(match row {
// The header already says there is no Season, and a banner the statistics' error:
// not twice.
Some(line) if self.home_season.is_none() && line == NO_SEASON => None,
Some(line) if self.error().is_some_and(|error| line == error.as_str()) => None,
Some(line) => Some(
div()
.text_sm()
.text_color(muted)
.debug_selector(|| "anvil-notice".into())
.child(line)
.into_any_element(),
),
Some(_) if said_elsewhere => None,
Some(line) => Some(notice_line("anvil-notice", line, muted)),
None => Some(
div()
.w_full()
@@ -189,8 +242,8 @@ impl Page {
}
/// « Autres champions »: a header that folds the section, and open, its search and its
/// cards. Folded, no card is built and the grid is not even drawn. The champions are « sans
/// enclume » only when the client gave the list: else they are all of them. `window_width`
/// cards. Folded, no card is built and the grid is not even drawn. They are the champions
/// without an anvil only when the client gave the list: else they are all of them. `window_width`
/// gives the cards' size: the grid is never shorter than a whole row, and in a small window
/// the column scrolls instead.
fn others_area(&self, window_width: Pixels, cx: &mut Context<Page>) -> impl IntoElement {
@@ -283,17 +336,7 @@ impl Page {
.font_weight(FontWeight::SEMIBOLD)
.child("Mes champions"),
)
.child(
div()
.px(px(7.))
.py(px(2.))
.border_1()
.border_color(border)
.rounded(px(6.))
.text_xs()
.text_color(muted)
.child(self.home_shown_count.clone()),
),
.child(count_badge(self.home_shown_count.clone(), muted, border)),
)
.child(
div()
+6 -2
View File
@@ -319,7 +319,7 @@ pub fn spawn_statistics(
spawn_guarded(tx, Msg::Crashed, move |tx| {
// A panic is reported as this job's result, not as `Crashed`: the page's statistics job
// must end with a result whatever happens, and a crash banner is for the other workers.
let apart = home_scope.is_some();
let home_has_own_scope = home_scope.is_some();
let (stats, home, stored) = catch_unwind(AssertUnwindSafe(|| {
let stats = compute_statistics(&tracker, &puuid, &scope);
let home = home_scope.map(|home| Box::new(compute_statistics(&tracker, &puuid, &home)));
@@ -327,7 +327,11 @@ pub fn spawn_statistics(
}))
.unwrap_or_else(|_| {
let error = || "Statistiques indisponibles : erreur interne".to_string();
(Err(error()), apart.then(|| Box::new(Err(error()))), None)
(
Err(error()),
home_has_own_scope.then(|| Box::new(Err(error()))),
None,
)
});
let _ = tx.try_send(Msg::Statistics {
generation,
+10 -4
View File
@@ -92,16 +92,22 @@ impl ChampionSource for DataDragon {
const CARD_PORTRAIT_WIDTH: u32 = 308;
/// Height of a stored card portrait: `CARD_PORTRAIT_WIDTH / CARD_ASPECT`, rounded.
const CARD_PORTRAIT_HEIGHT: u32 = 453;
/// A card's width / height (the mockup's `.card { aspect-ratio: .68 }`).
const CARD_ASPECT: f64 = 0.68;
/// A card's width over its height (the mockup's `.card { aspect-ratio: .68 }`): the ratio the
/// stored card portraits are cropped to, and the one the app draws its cards at.
pub const CARD_ASPECT: f64 = 0.68;
/// Where the crop window sits in the overflow (the mockup's `object-position: 50% 24%`).
const CARD_FOCUS_X: f64 = 0.5;
const CARD_FOCUS_Y: f64 = 0.24;
const CARD_JPEG_QUALITY: u8 = 85;
/// The folder of the card portraits, in the portraits folder.
pub(crate) fn cards_dir(portraits_dir: &Path) -> PathBuf {
portraits_dir.join("cards")
}
/// Where a champion's card portrait is kept.
pub(crate) fn card_portrait_path(portraits_dir: &Path, key: &str) -> PathBuf {
portraits_dir.join("cards").join(format!("{key}.jpg"))
cards_dir(portraits_dir).join(format!("{key}.jpg"))
}
/// The crop window (x, y, width, height) that `object-fit: cover` with the card's
@@ -252,7 +258,7 @@ impl Tracker {
let Some((source, portraits_dir)) = &self.champions else {
return Ok(());
};
let cards_dir = portraits_dir.join("cards");
let cards_dir = cards_dir(portraits_dir);
std::fs::create_dir_all(&cards_dir)
.map_err(|e| Error::Storage(format!("{} : {e}", cards_dir.display())))?;
for champion in self.cached_champions()? {
+1 -1
View File
@@ -16,7 +16,7 @@ mod update_package;
pub use champ_select::{ChampSelect, ChampSelectReader, Unpickable};
pub use champion_search::ChampionSearch;
pub use champions::{Champion, ChampionCatalog, ChampionSource, DataDragon};
pub use champions::{CARD_ASPECT, Champion, ChampionCatalog, ChampionSource, DataDragon};
pub use client::{ClientError, ClientEvent, ClientSnapshot, GameClientSource, GamePhase, Gameflow};
pub use config::{ChampionSort, Config, Preferences, ThemePreference, UpdateChannel, data_dir};
pub use date::Date;
+2 -2
View File
@@ -5,7 +5,7 @@ use std::ffi::{OsStr, OsString};
use std::ops::Range;
use std::path::{Path, PathBuf};
use crate::champions::{Champion, card_portrait_path};
use crate::champions::{Champion, card_portrait_path, cards_dir};
use crate::date::Date;
use crate::error::Error;
use crate::model::{Format, Match};
@@ -461,7 +461,7 @@ impl Tracker {
if let Some((_, dir)) = &self.champions {
// One read of each folder rather than a file check per champion and per portrait.
let squares = file_names(dir);
let cards = file_names(&dir.join("cards"));
let cards = file_names(&cards_dir(dir));
for row in &mut stats.rows {
let name = format!("{}.png", row.champion.key);
row.portrait = squares.contains(OsStr::new(&name)).then(|| dir.join(name));