use super::{ChampSelectTransition, Page, Tab}; use crate::worker::LiveChampSelect; use arena_tracker_core::{account_riot_id, same_riot_id}; use gpui_kit::*; pub(in crate::page) const UNKNOWN_ANVIL: &str = "Champions de l'Enclume non communiqués par le client"; mod cards; mod motion; mod render; impl Page { /// The Account of the phase: the live champ select's, else the Live Match's. Resolved when /// the signed-in Riot ID changes (or the Accounts do), so preparing statistics builds no /// Riot ID per Account every time. pub(in crate::page) fn phase_account(&mut self) -> Option { let id = (self.champ_select.as_ref().map(|(id, _)| id.as_str())) .or(self.live_match.as_ref().map(|live| live.riot_id.as_str()))?; if self.phase_riot_id.as_deref() != Some(id) { self.phase_riot_id = Some(id.into()); self.phase_account = self .accounts .iter() .find(|a| same_riot_id(&account_riot_id(a), id)) .map(|a| a.puuid.clone()); } self.phase_account.clone() } /// The phase's Account and the current Season stand in for the home's, or the home's come /// back: what was computed for the scope left goes while the new one loads. pub(in crate::page) fn rescope(&mut self, window: &mut Window, cx: &mut Context) { // The Account belongs to the signed-in Riot ID: resolve it once, not on every // statistics preparation. self.phase_riot_id = None; self.stats_generation += 1; self.stats = None; self.stats_error = None; self.forget_home(); self.stored = None; self.reorder(); self.reload_in_background(window, cx); // Nor does the banner keep the previous scope's Challenge while the new one loads: its // Season, its ticks and its splash go with the statistics. self.prepare_banner(cx); } /// The champ select the client reports changed: entered, left, another one, or the same /// one with new picks and bans. pub(in crate::page) fn change_champ_select( &mut self, champ_select: LiveChampSelect, window: &mut Window, cx: &mut Context, ) { let previous = self.champ_select.as_ref(); let next = champ_select.as_ref(); let changed_page = previous.is_some() != next.is_some(); let switch = changed_page || previous.map(|(id, _)| id) != next.map(|(id, _)| id); // The game it launched is the same Account's in the same Season: its statistics stay. let launched = next.is_none() && (previous.zip(self.live_match.as_ref())) .is_some_and(|((id, _), live)| same_riot_id(id, &live.riot_id)); self.champ_select = champ_select; if changed_page { if self.in_champ_select() { // Nothing plays during a champ select: what waited is no longer news. self.stop_holding(); self.end_match(cx); // The phase decides: « Sélection » shows, whatever screen was open, at once (its // entry's band of light is the transition). self.tab = Tab::ChampSelect; self.lifts.clear(); self.end_fade(window, cx); // Its entry plays once the window shows it (#63 reveals it without focus). self.entry_waiting = true; } else { self.forget_stage(); self.reset_home_view(window, cx); self.anvil_grid .update(cx, |grid, cx| grid.release_images(window, cx)); // An animation asked for during the champ select plays on the home. self.playback.stats_pending = self.playback.active(); // The phase decides: « Sélection » goes, and « Défi » shows, from wherever the // player was (under the veil the hand left for, when it left); « En partie » // when the champ select launched the game. let next = if self.in_live_match() { Tab::InGame } else { Tab::Challenge }; self.set_tab(next, window, cx); } } if switch { // A new champ select starts with « Autres champions » folded and searchless, at the // top of the page. self.fold_others(window, cx); self.paging.scroll.set_offset(point(px(0.), px(0.))); if launched { // Only the banner stops being the champ select's. self.prepare_banner(cx); } else { // The phase shows the active Account, and so does the page after it. self.show_account(None, window, cx); } } if changed_page { cx.emit(ChampSelectTransition { entered: self.in_champ_select(), }); } // The hand as it was, to see which card an ally just took. let before = (!switch).then(|| self.anvil_grid.read(cx).cards().clone()); // Any change (a hover or a lock-in too) changes the reasons of the cards. Only // the client's events get here: no polling. self.prepare_champ_select(cx); if let Some(before) = before { self.lower_taken(&before, window, cx); } self.start_entry(window, cx); } }