Files
arena-tracker/crates/app/src/page/hover.rs
T
nessarandClaude Opus 5.5 e7ff365069
CI / core (pull_request) Successful in 1m34s
CI / core (push) Successful in 1m35s
Settle names and module homes after third review (#103)
- Rename CardPosition/CardPositions/positions() to DrawnCard/DrawnCards/
  drawn_cards(): "position" is a word CONTEXT.md avoids for Placement.
- Move the Account and status queries from page/statistics/scope.rs to
  page/displayed.rs, since the whole page uses them.
- Move the home's own statistics state (settle_home_scope, set_home_result,
  forget_home, home_is_current) to page/home/data.rs, leaving home.rs to
  queries and rendering.
- Move the profiling flag shown() from display.rs to page/profiling.rs.
- Narrow Page::new to pub(crate), and restore the domain phrase in the
  same_riot_id doc comment and the page.rs module doc.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 18:16:00 +01:00

158 lines
6.0 KiB
Rust

use super::Page;
use crate::card_grid::{CardGrid, CardHovered, PutDown};
use crate::card_lift::{Changes, Changing};
use crate::motion::MatchEnd;
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(in crate::page) fn light_on_hover(
grid: &Entity<CardGrid>,
cx: &mut Context<Self>,
) -> [Subscription; 2] {
[
cx.subscribe(grid, |this, grid, hovered: &CardHovered, cx| {
let mut hovered = *hovered;
if grid.entity_id() == this.anvil_grid.entity_id() {
this.hover_waiting = None;
}
// A card of the hand still dealt is taken into account once in its place.
let now = cx.background_executor().now();
let waiting = hovered
.id
.is_some_and(|id| this.dealing(&grid, id, now, cx));
if waiting {
this.hover_waiting = Some(hovered);
hovered.id = None;
}
this.hovered(&grid, hovered, cx);
// The pointer moving puts the card the keyboard waits for down, as a lifted
// one: it is not lifted once in its place.
if waiting && hovered.by_keyboard {
this.lifted_by_keyboard = Some(grid.downgrade());
}
}),
cx.subscribe(grid, |this, grid, _: &PutDown, cx| {
this.lifts.drop_grid(grid.entity_id());
cx.notify();
}),
]
}
/// The card under the pointer or the keyboard in `grid` changed: it is lifted, and its tick
/// lit.
pub(in crate::page) fn hovered(
&mut self,
grid: &Entity<CardGrid>,
hovered: CardHovered,
cx: &mut Context<Self>,
) {
let CardHovered { id, by_keyboard } = hovered;
if by_keyboard && id.is_some() {
self.lifted_by_keyboard = Some(grid.downgrade());
} else if (self.lifted_by_keyboard.as_ref())
.is_some_and(|lifted| lifted.entity_id() == grid.entity_id())
{
self.lifted_by_keyboard = None;
}
self.lift(grid, id, cx);
self.light(grid.entity_id(), id, cx);
}
/// The card under the pointer or the keyboard in `grid` is now `id`: it rises over the grid,
/// and the one it replaces settles back. With the Windows « Show animations » setting off,
/// each is where it goes at once.
fn lift(&mut self, grid: &Entity<CardGrid>, id: Option<u32>, cx: &mut Context<Self>) {
// The hand leaving at the end of a champ select lifts nothing.
if self.leave.is_some() {
return;
}
let now = cx.background_executor().now();
let hand = grid.read(cx).is_hand();
self.lifts.hover(grid.entity_id(), id, hand, now);
if cx.reduce_motion() {
self.lifts.finish(now);
}
cx.notify();
}
/// The cards lifted over `grid`, if any: drawn after it, as long as it is.
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();
// The card of the champion changes in place; once the comet lands, « Validé » is the
// grid's own card.
let changing = (self.playback.animation)
.filter(|a| id == self.home_grid.entity_id() && a.end != MatchEnd::Nothing)
.and_then(|a| {
let since_landing = a.since_landing(now);
let before = self.playback.previous_card.clone()?;
if since_landing >= 0. && a.has_comet() {
return None;
}
if !lifted.iter().any(|card| card.id == before.id) {
lifted.insert(
0,
crate::card_lift::Lifted {
id: before.id,
progress: 0.,
},
);
}
Some(Changing {
before,
since_landing,
})
});
let veil = self.lifts.veil(id, now);
if lifted.is_empty() && veil == 0. {
return None;
}
// A lifted card of the hand an ally just took goes down as it greys all the same.
let hand = id == self.anvil_grid.entity_id();
let lowered = (self.taken.iter())
.filter(|taken| hand && lifted.iter().any(|lifted| lifted.id == taken.id))
.map(|taken| taken.lowered(now))
.collect();
let grid = grid.read(cx);
Some(crate::card_lift::layer(
grid.cards().clone(),
grid.drawn_cards().clone(),
grid.images().cloned(),
lifted,
changing.map_or(Changes::Taken(lowered), Changes::Match),
veil,
!cx.reduce_motion(),
))
}
/// 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(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,
None => return,
}
if id.is_none() && grid == self.home_grid.entity_id() {
self.release_home(cx);
}
self.ring.update(cx, |ring, cx| ring.set_lit(id, cx));
if self.in_champ_select() {
self.select_art(id, cx);
}
}
}