Download champion splashes and cache their banner focus (#83)
CI / core (pull_request) Successful in 1m31s

This commit is contained in:
nessar committed 2026-11-21 14:16:58 +01:00
1 parent 3de8fd527c
commit e440d155fc
11 files changed
+488 -99

No files matched your search

+23
View File
@@ -410,6 +410,7 @@ pub struct FakeChampions {
/// The card portrait downloads fail with a network error while this is set.
card_failure: Arc<AtomicBool>,
card_calls: Arc<AtomicUsize>,
pub splash_calls: Arc<AtomicUsize>,
}
/// A small valid JPEG, tall like the loading art (40 x 60 px).
@@ -422,6 +423,18 @@ pub fn card_art() -> Vec<u8> {
out
}
/// The loading art at (59, 6) in a landscape JPEG.
pub fn splash_art() -> Vec<u8> {
let card = image::load_from_memory(&card_art()).unwrap().into_rgb8();
let mut splash = image::RgbImage::new(112, 75);
image::imageops::replace(&mut splash, &card, 59, 6);
let mut out = Vec::new();
image::codecs::jpeg::JpegEncoder::new(&mut out)
.encode_image(&splash)
.unwrap();
out
}
impl FakeChampions {
/// `champions`: (id, key, display name).
pub fn new(version: &str, champions: &[(u32, &str, &str)]) -> FakeChampions {
@@ -441,6 +454,7 @@ impl FakeChampions {
card_art: card_art(),
card_failure: Arc::default(),
card_calls: Arc::default(),
splash_calls: Arc::default(),
}
}
@@ -519,6 +533,15 @@ impl ChampionSource for FakeChampions {
}
Ok(self.card_art.clone())
}
fn splash(&self, _: &str) -> Result<Vec<u8>, SourceError> {
self.splash_calls.fetch_add(1, Ordering::SeqCst);
self.check()?;
if self.card_failure.load(Ordering::SeqCst) {
return Err(SourceError::Network("coupé".into()));
}
Ok(splash_art())
}
}
// Statistics scenarios: a small catalog, two Seasons and Matches described by champion and Placement.