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

+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));