Tighten module organization after second review (#103)
CI / core (pull_request) Successful in 1m35s
CI / core (pull_request) Successful in 1m35s
This commit is contained in:
1 parent
e56da040e5
commit
242ecc4f28
31 files changed
+545
-492
No files matched your search
@@ -16,7 +16,7 @@ When adding behavior or tests would grow a Rust file and leave it above 500 line
|
||||
- Keep small unit-test suites next to the implementation in an inline `#[cfg(test)] mod tests { ... }`. The child module can access private items in its parent.
|
||||
- Move larger unit-test suites to a child file such as `src/ring/tests.rs`, declared with `#[cfg(test)] mod tests;`. Split suites by behavior as they grow.
|
||||
- Group integration tests by behavior in the package's top-level `tests/` directory and exercise the public API.
|
||||
- Write runnable API examples as Rust code blocks in `///` doc comments so they run as doc tests.
|
||||
- When documenting a runnable API example, use a Rust code block in the item's `///` comments so `cargo test` checks it.
|
||||
|
||||
## Agent skills
|
||||
|
||||
|
||||
+12
-12
@@ -35,7 +35,7 @@ use geometry::{MAX_COLUMNS, Metrics};
|
||||
pub use geometry::{MAX_WIDTH, TAKEN_DROP, row_height};
|
||||
|
||||
mod layout;
|
||||
pub use layout::{CardHovered, Placed, Placements, PutDown};
|
||||
pub use layout::{CardHovered, CardPosition, CardPositions, PutDown};
|
||||
|
||||
/// What makes one card reachable with the keyboard: its handle, and the subscriptions that lift
|
||||
/// it while the keyboard is on it.
|
||||
@@ -54,7 +54,7 @@ pub struct CardGrid {
|
||||
/// The card under the pointer or the keyboard, which is lifted.
|
||||
hovered: Option<u32>,
|
||||
/// Where the visible cards were drawn last.
|
||||
placed: Placements,
|
||||
positions: CardPositions,
|
||||
/// How far the list was scrolled when last drawn: a wheel that leaves it there (at either
|
||||
/// end) moves no card from under the pointer.
|
||||
drawn_scroll: Pixels,
|
||||
@@ -86,7 +86,7 @@ impl CardGrid {
|
||||
shown: Vec::new(),
|
||||
scroll: UniformListScrollHandle::new(),
|
||||
hovered: None,
|
||||
placed: Placements::default(),
|
||||
positions: CardPositions::default(),
|
||||
drawn_scroll: Pixels::ZERO,
|
||||
focus: HashMap::new(),
|
||||
focus_stale: false,
|
||||
@@ -251,7 +251,7 @@ impl CardGrid {
|
||||
// Nor is any of its cards under the pointer: the ring's tick goes out.
|
||||
self.hover(None, cx);
|
||||
cx.emit(PutDown);
|
||||
self.placed.borrow_mut().clear();
|
||||
self.positions.borrow_mut().clear();
|
||||
let released = self
|
||||
.images
|
||||
.as_ref()
|
||||
@@ -305,11 +305,11 @@ impl CardGrid {
|
||||
}
|
||||
|
||||
/// Where its visible cards were drawn last.
|
||||
pub fn placed(&self) -> &Placements {
|
||||
&self.placed
|
||||
pub fn positions(&self) -> &CardPositions {
|
||||
&self.positions
|
||||
}
|
||||
|
||||
/// All its cards, which `Placed::ix` indexes.
|
||||
/// All its cards, which `CardPosition::ix` indexes.
|
||||
pub fn cards(&self) -> &Rc<[Card]> {
|
||||
&self.cards
|
||||
}
|
||||
@@ -357,7 +357,7 @@ impl CardGrid {
|
||||
None => slots.push(div().flex_1().min_w_0().into_any_element()),
|
||||
}
|
||||
}
|
||||
let placed = self.placed.clone();
|
||||
let positions = self.positions.clone();
|
||||
div()
|
||||
.h_flex()
|
||||
.items_start()
|
||||
@@ -369,12 +369,12 @@ impl CardGrid {
|
||||
// Only a row painted is laid out here, not one `uniform_list` merely measures.
|
||||
.on_children_prepainted(move |bounds, window, _| {
|
||||
let visible = window.content_mask().bounds;
|
||||
let mut placed = placed.borrow_mut();
|
||||
let mut positions = positions.borrow_mut();
|
||||
for (slot, bounds) in placing.iter().zip(bounds) {
|
||||
if let Some((id, ix)) = *slot {
|
||||
placed.insert(
|
||||
positions.insert(
|
||||
id,
|
||||
Placed {
|
||||
CardPosition {
|
||||
bounds,
|
||||
visible,
|
||||
ix,
|
||||
@@ -429,7 +429,7 @@ impl Render for CardGrid {
|
||||
}
|
||||
self.drawn_scroll = self.scrolled_to();
|
||||
// Only the rows drawn now place their cards.
|
||||
self.placed.borrow_mut().clear();
|
||||
self.positions.borrow_mut().clear();
|
||||
let images = (self.images)
|
||||
.get_or_insert_with(|| CardImages::new(cx))
|
||||
.clone();
|
||||
|
||||
@@ -20,11 +20,11 @@ pub struct PutDown;
|
||||
/// Where the grid last drew a card, in the window, the part of the window it showed of it, and
|
||||
/// its index in the grid's cards.
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
pub struct Placed {
|
||||
pub struct CardPosition {
|
||||
pub bounds: Bounds<Pixels>,
|
||||
pub visible: Bounds<Pixels>,
|
||||
pub ix: usize,
|
||||
}
|
||||
|
||||
/// The cards the grid drew last, by id: filled as its rows are laid out, read between its draws.
|
||||
pub type Placements = Rc<RefCell<HashMap<u32, Placed>>>;
|
||||
pub type CardPositions = Rc<RefCell<HashMap<u32, CardPosition>>>;
|
||||
@@ -9,7 +9,7 @@ use gpui_kit::component::ActiveTheme as _;
|
||||
use gpui_kit::*;
|
||||
|
||||
use crate::card::{CARD_RADIUS, Card, MarkFill, Pose, lifted, veil_color};
|
||||
use crate::card_grid::{Placed, Placements};
|
||||
use crate::card_grid::{CardPosition, CardPositions};
|
||||
use crate::card_images::CardImages;
|
||||
use crate::motion::{MATCH_SETTLE, ease_out};
|
||||
|
||||
@@ -217,7 +217,7 @@ pub(crate) enum Changes {
|
||||
/// stays cut where it is. The cards `changes` names show their change.
|
||||
pub(crate) fn layer(
|
||||
cards: Rc<[Card]>,
|
||||
placed: Placements,
|
||||
positions: CardPositions,
|
||||
images: Option<Entity<CardImages>>,
|
||||
lifted_cards: Vec<Lifted>,
|
||||
changes: Changes,
|
||||
@@ -227,18 +227,18 @@ pub(crate) fn layer(
|
||||
deferred(
|
||||
canvas(
|
||||
move |_, window, cx| {
|
||||
let placed = placed.borrow();
|
||||
let positions = positions.borrow();
|
||||
let background = cx.theme().background;
|
||||
let mut layers = Vec::new();
|
||||
if veil > 0. {
|
||||
for (id, place) in placed.iter() {
|
||||
for (id, place) in positions.iter() {
|
||||
if !lifted_cards.iter().any(|lifted| lifted.id == *id) {
|
||||
layers.push(Layer::Quad(place.bounds, veil_color(veil), place.visible));
|
||||
}
|
||||
}
|
||||
}
|
||||
for &Lifted { id, progress } in &lifted_cards {
|
||||
let place = placed.get(&id);
|
||||
let place = positions.get(&id);
|
||||
let card = place.and_then(|place| cards.get(place.ix));
|
||||
let (Some(place), Some(card)) = (place, card) else {
|
||||
continue;
|
||||
@@ -306,7 +306,7 @@ pub(crate) fn layer(
|
||||
/// Where a lifted card is cut: nowhere when its grid shows it whole, so it rises out of a
|
||||
/// scrolling list, else where the grid cuts it. A fraction of a pixel of layout or scrolling
|
||||
/// does not cut a card flush with the list's edge.
|
||||
pub(crate) fn cut(place: &Placed) -> Option<Bounds<Pixels>> {
|
||||
pub(crate) fn cut(place: &CardPosition) -> Option<Bounds<Pixels>> {
|
||||
const SLACK: f32 = 1.;
|
||||
let (card, shown) = (place.bounds, place.visible);
|
||||
let whole = card.top().as_f32() >= shown.top().as_f32() - SLACK
|
||||
|
||||
@@ -3,7 +3,7 @@ use std::time::{Duration, Instant};
|
||||
use gpui_kit::{Bounds, point, px, size};
|
||||
|
||||
use super::{Lifts, cut};
|
||||
use crate::card_grid::Placed;
|
||||
use crate::card_grid::CardPosition;
|
||||
|
||||
const GRID: u32 = 1;
|
||||
|
||||
@@ -140,8 +140,8 @@ fn finishing_shows_the_end_state_at_once_and_nothing_moves_any_more() {
|
||||
assert_eq!(lifts.veil(GRID, start), 0.);
|
||||
}
|
||||
|
||||
fn placed(top: f32, list_top: f32) -> Placed {
|
||||
Placed {
|
||||
fn card_position(top: f32, list_top: f32) -> CardPosition {
|
||||
CardPosition {
|
||||
bounds: Bounds::new(point(px(12.), px(top)), size(px(240.), px(350.))),
|
||||
visible: Bounds::new(point(px(12.), px(list_top)), size(px(1256.), px(480.))),
|
||||
ix: 0,
|
||||
@@ -152,14 +152,14 @@ fn placed(top: f32, list_top: f32) -> Placed {
|
||||
fn a_card_the_list_shows_whole_rises_out_of_it() {
|
||||
// The first row, flush with the list's top edge, give or take a fraction of a pixel of
|
||||
// layout or scrolling.
|
||||
assert_eq!(cut(&placed(583., 583.)), None);
|
||||
assert_eq!(cut(&placed(582.7, 583.)), None);
|
||||
assert_eq!(cut(&placed(583.3, 583.)), None);
|
||||
assert_eq!(cut(&card_position(583., 583.)), None);
|
||||
assert_eq!(cut(&card_position(582.7, 583.)), None);
|
||||
assert_eq!(cut(&card_position(583.3, 583.)), None);
|
||||
// A column of a fractional width: the bounds' intersection with the list differs from
|
||||
// the card by a rounding error, which cut the first row's lifted card (#88).
|
||||
let column = Placed {
|
||||
let column = CardPosition {
|
||||
bounds: Bounds::new(point(px(533.3333), px(583.)), size(px(240.66666), px(357.))),
|
||||
..placed(583., 583.)
|
||||
..card_position(583., 583.)
|
||||
};
|
||||
assert_ne!(column.visible.intersect(&column.bounds), column.bounds);
|
||||
assert_eq!(cut(&column), None);
|
||||
@@ -167,8 +167,8 @@ fn a_card_the_list_shows_whole_rises_out_of_it() {
|
||||
|
||||
#[test]
|
||||
fn a_card_the_list_shows_in_part_stays_cut_where_it_is() {
|
||||
let half_scrolled = placed(400., 583.);
|
||||
let half_scrolled = card_position(400., 583.);
|
||||
assert_eq!(cut(&half_scrolled), Some(half_scrolled.visible));
|
||||
let below = placed(900., 583.);
|
||||
let below = card_position(900., 583.);
|
||||
assert_eq!(cut(&below), Some(below.visible));
|
||||
}
|
||||
+13
-40
@@ -1,5 +1,4 @@
|
||||
//! The page and its two tabs: the shared state, the header row with its navigation and the
|
||||
//! alerts. `home`, `champ_select` and `statistics` render the content under the alerts.
|
||||
//! The page state and navigation for the home, champ select and statistics screens.
|
||||
|
||||
use crate::banner_art::BannerArt;
|
||||
use crate::card::Card;
|
||||
@@ -14,6 +13,7 @@ use arena_tracker_core::{
|
||||
Account, ChampionSearch, ChampionSort, Format, Scope, SeasonScope, StateFilter, Statistics,
|
||||
Status, SyncProgress, Tracker,
|
||||
};
|
||||
pub use display::shown;
|
||||
use gpui_kit::base::Button as BaseButton;
|
||||
use gpui_kit::base::async_util::Sender;
|
||||
use gpui_kit::component::input::InputState;
|
||||
@@ -27,8 +27,19 @@ use std::rc::Rc;
|
||||
use std::sync::Arc;
|
||||
use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH};
|
||||
|
||||
mod cards;
|
||||
mod champ_select;
|
||||
mod display;
|
||||
mod home;
|
||||
mod hover;
|
||||
mod lifecycle;
|
||||
mod playback;
|
||||
mod setup;
|
||||
mod statistics;
|
||||
mod worker_messages;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
/// The page's padding on every side: the card grid derives its width from it.
|
||||
pub(crate) const PAGE_PADDING: f32 = 12.;
|
||||
@@ -48,32 +59,6 @@ fn now_ms() -> i64 {
|
||||
.map_or(0, |d| d.as_millis() as i64)
|
||||
}
|
||||
|
||||
/// Hides page parts for issue #27 measurements only with `--features profile`.
|
||||
#[inline]
|
||||
pub fn shown(part: &str) -> bool {
|
||||
#[cfg(feature = "profile")]
|
||||
{
|
||||
static HIDDEN: std::sync::OnceLock<Vec<String>> = std::sync::OnceLock::new();
|
||||
!HIDDEN
|
||||
.get_or_init(|| {
|
||||
std::env::var("ARENA_TRACKER_HIDE")
|
||||
.unwrap_or_default()
|
||||
.split(',')
|
||||
.map(str::trim)
|
||||
.filter(|part| !part.is_empty())
|
||||
.map(str::to_owned)
|
||||
.collect()
|
||||
})
|
||||
.iter()
|
||||
.any(|hidden| hidden == part)
|
||||
}
|
||||
#[cfg(not(feature = "profile"))]
|
||||
{
|
||||
let _ = part;
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
/// One Account in the selector; its value is the puuid.
|
||||
#[derive(Clone, PartialEq)]
|
||||
struct AccountItem {
|
||||
@@ -312,18 +297,6 @@ pub struct Page {
|
||||
_listener: Task<()>,
|
||||
}
|
||||
|
||||
mod cards;
|
||||
mod champ_select;
|
||||
mod display;
|
||||
mod hover;
|
||||
mod lifecycle;
|
||||
mod playback;
|
||||
mod setup;
|
||||
mod worker_messages;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
impl Page {
|
||||
/// The two tabs as buttons: they take the keyboard focus, and Enter or Space activates them.
|
||||
fn navigation(&self, cx: &mut Context<Self>) -> impl IntoElement {
|
||||
|
||||
@@ -8,12 +8,12 @@ use std::rc::Rc;
|
||||
impl Page {
|
||||
/// Computes the cards' order again: for when the home statistics (the champ select's during
|
||||
/// a champ select) or the sort change, and for nothing else.
|
||||
pub(super) fn reorder(&mut self) {
|
||||
pub(in crate::page) fn reorder(&mut self) {
|
||||
self.order = self.sorted_order();
|
||||
}
|
||||
|
||||
/// The cards' order for the home statistics and the sort.
|
||||
pub(super) fn sorted_order(&mut self) -> Vec<usize> {
|
||||
pub(in crate::page) fn sorted_order(&mut self) -> Vec<usize> {
|
||||
#[cfg(test)]
|
||||
{
|
||||
self.reorders += 1;
|
||||
@@ -27,7 +27,7 @@ impl Page {
|
||||
|
||||
/// The pointer left the home grid it held still: the grid prepared when the statistics
|
||||
/// arrived takes its place, built and sorted already.
|
||||
pub(super) fn release_home(&mut self, cx: &mut Context<Self>) {
|
||||
pub(in crate::page) fn release_home(&mut self, cx: &mut Context<Self>) {
|
||||
let held = std::mem::take(&mut self.hold_grid);
|
||||
let Some(next) = self.next_home.take().filter(|_| held) else {
|
||||
return;
|
||||
@@ -42,21 +42,21 @@ impl Page {
|
||||
|
||||
/// The player changed the home's filter or search: the grid follows at once, even under the
|
||||
/// pointer or with a card kept for its Match.
|
||||
pub(super) fn home_filtered(&mut self, cx: &mut Context<Self>) {
|
||||
pub(in crate::page) fn home_filtered(&mut self, cx: &mut Context<Self>) {
|
||||
self.release_home(cx);
|
||||
self.playback.kept_card = None;
|
||||
self.refresh_home(cx);
|
||||
}
|
||||
|
||||
/// The home grid no longer waits for the pointer to leave: what comes next rebuilds it.
|
||||
pub(super) fn stop_holding(&mut self) {
|
||||
pub(in crate::page) fn stop_holding(&mut self) {
|
||||
self.hold_grid = false;
|
||||
self.next_home = None;
|
||||
}
|
||||
|
||||
/// The home statistics' rows in the cards' order: the single iteration the home grid, the
|
||||
/// Anvil champions and « Autres champions » all follow.
|
||||
pub(super) fn ordered_rows(&self) -> impl Iterator<Item = &ChampionRow> {
|
||||
pub(in crate::page) fn ordered_rows(&self) -> impl Iterator<Item = &ChampionRow> {
|
||||
let rows = self
|
||||
.home_statistics()
|
||||
.map_or(&[][..], |s| s.rows.as_slice());
|
||||
@@ -83,7 +83,7 @@ impl Page {
|
||||
|
||||
/// One card per champion, in the cards' order, for when the statistics or the sort change.
|
||||
/// While the home is not shown the next switch to it does (`home_cards_stale`).
|
||||
pub(super) fn prepare_home_cards(&mut self, cx: &mut Context<Self>) {
|
||||
pub(in crate::page) fn prepare_home_cards(&mut self, cx: &mut Context<Self>) {
|
||||
if self.shown_tab != Tab::Challenge {
|
||||
self.home_cards_stale = true;
|
||||
return;
|
||||
@@ -96,7 +96,7 @@ impl Page {
|
||||
|
||||
/// At the end of a champ select the home is as at launch: « Tous » and an empty search. The
|
||||
/// Account and Season viewed were never touched.
|
||||
pub(super) fn reset_home_view(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
||||
pub(in crate::page) fn reset_home_view(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
||||
self.home_filter = StateFilter::All;
|
||||
self.home_search = ChampionSearch::new("");
|
||||
self.home_search_input
|
||||
@@ -104,7 +104,7 @@ impl Page {
|
||||
}
|
||||
|
||||
/// Rebuilds the Statistics tab's rows; while it is not shown, the next switch does.
|
||||
pub(super) fn refresh_table(&mut self, cx: &mut Context<Self>) {
|
||||
pub(in crate::page) fn refresh_table(&mut self, cx: &mut Context<Self>) {
|
||||
if self.shown_tab != Tab::Statistics {
|
||||
return;
|
||||
}
|
||||
@@ -122,7 +122,7 @@ impl Page {
|
||||
|
||||
/// Recomputes which cards the home shows from its own filter and search, with the total
|
||||
/// untouched; while the home is not shown, the next switch does.
|
||||
pub(super) fn refresh_home(&mut self, cx: &mut Context<Self>) {
|
||||
pub(in crate::page) fn refresh_home(&mut self, cx: &mut Context<Self>) {
|
||||
if self.shown_tab != Tab::Challenge || self.in_champ_select() {
|
||||
return;
|
||||
}
|
||||
@@ -144,7 +144,7 @@ impl Page {
|
||||
/// The cards the home's filter and search keep, as indices of its cards in `order`. The
|
||||
/// card of a followed Match's champion that was shown stays until its animation ends, so
|
||||
/// that it changes in place (#89).
|
||||
pub(super) fn home_shown(&self, order: &[usize]) -> Vec<usize> {
|
||||
pub(in crate::page) fn home_shown(&self, order: &[usize]) -> Vec<usize> {
|
||||
let rows = self
|
||||
.home_statistics()
|
||||
.map_or(&[][..], |s| s.rows.as_slice());
|
||||
|
||||
@@ -3,7 +3,8 @@ use crate::worker::LiveChampSelect;
|
||||
use arena_tracker_core::{account_riot_id, same_riot_id};
|
||||
use gpui_kit::*;
|
||||
|
||||
pub(super) const UNKNOWN_ANVIL: &str = "Champions de l'Enclume non communiqués par le client";
|
||||
pub(in crate::page) const UNKNOWN_ANVIL: &str =
|
||||
"Champions de l'Enclume non communiqués par le client";
|
||||
|
||||
mod cards;
|
||||
mod motion;
|
||||
@@ -1,6 +1,6 @@
|
||||
use super::super::{Page, home};
|
||||
use crate::card::Card;
|
||||
use crate::card_grid::CardGrid;
|
||||
use crate::page::{Page, home};
|
||||
use arena_tracker_core::{ChampSelect, ChampionRow, ChampionSearch};
|
||||
use gpui_kit::*;
|
||||
use std::rc::Rc;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use super::super::Page;
|
||||
use crate::card::{Card, Reason};
|
||||
use crate::card_grid::CardGrid;
|
||||
use crate::motion::Fade;
|
||||
use crate::page::Page;
|
||||
use crate::stage::{self, BEFORE_VEIL, Entry, HandAt, HandMotion, Leave, Taken};
|
||||
use gpui_kit::*;
|
||||
use std::rc::Rc;
|
||||
@@ -135,7 +135,7 @@ impl Page {
|
||||
// A card under the pointer or the keyboard is drawn: the grid knows where it is.
|
||||
let ix = grid
|
||||
.read(cx)
|
||||
.placed()
|
||||
.positions()
|
||||
.borrow()
|
||||
.get(&id)
|
||||
.map(|place| place.ix);
|
||||
@@ -221,7 +221,7 @@ impl Page {
|
||||
let grid = self.anvil_grid.read(cx);
|
||||
Some(stage::hand_layer(
|
||||
grid.cards().clone(),
|
||||
grid.placed().clone(),
|
||||
grid.positions().clone(),
|
||||
grid.images().cloned(),
|
||||
motion,
|
||||
))
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
use super::super::{
|
||||
use super::UNKNOWN_ANVIL;
|
||||
use crate::card_grid::row_height;
|
||||
use crate::page::{
|
||||
Page,
|
||||
home::{StatsNotice, count_badge, notice_line},
|
||||
};
|
||||
use super::UNKNOWN_ANVIL;
|
||||
use crate::card_grid::row_height;
|
||||
use crate::theme::heading;
|
||||
use gpui_kit::base::Button as BaseButton;
|
||||
use gpui_kit::component::input::Input;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use super::{PAGE_PADDING, Page, Tab, shown};
|
||||
use super::{PAGE_PADDING, Page, Tab};
|
||||
use crate::stage;
|
||||
use crate::text::{CLIENT_ABSENT, official_differs, sync_line};
|
||||
#[cfg(test)]
|
||||
@@ -10,9 +10,35 @@ use gpui_kit::component::{ActiveTheme as _, Sizable as _, StyledExt as _};
|
||||
use gpui_kit::prelude::FluentBuilder as _;
|
||||
use gpui_kit::*;
|
||||
|
||||
/// Hides page parts for issue #27 measurements only with `--features profile`.
|
||||
#[inline]
|
||||
pub fn shown(part: &str) -> bool {
|
||||
#[cfg(feature = "profile")]
|
||||
{
|
||||
static HIDDEN: std::sync::OnceLock<Vec<String>> = std::sync::OnceLock::new();
|
||||
!HIDDEN
|
||||
.get_or_init(|| {
|
||||
std::env::var("ARENA_TRACKER_HIDE")
|
||||
.unwrap_or_default()
|
||||
.split(',')
|
||||
.map(str::trim)
|
||||
.filter(|part| !part.is_empty())
|
||||
.map(str::to_owned)
|
||||
.collect()
|
||||
})
|
||||
.iter()
|
||||
.any(|hidden| hidden == part)
|
||||
}
|
||||
#[cfg(not(feature = "profile"))]
|
||||
{
|
||||
let _ = part;
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
impl Page {
|
||||
/// One line each, the most important first; the stored data stays visible under all.
|
||||
pub(super) fn status_alerts(&self) -> Vec<AnyElement> {
|
||||
fn status_alerts(&self) -> Vec<AnyElement> {
|
||||
let mut banners = Vec::new();
|
||||
if let Some(problem) = &self.status.problem {
|
||||
let message = problem.message();
|
||||
@@ -45,7 +71,7 @@ impl Page {
|
||||
}
|
||||
|
||||
/// The veil's opacity over the screen shown, 0 at rest.
|
||||
pub(super) fn veil(&self, cx: &App) -> f32 {
|
||||
pub(in crate::page) fn veil(&self, cx: &App) -> f32 {
|
||||
self.fade
|
||||
.as_ref()
|
||||
.map_or(0., |fade| fade.veil(cx.background_executor().now()))
|
||||
|
||||
+69
-14
@@ -1,6 +1,6 @@
|
||||
//! The « Défi » tab, the home: the Challenge of one Season, and its champions.
|
||||
|
||||
use arena_tracker_core::{SeasonScope, StateFilter, Statistics};
|
||||
use arena_tracker_core::{Scope, SeasonScope, StateFilter, Statistics};
|
||||
use gpui_kit::component::input::Input;
|
||||
use gpui_kit::component::select::Select;
|
||||
use gpui_kit::component::tab::{Tab, TabBar};
|
||||
@@ -10,25 +10,25 @@ use gpui_kit::*;
|
||||
mod banner;
|
||||
mod content;
|
||||
|
||||
pub(super) use content::{BannerContent, Line};
|
||||
pub(in crate::page) use content::{BannerContent, Line};
|
||||
|
||||
use super::{Page, shown};
|
||||
use crate::card_grid::MAX_WIDTH;
|
||||
use crate::theme::heading;
|
||||
|
||||
/// The filters on offer, whatever the Season.
|
||||
pub(super) const FILTERS: [(&str, StateFilter); 3] = [
|
||||
pub(in crate::page) const FILTERS: [(&str, StateFilter); 3] = [
|
||||
("Tous", StateFilter::All),
|
||||
("Restants", StateFilter::Remaining),
|
||||
("Validés", StateFilter::Completed),
|
||||
];
|
||||
|
||||
pub(super) const NO_SEASON: &str = "Aucune Saison en cours";
|
||||
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 {
|
||||
pub(in crate::page) enum StatsNotice {
|
||||
/// There is no Season to read: the banner already says so.
|
||||
NoSeason,
|
||||
/// No Account to read.
|
||||
@@ -41,7 +41,7 @@ pub(super) enum StatsNotice {
|
||||
|
||||
impl StatsNotice {
|
||||
/// The French text, `error` being the statistics' error for `Error`.
|
||||
pub(super) fn label(self, error: Option<&str>) -> SharedString {
|
||||
pub(in crate::page) fn label(self, error: Option<&str>) -> SharedString {
|
||||
match self {
|
||||
Self::NoSeason => NO_SEASON.into(),
|
||||
Self::NoAccount => "Compte indisponible".into(),
|
||||
@@ -51,13 +51,17 @@ impl StatsNotice {
|
||||
}
|
||||
|
||||
/// Whether something else on the page already says it: the notice stays silent then.
|
||||
pub(super) fn said_elsewhere(self) -> bool {
|
||||
pub(in crate::page) 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.
|
||||
pub(super) fn notice_line(selector: &'static str, text: SharedString, muted: Hsla) -> AnyElement {
|
||||
pub(in crate::page) fn notice_line(
|
||||
selector: &'static str,
|
||||
text: SharedString,
|
||||
muted: Hsla,
|
||||
) -> AnyElement {
|
||||
div()
|
||||
.text_sm()
|
||||
.text_color(muted)
|
||||
@@ -67,7 +71,11 @@ pub(super) fn notice_line(selector: &'static str, text: SharedString, muted: Hsl
|
||||
}
|
||||
|
||||
/// The small bordered count beside a heading.
|
||||
pub(super) fn count_badge(count: SharedString, muted: Hsla, border: Hsla) -> impl IntoElement {
|
||||
pub(in crate::page) fn count_badge(
|
||||
count: SharedString,
|
||||
muted: Hsla,
|
||||
border: Hsla,
|
||||
) -> impl IntoElement {
|
||||
div()
|
||||
.px(px(7.))
|
||||
.py(px(2.))
|
||||
@@ -80,13 +88,60 @@ pub(super) fn count_badge(count: SharedString, muted: Hsla, border: Hsla) -> imp
|
||||
}
|
||||
|
||||
impl Page {
|
||||
/// The Season of the home's Challenge, and the scope to compute for it when the Statistics
|
||||
/// tab's does not already cover it. The Format never applies to the home.
|
||||
pub(in crate::page) fn settle_home_scope(&mut self) {
|
||||
let season = match &self.season {
|
||||
SeasonScope::Season(name) => Some(name),
|
||||
// A Challenge belongs to one Season: the current one stands in.
|
||||
SeasonScope::AllSeasons => self.current_season.as_ref(),
|
||||
};
|
||||
self.home_season = season.map(|name| name.clone().into());
|
||||
let home = season.map(|name| Scope {
|
||||
season: SeasonScope::Season(name.clone()),
|
||||
format: None,
|
||||
});
|
||||
self.home_scope = home.filter(|home| *home != self.statistics_scope());
|
||||
}
|
||||
|
||||
/// Keeps what was computed for the home's own scope, if it had one, and for which Account.
|
||||
pub(in crate::page) fn set_home_result(
|
||||
&mut self,
|
||||
home: Option<Box<Result<Statistics, String>>>,
|
||||
) {
|
||||
self.home_computed = home
|
||||
.as_ref()
|
||||
.and_then(|_| self.shown.clone().zip(self.home_scope.clone()));
|
||||
(self.home_stats, self.home_error) = match home.map(|result| *result) {
|
||||
Some(Ok(stats)) => (Some(stats), None),
|
||||
Some(Err(error)) => (None, Some(error)),
|
||||
None => (None, None),
|
||||
};
|
||||
}
|
||||
|
||||
pub(in crate::page) fn forget_home(&mut self) {
|
||||
self.home_stats = None;
|
||||
self.home_error = None;
|
||||
self.home_computed = None;
|
||||
}
|
||||
|
||||
/// Whether the home's own statistics were computed for the Account and scope it has now.
|
||||
pub(in crate::page) fn home_is_current(&self) -> bool {
|
||||
match (&self.shown, &self.home_scope, &self.home_computed) {
|
||||
(Some(puuid), Some(scope), Some((computed_puuid, computed_scope))) => {
|
||||
puuid == computed_puuid && scope == computed_scope
|
||||
}
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether one Season is selected, rather than all of them: only a Season has a Challenge.
|
||||
pub(super) fn in_season(&self) -> bool {
|
||||
pub(in crate::page) fn in_season(&self) -> bool {
|
||||
matches!(self.season, SeasonScope::Season(_))
|
||||
}
|
||||
|
||||
/// What the home reads: its own statistics when its scope differs, else the Statistics tab's.
|
||||
pub(super) fn home_statistics(&self) -> Option<&Statistics> {
|
||||
pub(in crate::page) fn home_statistics(&self) -> Option<&Statistics> {
|
||||
self.home_season.as_ref()?;
|
||||
match self.home_scope {
|
||||
Some(_) => self.home_stats.as_ref(),
|
||||
@@ -96,7 +151,7 @@ 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.
|
||||
pub(super) fn stats_notice(&self) -> Option<StatsNotice> {
|
||||
pub(in crate::page) fn stats_notice(&self) -> Option<StatsNotice> {
|
||||
if self.error().is_some() {
|
||||
return Some(StatsNotice::Error);
|
||||
}
|
||||
@@ -123,7 +178,7 @@ impl Page {
|
||||
/// Under the status messages: the banner, then the heading with the filters and
|
||||
/// search, and the cards. It holds no chart (#71): the cached charts row only belongs to the
|
||||
/// Statistics tab. Everything is one centred column, as wide as the mockup's.
|
||||
pub(super) fn home_content(
|
||||
pub(in crate::page) fn home_content(
|
||||
&self,
|
||||
window: &mut Window,
|
||||
cx: &mut Context<Page>,
|
||||
@@ -195,7 +250,7 @@ impl Page {
|
||||
|
||||
/// The sort selector: a sort icon and the choice, « Maîtrise » or « A–Z ». It stays on the
|
||||
/// home and during a champ select, and applies to every section of cards.
|
||||
pub(super) fn sort_selector(&self, cx: &App) -> impl IntoElement {
|
||||
pub(in crate::page) fn sort_selector(&self, cx: &App) -> impl IntoElement {
|
||||
let muted = cx.theme().muted_foreground;
|
||||
div()
|
||||
.h_flex()
|
||||
|
||||
@@ -4,7 +4,7 @@ use std::rc::Rc;
|
||||
use arena_tracker_core::{MatchOutcome, Splash, Statistics};
|
||||
use gpui_kit::SharedString;
|
||||
|
||||
use super::super::champ_select::UNKNOWN_ANVIL;
|
||||
use crate::page::champ_select::UNKNOWN_ANVIL;
|
||||
use crate::text::{attempt_ordinal, ordinal, short_date};
|
||||
|
||||
/// A line of the banner, the champion's name (or the count) set apart.
|
||||
|
||||
@@ -7,7 +7,7 @@ use gpui_kit::*;
|
||||
impl Page {
|
||||
/// Lifts the card under the pointer or the keyboard in `grid`, and lights its ring's tick.
|
||||
/// A wheel over the grid drops its cards at once.
|
||||
pub(super) fn light_on_hover(
|
||||
pub(in crate::page) fn light_on_hover(
|
||||
grid: &Entity<CardGrid>,
|
||||
cx: &mut Context<Self>,
|
||||
) -> [Subscription; 2] {
|
||||
@@ -42,7 +42,7 @@ impl Page {
|
||||
|
||||
/// The card under the pointer or the keyboard in `grid` changed: it is lifted, and its tick
|
||||
/// lit.
|
||||
pub(super) fn hovered(
|
||||
pub(in crate::page) fn hovered(
|
||||
&mut self,
|
||||
grid: &Entity<CardGrid>,
|
||||
hovered: CardHovered,
|
||||
@@ -78,7 +78,11 @@ impl Page {
|
||||
}
|
||||
|
||||
/// The cards lifted over `grid`, if any: drawn after it, as long as it is.
|
||||
pub(super) fn lift_layer(&self, grid: &Entity<CardGrid>, cx: &App) -> Option<AnyElement> {
|
||||
pub(in crate::page) fn lift_layer(
|
||||
&self,
|
||||
grid: &Entity<CardGrid>,
|
||||
cx: &App,
|
||||
) -> Option<AnyElement> {
|
||||
let now = cx.background_executor().now();
|
||||
let id = grid.entity_id();
|
||||
let mut lifted: Vec<_> = self.lifts.lifted(id, now).collect();
|
||||
@@ -119,7 +123,7 @@ impl Page {
|
||||
let grid = grid.read(cx);
|
||||
Some(crate::card_lift::layer(
|
||||
grid.cards().clone(),
|
||||
grid.placed().clone(),
|
||||
grid.positions().clone(),
|
||||
grid.images().cloned(),
|
||||
lifted,
|
||||
changing.map_or(Changes::Taken(lowered), Changes::Match),
|
||||
@@ -131,7 +135,12 @@ impl Page {
|
||||
/// The card under the pointer in `grid` changed to `id`. The tick follows the grid that lit
|
||||
/// it: another grid saying that none of its cards is under the pointer (the pointer went from
|
||||
/// it to this one, or it was folded) leaves the tick lit.
|
||||
pub(super) fn light(&mut self, grid: EntityId, id: Option<u32>, cx: &mut Context<Self>) {
|
||||
pub(in crate::page) fn light(
|
||||
&mut self,
|
||||
grid: EntityId,
|
||||
id: Option<u32>,
|
||||
cx: &mut Context<Self>,
|
||||
) {
|
||||
match id {
|
||||
Some(_) => self.lit_by = Some(grid),
|
||||
None if self.lit_by == Some(grid) => self.lit_by = None,
|
||||
|
||||
@@ -4,7 +4,7 @@ use gpui_kit::*;
|
||||
|
||||
impl Page {
|
||||
/// The follower thread was just started.
|
||||
pub fn following(&mut self, cx: &mut Context<Self>) {
|
||||
pub(crate) fn following(&mut self, cx: &mut Context<Self>) {
|
||||
self.pending_round = true;
|
||||
cx.notify();
|
||||
}
|
||||
@@ -12,7 +12,7 @@ impl Page {
|
||||
/// The page gives way to another screen (« Paramètres »): what it shows is given back, the
|
||||
/// grids' portraits and the banner's splash, in memory and in the window's atlas. They load
|
||||
/// again when it is drawn.
|
||||
pub fn hidden(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
||||
pub(crate) fn hidden(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
||||
self.covered = true;
|
||||
self.end_stage(cx);
|
||||
self.lifts.clear();
|
||||
@@ -25,21 +25,21 @@ impl Page {
|
||||
}
|
||||
|
||||
/// The page is back in front of « Paramètres ».
|
||||
pub fn uncovered(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
||||
pub(crate) fn uncovered(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
||||
self.covered = false;
|
||||
self.play_waiting(window, cx);
|
||||
self.start_entry(window, cx);
|
||||
}
|
||||
|
||||
/// Starts a refresh, or queues one behind the refresh already running.
|
||||
pub fn request_refresh(&mut self, cx: &mut Context<Self>) {
|
||||
pub(crate) fn request_refresh(&mut self, cx: &mut Context<Self>) {
|
||||
if self.refresh.request() {
|
||||
spawn_refresh(self.tracker.clone(), self.tx.clone());
|
||||
}
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
pub fn busy(&self) -> bool {
|
||||
pub(crate) fn busy(&self) -> bool {
|
||||
self.progress.is_some() || self.refresh.running() || self.pending_round
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@ use std::rc::Rc;
|
||||
impl Page {
|
||||
/// Ends the end of a followed Match, waiting or playing: the banner shows its splash again,
|
||||
/// and the champion's card leaves the grid if the filter or the search leave it out.
|
||||
pub(super) fn end_match(&mut self, cx: &mut Context<Self>) {
|
||||
pub(in crate::page) fn end_match(&mut self, cx: &mut Context<Self>) {
|
||||
// A Match the ring had no tick for left only its kept card.
|
||||
let active = self.playback.active() || self.playback.kept_card.is_some();
|
||||
self.playback = MatchPlayback::default();
|
||||
@@ -23,7 +23,7 @@ impl Page {
|
||||
/// is in front. Of several meanwhile, the strongest plays, on its own champion; the most
|
||||
/// recent of the strongest. With the Windows « Show animations » setting off, the end state
|
||||
/// is all there is.
|
||||
pub(super) fn queue_match(&mut self, event: FollowedMatch, cx: &mut Context<Self>) {
|
||||
pub(in crate::page) fn queue_match(&mut self, event: FollowedMatch, cx: &mut Context<Self>) {
|
||||
if cx.reduce_motion() {
|
||||
return;
|
||||
}
|
||||
@@ -57,7 +57,7 @@ impl Page {
|
||||
/// Whether « Défi » is in front of the player. A window merely covered by another cannot
|
||||
/// be told on Windows (GPUI's `WindowVisibility`): visible then means shown and not
|
||||
/// minimised.
|
||||
pub(super) fn challenge_visible(&self, window: &Window) -> bool {
|
||||
pub(in crate::page) fn challenge_visible(&self, window: &Window) -> bool {
|
||||
window.is_visible()
|
||||
&& !self.covered
|
||||
&& self.tab == Tab::Challenge
|
||||
@@ -67,7 +67,7 @@ impl Page {
|
||||
}
|
||||
|
||||
/// « Défi » may have become visible: the animation waiting, if any, plays.
|
||||
pub(super) fn play_waiting(&mut self, window: &Window, cx: &mut Context<Self>) {
|
||||
pub(in crate::page) fn play_waiting(&mut self, window: &Window, cx: &mut Context<Self>) {
|
||||
if self.challenge_visible(window)
|
||||
&& !cx.reduce_motion()
|
||||
&& !self.playback.stats_pending
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
//! The « Statistiques » tab: the analysis of one Account, Season and Format.
|
||||
|
||||
mod data;
|
||||
mod scope;
|
||||
|
||||
use arena_tracker_core::{ChallengeSummary, Charts, ProgressCheck, StateFilter};
|
||||
use gpui_kit::component::chart::{AreaChart, BarChart};
|
||||
@@ -137,17 +138,17 @@ fn card(
|
||||
|
||||
/// The charts, a cached view: hovering the table, which redraws the page, does not draw them
|
||||
/// again (#31). The page updates it from `show_statistics`.
|
||||
pub(super) struct ChartsRow {
|
||||
pub(in crate::page) struct ChartsRow {
|
||||
/// Empty when there are no statistics.
|
||||
charts: Charts,
|
||||
in_season: bool,
|
||||
/// Guards the cache in tests.
|
||||
#[cfg(test)]
|
||||
pub(super) renders: usize,
|
||||
pub(in crate::page) renders: usize,
|
||||
}
|
||||
|
||||
impl ChartsRow {
|
||||
pub(super) fn new() -> ChartsRow {
|
||||
pub(in crate::page) fn new() -> ChartsRow {
|
||||
ChartsRow {
|
||||
charts: Charts {
|
||||
placements: vec![],
|
||||
@@ -162,7 +163,12 @@ impl ChartsRow {
|
||||
|
||||
/// Shows `charts`, or none; drawing them again only when they changed, since reloads keep
|
||||
/// coming during an import.
|
||||
pub(super) fn set(&mut self, charts: Option<&Charts>, in_season: bool, cx: &mut Context<Self>) {
|
||||
pub(in crate::page) fn set(
|
||||
&mut self,
|
||||
charts: Option<&Charts>,
|
||||
in_season: bool,
|
||||
cx: &mut Context<Self>,
|
||||
) {
|
||||
let charts = charts.cloned().unwrap_or_else(|| ChartsRow::new().charts);
|
||||
if (&self.charts, self.in_season) != (&charts, in_season) {
|
||||
self.charts = charts;
|
||||
@@ -286,7 +292,7 @@ fn attempts_chart(charts: &Charts) -> Option<AnyElement> {
|
||||
|
||||
impl Page {
|
||||
/// The Season and Format selectors, which only the statistics have.
|
||||
pub(super) fn statistics_selectors(&self) -> [AnyElement; 2] {
|
||||
fn statistics_selectors(&self) -> [AnyElement; 2] {
|
||||
[
|
||||
Select::new(&self.season_select)
|
||||
.id("season")
|
||||
@@ -302,7 +308,7 @@ impl Page {
|
||||
}
|
||||
|
||||
/// Under the banners: the Challenge tiles, the charts, the filters and the table.
|
||||
pub(super) fn statistics_content(&self, cx: &mut Context<Page>) -> Vec<AnyElement> {
|
||||
pub(in crate::page) fn statistics_content(&self, cx: &mut Context<Page>) -> Vec<AnyElement> {
|
||||
let options = filters(self.in_season());
|
||||
let selected = options.iter().position(|(_, f)| *f == self.filter);
|
||||
let challenge = self.stats.as_ref().and_then(|s| s.challenge.as_ref());
|
||||
|
||||
@@ -1,67 +1,12 @@
|
||||
use super::super::{ALL_FORMATS, AccountItem, NextHome, Page, Tab, now_ms};
|
||||
use crate::card::Card;
|
||||
use crate::page::{ALL_FORMATS, AccountItem, NextHome, Page, now_ms};
|
||||
use crate::worker::{compute_statistics, spawn_statistics};
|
||||
use arena_tracker_core::{
|
||||
Account, ProgressCheck, Scope, SeasonScope, StateFilter, Statistics, account_riot_id,
|
||||
};
|
||||
use arena_tracker_core::{SeasonScope, StateFilter, account_riot_id};
|
||||
use gpui_kit::component::IndexPath;
|
||||
use gpui_kit::*;
|
||||
use std::time::Instant;
|
||||
|
||||
impl Page {
|
||||
/// The Account shown: the pinned one, else the one being updated.
|
||||
pub(in crate::page) fn viewed(&self) -> Option<&Account> {
|
||||
self.pinned
|
||||
.as_ref()
|
||||
.and_then(|puuid| self.accounts.iter().find(|a| a.puuid == *puuid))
|
||||
.or(self.status.updating.as_ref())
|
||||
.or(self.last_active.as_ref())
|
||||
.or(self.accounts.first())
|
||||
}
|
||||
|
||||
/// The Account whose data the page shows: during a champ select the one signed in to the
|
||||
/// client, whatever the pinned or followed one is, else `viewed`.
|
||||
pub(in crate::page) fn displayed(&self) -> Option<&Account> {
|
||||
if self.in_champ_select() {
|
||||
let puuid = self.champ_select_account.as_deref()?;
|
||||
return self.accounts.iter().find(|a| a.puuid == puuid);
|
||||
}
|
||||
self.viewed()
|
||||
}
|
||||
|
||||
/// Whether the Account shown is not the one being updated (or none is), so only stored
|
||||
/// data is shown. Unknown until the follower's first round has reported.
|
||||
pub(in crate::page) fn stale(&self) -> bool {
|
||||
!self.pending_round
|
||||
&& self.displayed().is_some_and(|viewed| {
|
||||
self.status
|
||||
.updating
|
||||
.as_ref()
|
||||
.is_none_or(|updating| updating.puuid != viewed.puuid)
|
||||
})
|
||||
}
|
||||
|
||||
/// The game's own count, only meaningful for the Account being updated in the current Season,
|
||||
/// whether the page shows it as the home's Challenge or as the selected Season.
|
||||
pub(in crate::page) fn official(&self) -> Option<&ProgressCheck> {
|
||||
let updated = matches!((self.displayed(), &self.status.updating), (Some(v), Some(u)) if v.puuid == u.puuid);
|
||||
let shown = match (self.shown_tab, &self.season) {
|
||||
(Tab::Challenge, _) => self.home_season.as_deref(),
|
||||
(Tab::Statistics, SeasonScope::Season(season)) => Some(season.as_str()),
|
||||
(Tab::Statistics, SeasonScope::AllSeasons) => None,
|
||||
};
|
||||
let current = shown.is_some() && shown == self.current_season.as_deref();
|
||||
(updated && current).then_some(&self.status.official_progress)
|
||||
}
|
||||
|
||||
/// The tab's own statistics error: the home may have computed its own.
|
||||
pub(in crate::page) fn error(&self) -> Option<&String> {
|
||||
match (self.shown_tab, &self.home_scope) {
|
||||
(Tab::Challenge, Some(_)) => self.home_error.as_ref(),
|
||||
_ => self.stats_error.as_ref(),
|
||||
}
|
||||
}
|
||||
|
||||
/// A worker's reload: the Accounts now, the statistics on a below-normal worker, so neither a
|
||||
/// visible nor a hidden window waits for them (rule #1).
|
||||
pub(in crate::page) fn reload_in_background(
|
||||
@@ -168,68 +113,6 @@ impl Page {
|
||||
viewed
|
||||
}
|
||||
|
||||
/// The Season of the home's Challenge, and the scope to compute for it when the Statistics
|
||||
/// tab's does not already cover it. The Format never applies to the home.
|
||||
fn settle_home_scope(&mut self) {
|
||||
let season = match &self.season {
|
||||
SeasonScope::Season(name) => Some(name),
|
||||
// A Challenge belongs to one Season: the current one stands in.
|
||||
SeasonScope::AllSeasons => self.current_season.as_ref(),
|
||||
};
|
||||
self.home_season = season.map(|name| name.clone().into());
|
||||
let home = season.map(|name| Scope {
|
||||
season: SeasonScope::Season(name.clone()),
|
||||
format: None,
|
||||
});
|
||||
self.home_scope = home.filter(|home| *home != self.statistics_scope());
|
||||
}
|
||||
|
||||
/// Keeps what was computed for the home's own scope, if it had one, and for which Account.
|
||||
pub(in crate::page) fn set_home_result(
|
||||
&mut self,
|
||||
home: Option<Box<Result<Statistics, String>>>,
|
||||
) {
|
||||
self.home_computed = home
|
||||
.as_ref()
|
||||
.and_then(|_| self.shown.clone().zip(self.home_scope.clone()));
|
||||
(self.home_stats, self.home_error) = match home.map(|result| *result) {
|
||||
Some(Ok(stats)) => (Some(stats), None),
|
||||
Some(Err(error)) => (None, Some(error)),
|
||||
None => (None, None),
|
||||
};
|
||||
}
|
||||
|
||||
pub(in crate::page) fn forget_home(&mut self) {
|
||||
self.home_stats = None;
|
||||
self.home_error = None;
|
||||
self.home_computed = None;
|
||||
}
|
||||
|
||||
/// Whether the home's own statistics were computed for the Account and scope it has now.
|
||||
fn home_is_current(&self) -> bool {
|
||||
match (&self.shown, &self.home_scope, &self.home_computed) {
|
||||
(Some(puuid), Some(scope), Some((computed_puuid, computed_scope))) => {
|
||||
puuid == computed_puuid && scope == computed_scope
|
||||
}
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
fn statistics_scope(&self) -> Scope {
|
||||
if self.in_champ_select()
|
||||
&& let Some(season) = &self.current_season
|
||||
{
|
||||
return Scope {
|
||||
season: SeasonScope::Season(season.clone()),
|
||||
format: None,
|
||||
};
|
||||
}
|
||||
Scope {
|
||||
season: self.season.clone(),
|
||||
format: self.format,
|
||||
}
|
||||
}
|
||||
|
||||
/// Requests the statistics from a worker (`start_job`: none is running), or shows none when no
|
||||
/// Account is viewed.
|
||||
pub(in crate::page) fn recompute_in_background(
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
use crate::page::{Page, Tab};
|
||||
use arena_tracker_core::{Account, ProgressCheck, Scope, SeasonScope};
|
||||
|
||||
impl Page {
|
||||
/// The Account shown: the pinned one, else the one being updated.
|
||||
pub(in crate::page) fn viewed(&self) -> Option<&Account> {
|
||||
self.pinned
|
||||
.as_ref()
|
||||
.and_then(|puuid| self.accounts.iter().find(|a| a.puuid == *puuid))
|
||||
.or(self.status.updating.as_ref())
|
||||
.or(self.last_active.as_ref())
|
||||
.or(self.accounts.first())
|
||||
}
|
||||
|
||||
/// The Account whose data the page shows: during a champ select the one signed in to the
|
||||
/// client, whatever the pinned or followed one is, else `viewed`.
|
||||
pub(in crate::page) fn displayed(&self) -> Option<&Account> {
|
||||
if self.in_champ_select() {
|
||||
let puuid = self.champ_select_account.as_deref()?;
|
||||
return self.accounts.iter().find(|a| a.puuid == puuid);
|
||||
}
|
||||
self.viewed()
|
||||
}
|
||||
|
||||
/// Whether the Account shown is not the one being updated (or none is), so only stored
|
||||
/// data is shown. Unknown until the follower's first round has reported.
|
||||
pub(in crate::page) fn stale(&self) -> bool {
|
||||
!self.pending_round
|
||||
&& self.displayed().is_some_and(|viewed| {
|
||||
self.status
|
||||
.updating
|
||||
.as_ref()
|
||||
.is_none_or(|updating| updating.puuid != viewed.puuid)
|
||||
})
|
||||
}
|
||||
|
||||
/// The game's own count, only meaningful for the Account being updated in the current Season,
|
||||
/// whether the page shows it as the home's Challenge or as the selected Season.
|
||||
pub(in crate::page) fn official(&self) -> Option<&ProgressCheck> {
|
||||
let updated = matches!((self.displayed(), &self.status.updating), (Some(v), Some(u)) if v.puuid == u.puuid);
|
||||
let shown = match (self.shown_tab, &self.season) {
|
||||
(Tab::Challenge, _) => self.home_season.as_deref(),
|
||||
(Tab::Statistics, SeasonScope::Season(season)) => Some(season.as_str()),
|
||||
(Tab::Statistics, SeasonScope::AllSeasons) => None,
|
||||
};
|
||||
let current = shown.is_some() && shown == self.current_season.as_deref();
|
||||
(updated && current).then_some(&self.status.official_progress)
|
||||
}
|
||||
|
||||
/// The tab's own statistics error: the home may have computed its own.
|
||||
pub(in crate::page) fn error(&self) -> Option<&String> {
|
||||
match (self.shown_tab, &self.home_scope) {
|
||||
(Tab::Challenge, Some(_)) => self.home_error.as_ref(),
|
||||
_ => self.stats_error.as_ref(),
|
||||
}
|
||||
}
|
||||
|
||||
pub(in crate::page) fn statistics_scope(&self) -> Scope {
|
||||
if self.in_champ_select()
|
||||
&& let Some(season) = &self.current_season
|
||||
{
|
||||
return Scope {
|
||||
season: SeasonScope::Season(season.clone()),
|
||||
format: None,
|
||||
};
|
||||
}
|
||||
Scope {
|
||||
season: self.season.clone(),
|
||||
format: self.format,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,12 +2,10 @@ use super::banner_fixtures::{
|
||||
banner, banner_champion, banner_rows, banner_statistics, bold, draw_loaded, held_splashes,
|
||||
in_atlas, loaded_splashes, on, ring_renders, ring_ticks, rows_with_splashes, splash,
|
||||
};
|
||||
|
||||
use super::page_fixtures::{
|
||||
center, champions, draw, open_page_in_season, show, statistics, switch_tab,
|
||||
};
|
||||
use crate::card_images::tests::{PORTRAIT_JPEG, TestDir};
|
||||
|
||||
use crate::page::Tab;
|
||||
use arena_tracker_core::{
|
||||
ChampionChallenge, ChampionRow, ChampionSort, ChampionState, LastMatch, MatchOutcome,
|
||||
|
||||
@@ -3,7 +3,7 @@ use crate::worker::{Msg, spawn_refresh};
|
||||
use gpui_kit::*;
|
||||
|
||||
impl Page {
|
||||
pub(super) fn apply(&mut self, msg: Msg, window: &mut Window, cx: &mut Context<Self>) {
|
||||
pub(in crate::page) fn apply(&mut self, msg: Msg, window: &mut Window, cx: &mut Context<Self>) {
|
||||
match msg {
|
||||
Msg::Progress(progress) => {
|
||||
self.progress = Some(progress);
|
||||
|
||||
+3
-36
@@ -10,48 +10,15 @@ use std::cell::RefCell;
|
||||
use std::f32::consts::{FRAC_PI_2, TAU};
|
||||
use std::rc::Rc;
|
||||
|
||||
use arena_tracker_core::{ChampionRow, ChampionSort, ChampionState};
|
||||
use arena_tracker_core::ChampionState;
|
||||
use gpui_kit::component::ActiveTheme as _;
|
||||
use gpui_kit::*;
|
||||
|
||||
use crate::card_order::card_order;
|
||||
use crate::motion::{MATCH_SETTLE, MatchAnimation, MatchEnd, ease_out};
|
||||
use crate::theme::{ring_never, ring_played};
|
||||
|
||||
/// A champion's tick: long and gold when Completed, pale gold when played, short and faint when
|
||||
/// never played.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub struct Tick {
|
||||
pub id: u32,
|
||||
pub state: ChampionState,
|
||||
}
|
||||
|
||||
/// The ticks of `rows` in the ring's order. `completion_order` lists the Completed champions'
|
||||
/// ids by their first top 1; an id the rows do not know is skipped.
|
||||
pub fn ticks(rows: &[ChampionRow], completion_order: &[u32]) -> Vec<Tick> {
|
||||
let completed = completion_order
|
||||
.iter()
|
||||
.filter(|&&id| rows.iter().any(|row| row.champion.id == id))
|
||||
.map(|&id| Tick {
|
||||
id,
|
||||
state: ChampionState::Completed,
|
||||
});
|
||||
let by_mastery = card_order(rows, ChampionSort::Mastery);
|
||||
let of_state = |state: ChampionState| {
|
||||
by_mastery
|
||||
.iter()
|
||||
.map(|&ix| &rows[ix])
|
||||
.filter(move |row| row.state == Some(state))
|
||||
.map(move |row| Tick {
|
||||
id: row.champion.id,
|
||||
state,
|
||||
})
|
||||
};
|
||||
completed
|
||||
.chain(of_state(ChampionState::InProgress))
|
||||
.chain(of_state(ChampionState::NeverPlayed))
|
||||
.collect()
|
||||
}
|
||||
mod ticks;
|
||||
pub use ticks::{Tick, ticks};
|
||||
|
||||
// The reference page's geometry, in the units of its SVG: the ring is drawn in a square
|
||||
// `BOX` wide, its centre `PAD + C` from the edges.
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
use arena_tracker_core::{ChampionRow, ChampionSort, ChampionState};
|
||||
|
||||
use crate::card_order::card_order;
|
||||
|
||||
/// A champion's tick: long and gold when Completed, pale gold when played, short and faint when
|
||||
/// never played.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub struct Tick {
|
||||
pub id: u32,
|
||||
pub state: ChampionState,
|
||||
}
|
||||
|
||||
/// The ticks of `rows` in the ring's order. `completion_order` lists the Completed champions'
|
||||
/// ids by their first top 1; an id the rows do not know is skipped.
|
||||
pub fn ticks(rows: &[ChampionRow], completion_order: &[u32]) -> Vec<Tick> {
|
||||
let completed = completion_order
|
||||
.iter()
|
||||
.filter(|&&id| rows.iter().any(|row| row.champion.id == id))
|
||||
.map(|&id| Tick {
|
||||
id,
|
||||
state: ChampionState::Completed,
|
||||
});
|
||||
let by_mastery = card_order(rows, ChampionSort::Mastery);
|
||||
let of_state = |state: ChampionState| {
|
||||
by_mastery
|
||||
.iter()
|
||||
.map(|&ix| &rows[ix])
|
||||
.filter(move |row| row.state == Some(state))
|
||||
.map(move |row| Tick {
|
||||
id: row.champion.id,
|
||||
state,
|
||||
})
|
||||
};
|
||||
completed
|
||||
.chain(of_state(ChampionState::InProgress))
|
||||
.chain(of_state(ChampionState::NeverPlayed))
|
||||
.collect()
|
||||
}
|
||||
+3
-118
@@ -2,13 +2,11 @@
|
||||
|
||||
use std::rc::Rc;
|
||||
|
||||
use arena_tracker_core::{ChampionSort, Preferences, ThemePreference, UpdateChannel};
|
||||
use arena_tracker_core::{ChampionSort, Preferences, UpdateChannel};
|
||||
use gpui_kit::base::async_util::{Sender, unbounded};
|
||||
use gpui_kit::component::button::{Button, ButtonVariants as _};
|
||||
use gpui_kit::component::input::{Input, InputEvent, InputState};
|
||||
use gpui_kit::component::radio::RadioGroup;
|
||||
use gpui_kit::component::switch::Switch;
|
||||
use gpui_kit::component::{ActiveTheme as _, Disableable as _, StyledExt as _};
|
||||
use gpui_kit::component::{ActiveTheme as _, StyledExt as _};
|
||||
use gpui_kit::*;
|
||||
|
||||
use crate::logon::LogonLaunch;
|
||||
@@ -18,20 +16,8 @@ use crate::worker::{RefreshGate, UpdateChecked, spawn_update_check};
|
||||
|
||||
const PLACEHOLDER_SAVED: &str = "Clé enregistrée";
|
||||
const PLACEHOLDER_EMPTY: &str = "Clé API Riot";
|
||||
const THEMES: [(ThemePreference, &str); 3] = [
|
||||
(ThemePreference::System, "Système"),
|
||||
(ThemePreference::Light, "Clair"),
|
||||
(ThemePreference::Dark, "Sombre"),
|
||||
];
|
||||
const CHANNELS: [(UpdateChannel, &str); 2] = [
|
||||
(UpdateChannel::Stable, "Stable"),
|
||||
(UpdateChannel::Beta, "Bêta"),
|
||||
];
|
||||
const STABLE_AFTER_BETA: &str =
|
||||
"La bêta installée reste en place jusqu’à une version stable plus récente.";
|
||||
const LOGON_LABEL: &str = "Lancer à l’ouverture de session Windows";
|
||||
// Not « Disponible »: the interface word of a Pickable champion (CONTEXT.md).
|
||||
const LOGON_UNAVAILABLE: &str = "Réservé à la version installée.";
|
||||
const LOGON_ERROR: &str = "Impossible de modifier le lancement à l’ouverture de session.";
|
||||
|
||||
mod appearance;
|
||||
@@ -39,6 +25,7 @@ pub use appearance::apply_theme;
|
||||
#[cfg(test)]
|
||||
use appearance::theme_mode;
|
||||
|
||||
mod preferences;
|
||||
mod store;
|
||||
pub use store::KeyStore;
|
||||
|
||||
@@ -277,108 +264,6 @@ impl KeyForm {
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
fn preferences(&self, cx: &mut Context<Self>) -> impl IntoElement {
|
||||
let preferences = self.store.preferences();
|
||||
let (muted, danger) = (cx.theme().muted_foreground, cx.theme().danger);
|
||||
let logon_available = self.logon_launch.available();
|
||||
div()
|
||||
.v_flex()
|
||||
.gap_3()
|
||||
.child(
|
||||
div()
|
||||
.v_flex()
|
||||
.gap_1()
|
||||
.child(
|
||||
Switch::new("launch-at-logon")
|
||||
.label(LOGON_LABEL)
|
||||
.checked(self.launches_at_logon)
|
||||
.disabled(!logon_available)
|
||||
.on_change(cx.listener(|this, enabled, _, cx| {
|
||||
this.set_logon_launch(*enabled, cx);
|
||||
})),
|
||||
)
|
||||
.children(
|
||||
(!logon_available)
|
||||
.then(|| div().text_color(muted).child(LOGON_UNAVAILABLE)),
|
||||
),
|
||||
)
|
||||
.child(
|
||||
Switch::new("close-to-tray")
|
||||
.label("Fermer dans la zone de notification")
|
||||
.checked(preferences.close_to_tray)
|
||||
.on_change(cx.listener(|this, enabled, window, cx| {
|
||||
this.set_preferences(
|
||||
Preferences {
|
||||
close_to_tray: *enabled,
|
||||
..this.store.preferences()
|
||||
},
|
||||
window,
|
||||
cx,
|
||||
);
|
||||
})),
|
||||
)
|
||||
.child(
|
||||
div().v_flex().gap_1().child("Thème").child(
|
||||
RadioGroup::horizontal("theme")
|
||||
.children(THEMES.map(|(_, label)| label))
|
||||
.selected_index(
|
||||
THEMES
|
||||
.iter()
|
||||
.position(|(theme, _)| *theme == preferences.theme),
|
||||
)
|
||||
.on_change(cx.listener(|this, index: &usize, window, cx| {
|
||||
this.set_preferences(
|
||||
Preferences {
|
||||
theme: THEMES[*index].0,
|
||||
..this.store.preferences()
|
||||
},
|
||||
window,
|
||||
cx,
|
||||
);
|
||||
})),
|
||||
),
|
||||
)
|
||||
.child(
|
||||
div()
|
||||
.v_flex()
|
||||
.gap_1()
|
||||
.child("Mises à jour")
|
||||
.child(
|
||||
RadioGroup::horizontal("update-channel")
|
||||
.children(CHANNELS.map(|(_, label)| label))
|
||||
.selected_index(
|
||||
CHANNELS
|
||||
.iter()
|
||||
.position(|(choice, _)| *choice == channel(preferences)),
|
||||
)
|
||||
.on_change(cx.listener(|this, index: &usize, window, cx| {
|
||||
this.set_preferences(
|
||||
Preferences {
|
||||
update_channel: Some(CHANNELS[*index].0),
|
||||
..this.store.preferences()
|
||||
},
|
||||
window,
|
||||
cx,
|
||||
);
|
||||
})),
|
||||
)
|
||||
.children(
|
||||
self.update_status()
|
||||
.map(|status| div().text_color(muted).child(status)),
|
||||
)
|
||||
.children(self.can_restart().then(|| {
|
||||
div().h_flex().child(
|
||||
Button::new("restart")
|
||||
.label("Redémarrer")
|
||||
.on_click(cx.listener(|this, _, _, cx| this.restart(cx))),
|
||||
)
|
||||
})),
|
||||
)
|
||||
.children(
|
||||
(self.preference_error.clone()).map(|error| div().text_color(danger).child(error)),
|
||||
)
|
||||
}
|
||||
|
||||
/// Hands the ready update to the installer, then quits as « Quitter » does: never hidden in
|
||||
/// the notification area, the single instance is free when the new version opens.
|
||||
fn restart(&mut self, cx: &mut Context<Self>) {
|
||||
|
||||
@@ -0,0 +1,126 @@
|
||||
use arena_tracker_core::{Preferences, ThemePreference, UpdateChannel};
|
||||
use gpui_kit::component::button::Button;
|
||||
use gpui_kit::component::radio::RadioGroup;
|
||||
use gpui_kit::component::switch::Switch;
|
||||
use gpui_kit::component::{ActiveTheme as _, Disableable as _, StyledExt as _};
|
||||
use gpui_kit::*;
|
||||
|
||||
use super::KeyForm;
|
||||
use crate::release::channel;
|
||||
|
||||
const THEMES: [(ThemePreference, &str); 3] = [
|
||||
(ThemePreference::System, "Système"),
|
||||
(ThemePreference::Light, "Clair"),
|
||||
(ThemePreference::Dark, "Sombre"),
|
||||
];
|
||||
const CHANNELS: [(UpdateChannel, &str); 2] = [
|
||||
(UpdateChannel::Stable, "Stable"),
|
||||
(UpdateChannel::Beta, "Bêta"),
|
||||
];
|
||||
const LOGON_LABEL: &str = "Lancer à l’ouverture de session Windows";
|
||||
// Not « Disponible »: the interface word of a Pickable champion (CONTEXT.md).
|
||||
const LOGON_UNAVAILABLE: &str = "Réservé à la version installée.";
|
||||
|
||||
impl KeyForm {
|
||||
pub(super) fn preferences(&self, cx: &mut Context<Self>) -> impl IntoElement {
|
||||
let preferences = self.store.preferences();
|
||||
let (muted, danger) = (cx.theme().muted_foreground, cx.theme().danger);
|
||||
let logon_available = self.logon_launch.available();
|
||||
div()
|
||||
.v_flex()
|
||||
.gap_3()
|
||||
.child(
|
||||
div()
|
||||
.v_flex()
|
||||
.gap_1()
|
||||
.child(
|
||||
Switch::new("launch-at-logon")
|
||||
.label(LOGON_LABEL)
|
||||
.checked(self.launches_at_logon)
|
||||
.disabled(!logon_available)
|
||||
.on_change(cx.listener(|this, enabled, _, cx| {
|
||||
this.set_logon_launch(*enabled, cx);
|
||||
})),
|
||||
)
|
||||
.children(
|
||||
(!logon_available)
|
||||
.then(|| div().text_color(muted).child(LOGON_UNAVAILABLE)),
|
||||
),
|
||||
)
|
||||
.child(
|
||||
Switch::new("close-to-tray")
|
||||
.label("Fermer dans la zone de notification")
|
||||
.checked(preferences.close_to_tray)
|
||||
.on_change(cx.listener(|this, enabled, window, cx| {
|
||||
this.set_preferences(
|
||||
Preferences {
|
||||
close_to_tray: *enabled,
|
||||
..this.store.preferences()
|
||||
},
|
||||
window,
|
||||
cx,
|
||||
);
|
||||
})),
|
||||
)
|
||||
.child(
|
||||
div().v_flex().gap_1().child("Thème").child(
|
||||
RadioGroup::horizontal("theme")
|
||||
.children(THEMES.map(|(_, label)| label))
|
||||
.selected_index(
|
||||
THEMES
|
||||
.iter()
|
||||
.position(|(theme, _)| *theme == preferences.theme),
|
||||
)
|
||||
.on_change(cx.listener(|this, index: &usize, window, cx| {
|
||||
this.set_preferences(
|
||||
Preferences {
|
||||
theme: THEMES[*index].0,
|
||||
..this.store.preferences()
|
||||
},
|
||||
window,
|
||||
cx,
|
||||
);
|
||||
})),
|
||||
),
|
||||
)
|
||||
.child(
|
||||
div()
|
||||
.v_flex()
|
||||
.gap_1()
|
||||
.child("Mises à jour")
|
||||
.child(
|
||||
RadioGroup::horizontal("update-channel")
|
||||
.children(CHANNELS.map(|(_, label)| label))
|
||||
.selected_index(
|
||||
CHANNELS
|
||||
.iter()
|
||||
.position(|(choice, _)| *choice == channel(preferences)),
|
||||
)
|
||||
.on_change(cx.listener(|this, index: &usize, window, cx| {
|
||||
this.set_preferences(
|
||||
Preferences {
|
||||
update_channel: Some(CHANNELS[*index].0),
|
||||
..this.store.preferences()
|
||||
},
|
||||
window,
|
||||
cx,
|
||||
);
|
||||
})),
|
||||
)
|
||||
.children(
|
||||
self.update_status()
|
||||
.map(|status| div().text_color(muted).child(status)),
|
||||
)
|
||||
.children(self.can_restart().then(|| {
|
||||
div().h_flex().child(
|
||||
Button::new("restart")
|
||||
.label("Redémarrer")
|
||||
.on_click(cx.listener(|this, _, _, cx| this.restart(cx))),
|
||||
)
|
||||
})),
|
||||
)
|
||||
.children(
|
||||
(self.preference_error.clone()).map(|error| div().text_color(danger).child(error)),
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use arena_tracker_core::{Config, Preferences, RiotApi, UpdateChannel};
|
||||
use arena_tracker_core::{Config, Preferences, RiotApi, ThemePreference, UpdateChannel};
|
||||
use gpui_kit::component::ThemeMode;
|
||||
use gpui_kit::{AppContext as _, TestAppContext, VisualTestContext, WindowOptions};
|
||||
|
||||
use super::{KeyForm, KeyStore, ThemePreference, theme_mode};
|
||||
use super::{KeyForm, KeyStore, theme_mode};
|
||||
use crate::logon::tests::Scratch;
|
||||
use crate::worker::UpdateChecked;
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ use gpui_kit::*;
|
||||
use super::motion::Leaving;
|
||||
use super::{Entry, Leave, Taken};
|
||||
use crate::card::{self, Card, Pose};
|
||||
use crate::card_grid::Placements;
|
||||
use crate::card_grid::CardPositions;
|
||||
use crate::card_images::CardImages;
|
||||
use crate::card_lift::{self, Layer};
|
||||
use std::time::Instant;
|
||||
@@ -54,7 +54,7 @@ impl<'a> Drawn<'a> {
|
||||
/// card out of sight is not built. Painted after the rest of the page, as the lifted cards are.
|
||||
pub(crate) fn hand_layer(
|
||||
cards: std::rc::Rc<[Card]>,
|
||||
placed: Placements,
|
||||
positions: CardPositions,
|
||||
images: Option<Entity<CardImages>>,
|
||||
motion: HandMotion,
|
||||
) -> AnyElement {
|
||||
@@ -62,13 +62,13 @@ pub(crate) fn hand_layer(
|
||||
canvas(
|
||||
move |_, window, cx| {
|
||||
let background = cx.theme().background;
|
||||
let placed = placed.borrow();
|
||||
let positions = positions.borrow();
|
||||
let now = motion.now;
|
||||
let mut quads = Vec::new();
|
||||
let mut moving = Vec::new();
|
||||
// In the hand's order: the cards dealt later go over the earlier ones.
|
||||
for (ix, card) in cards.iter().enumerate() {
|
||||
let Some(place) = placed.get(&card.id) else {
|
||||
let Some(place) = positions.get(&card.id) else {
|
||||
continue;
|
||||
};
|
||||
// How far a card dealt comes from: the bottom of the window.
|
||||
|
||||
+13
-82
@@ -1,6 +1,10 @@
|
||||
//! Keeping the active Account up to date by following the game client.
|
||||
mod pending;
|
||||
mod progress;
|
||||
mod status;
|
||||
|
||||
pub use status::{ProgressCheck, Status, UpdateProblem};
|
||||
|
||||
use std::sync::{MutexGuard, PoisonError};
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
@@ -8,7 +12,7 @@ use std::time::Duration;
|
||||
use rusqlite::OptionalExtension;
|
||||
|
||||
use crate::client::{ClientEvent, ClientSnapshot, GameClientSource, GamePhase, Gameflow};
|
||||
use crate::error::{Error, SourceError};
|
||||
use crate::error::Error;
|
||||
use crate::model::{Account, FollowedMatch, SyncProgress, SyncReport};
|
||||
use crate::seasons::Season;
|
||||
use crate::tracker::{Tracker, account_from_row};
|
||||
@@ -27,86 +31,6 @@ const WAIT_OTHERWISE: Duration = Duration::from_secs(60);
|
||||
/// ended before that time, and started longer ago than this: an Arena game lasts longer.
|
||||
const CLOCK_SLACK_MS: i64 = 5 * 60_000;
|
||||
|
||||
/// Why the last update did not (fully) happen.
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub enum UpdateProblem {
|
||||
MissingKey,
|
||||
InvalidKey,
|
||||
Network,
|
||||
RateLimited,
|
||||
/// Client absent and no Account known yet.
|
||||
NoAccount,
|
||||
/// A finished Arena game is not available from the Riot API yet.
|
||||
MatchPending,
|
||||
Other(String),
|
||||
}
|
||||
|
||||
impl UpdateProblem {
|
||||
/// The French banner text.
|
||||
pub fn message(&self) -> String {
|
||||
match self {
|
||||
UpdateProblem::MissingKey => {
|
||||
"Aucune clé API Riot n'est configurée : ajoutez-la dans les Paramètres.".into()
|
||||
}
|
||||
UpdateProblem::InvalidKey => {
|
||||
"La clé API Riot est refusée (invalide ou expirée) : renouvelez-la dans les Paramètres."
|
||||
.into()
|
||||
}
|
||||
UpdateProblem::Network => {
|
||||
"L'API Riot est injoignable : vérifiez votre connexion.".into()
|
||||
}
|
||||
UpdateProblem::RateLimited => {
|
||||
"L'API Riot limite les requêtes : la mise à jour reprendra plus tard.".into()
|
||||
}
|
||||
UpdateProblem::NoAccount => {
|
||||
"Aucun Compte connu : lancez le client de League of Legends et connectez-vous."
|
||||
.into()
|
||||
}
|
||||
UpdateProblem::MatchPending => {
|
||||
"La dernière Partie n'est pas encore disponible chez Riot : actualisez plus tard pour l'importer."
|
||||
.into()
|
||||
}
|
||||
UpdateProblem::Other(reason) => format!("Mise à jour impossible : {reason}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&Error> for UpdateProblem {
|
||||
fn from(error: &Error) -> Self {
|
||||
match error {
|
||||
Error::Source(SourceError::MissingKey) => UpdateProblem::MissingKey,
|
||||
Error::Source(SourceError::InvalidKey) => UpdateProblem::InvalidKey,
|
||||
Error::Source(SourceError::Network(_)) => UpdateProblem::Network,
|
||||
Error::Source(SourceError::RateLimited { .. }) => UpdateProblem::RateLimited,
|
||||
other => UpdateProblem::Other(other.to_string()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The game's own count compared with the app's, for the current Season.
|
||||
#[derive(Debug, Clone, Default, PartialEq)]
|
||||
pub enum ProgressCheck {
|
||||
#[default]
|
||||
Absent,
|
||||
Agrees(u32),
|
||||
Differs {
|
||||
app: usize,
|
||||
official: u32,
|
||||
},
|
||||
}
|
||||
|
||||
/// What the interface needs to know besides statistics.
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct Status {
|
||||
/// As of the last `follow_client` round.
|
||||
pub client_running: bool,
|
||||
/// The signed-in Account while the client runs, otherwise the last active one.
|
||||
pub updating: Option<Account>,
|
||||
/// Outcome of the most recent update attempt; `None` after a success.
|
||||
pub problem: Option<UpdateProblem>,
|
||||
pub official_progress: ProgressCheck,
|
||||
}
|
||||
|
||||
/// The Match of a finished Arena game, not stored yet.
|
||||
struct Pending {
|
||||
/// The client's id of that game, when it gave one.
|
||||
@@ -144,7 +68,14 @@ pub fn riot_id(game_name: &str, tag_line: &str) -> String {
|
||||
format!("{game_name}#{tag_line}")
|
||||
}
|
||||
|
||||
/// Riot IDs differ in case only when they name the same Account.
|
||||
/// Compare Riot IDs case-insensitively, including the tag line.
|
||||
///
|
||||
/// ```
|
||||
/// use arena_tracker_core::same_riot_id;
|
||||
///
|
||||
/// assert!(same_riot_id("Étoile#EUW", "étoile#euw"));
|
||||
/// assert!(!same_riot_id("Étoile#EUW", "Étoile#NA1"));
|
||||
/// ```
|
||||
pub fn same_riot_id(a: &str, b: &str) -> bool {
|
||||
a.to_lowercase() == b.to_lowercase()
|
||||
}
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
use crate::error::{Error, SourceError};
|
||||
use crate::model::Account;
|
||||
|
||||
/// Why the last update did not (fully) happen.
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub enum UpdateProblem {
|
||||
MissingKey,
|
||||
InvalidKey,
|
||||
Network,
|
||||
RateLimited,
|
||||
/// Client absent and no Account known yet.
|
||||
NoAccount,
|
||||
/// A finished Arena game is not available from the Riot API yet.
|
||||
MatchPending,
|
||||
Other(String),
|
||||
}
|
||||
|
||||
impl UpdateProblem {
|
||||
/// The French banner text.
|
||||
pub fn message(&self) -> String {
|
||||
match self {
|
||||
UpdateProblem::MissingKey => {
|
||||
"Aucune clé API Riot n'est configurée : ajoutez-la dans les Paramètres.".into()
|
||||
}
|
||||
UpdateProblem::InvalidKey => {
|
||||
"La clé API Riot est refusée (invalide ou expirée) : renouvelez-la dans les Paramètres."
|
||||
.into()
|
||||
}
|
||||
UpdateProblem::Network => {
|
||||
"L'API Riot est injoignable : vérifiez votre connexion.".into()
|
||||
}
|
||||
UpdateProblem::RateLimited => {
|
||||
"L'API Riot limite les requêtes : la mise à jour reprendra plus tard.".into()
|
||||
}
|
||||
UpdateProblem::NoAccount => {
|
||||
"Aucun Compte connu : lancez le client de League of Legends et connectez-vous."
|
||||
.into()
|
||||
}
|
||||
UpdateProblem::MatchPending => {
|
||||
"La dernière Partie n'est pas encore disponible chez Riot : actualisez plus tard pour l'importer."
|
||||
.into()
|
||||
}
|
||||
UpdateProblem::Other(reason) => format!("Mise à jour impossible : {reason}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&Error> for UpdateProblem {
|
||||
fn from(error: &Error) -> Self {
|
||||
match error {
|
||||
Error::Source(SourceError::MissingKey) => UpdateProblem::MissingKey,
|
||||
Error::Source(SourceError::InvalidKey) => UpdateProblem::InvalidKey,
|
||||
Error::Source(SourceError::Network(_)) => UpdateProblem::Network,
|
||||
Error::Source(SourceError::RateLimited { .. }) => UpdateProblem::RateLimited,
|
||||
other => UpdateProblem::Other(other.to_string()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The game's own count compared with the app's, for the current Season.
|
||||
#[derive(Debug, Clone, Default, PartialEq)]
|
||||
pub enum ProgressCheck {
|
||||
#[default]
|
||||
Absent,
|
||||
Agrees(u32),
|
||||
Differs {
|
||||
app: usize,
|
||||
official: u32,
|
||||
},
|
||||
}
|
||||
|
||||
/// What the interface needs to know besides statistics.
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct Status {
|
||||
/// As of the last `follow_client` round.
|
||||
pub client_running: bool,
|
||||
/// The signed-in Account while the client runs, otherwise the last active one.
|
||||
pub updating: Option<Account>,
|
||||
/// Outcome of the most recent update attempt; `None` after a success.
|
||||
pub problem: Option<UpdateProblem>,
|
||||
pub official_progress: ProgressCheck,
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
use super::*;
|
||||
use crate::error::SourceError;
|
||||
use std::collections::HashSet;
|
||||
use std::time::Duration;
|
||||
|
||||
|
||||
Reference in new issue
Block a user