app: draw the whole timeline under the review scrubber

Every event in the recording gets a tick: kills and deaths coloured by
whether they were the player's, objectives and LP changes in the accent,
game start and end muted. Highlights sit on the track as bands.

The summoner carries a #TAG that the live client data's KillerName does
not, so involvement never matched and every game showed 0 highlights.
Names are compared without the tag now.
This commit is contained in:
vhaudiquet committed 2026-11-15 23:34:23 +01:00
1 parent e7a36c3129
commit 17c73925bf
2 files changed
+109 -34

No files matched your search

+32 -5
View File
@@ -70,18 +70,34 @@ fn string_at<'a>(event: &'a TimelineEvent, key: &str) -> Option<&'a str> {
event.raw_data.get(key).and_then(|v| v.as_str())
}
fn involves(event: &TimelineEvent, player: &str) -> Option<Kind> {
if string_at(event, "KillerName") == Some(player) {
/// Whether a name from the live client data is the player. The timeline's summoner carries a
/// `#TAG` (`Kai'Sa#EUW`) that the live client data's `KillerName` does not, so the tag is
/// dropped before comparing.
fn same_player(name: &str, player: &str) -> bool {
fn base(n: &str) -> &str {
n.split('#').next().unwrap_or(n).trim()
}
base(name).eq_ignore_ascii_case(base(player))
}
/// How the player took part in a kill event, if at all.
pub fn involvement(event: &TimelineEvent, player: &str) -> Option<Kind> {
if string_at(event, "KillerName").is_some_and(|name| same_player(name, player)) {
return Some(Kind::Kill);
}
if string_at(event, "VictimName") == Some(player) {
if string_at(event, "VictimName").is_some_and(|name| same_player(name, player)) {
return Some(Kind::Death);
}
let assist = event
.raw_data
.get("Assisters")
.and_then(|v| v.as_array())
.is_some_and(|a| a.iter().any(|n| n.as_str() == Some(player)));
.is_some_and(|names| {
names
.iter()
.filter_map(|name| name.as_str())
.any(|name| same_player(name, player))
});
if assist {
return Some(Kind::Assist);
}
@@ -101,7 +117,7 @@ pub fn compute(timeline: &Timeline, player: Option<&str>, options: Options) -> V
let mut player_deaths: Vec<f64> = Vec::new();
for event in kills {
let Some(kind) = involves(event, player) else {
let Some(kind) = involvement(event, player) else {
continue;
};
let at = event.time();
@@ -242,6 +258,17 @@ mod tests {
assert!(clips.iter().all(|c| c.end > c.start));
}
#[test]
fn the_tag_in_the_summoner_does_not_hide_the_player() {
let game = &crate::history::sample()[0];
let clips = compute(game, Some("Demo"), Options::default());
assert_eq!(
clips.len(),
3,
"the live client names carry no tag: {clips:#?}"
);
}
#[test]
fn nobody_named_means_no_clips() {
let game = &crate::history::sample()[0];
+77 -29
View File
@@ -207,7 +207,7 @@ pub fn view(app: &App, p: Paint) -> El {
.gap(space::S3)
.child(header)
.child(video_stage(app, p))
.child(scrubber(app, p))
.child(scrubber(app, p, game))
.child(
row()
.key("review-body")
@@ -317,7 +317,7 @@ fn playing(app: &App) -> bool {
app.review.player.as_ref().is_some_and(Player::is_playing)
}
fn scrubber(app: &App, p: Paint) -> El {
fn scrubber(app: &App, p: Paint, game: &Timeline) -> El {
let width = if app.review.scrubber_width > 0.0 {
app.review.scrubber_width
} else {
@@ -326,6 +326,7 @@ fn scrubber(app: &App, p: Paint) -> El {
let duration = app.review.duration.max(0.001);
let progress = (app.review.time / duration).clamp(0.0, 1.0) as f32;
let knob = 14.0;
let player = game.summoner();
let mut bar = el()
.key("scrubber")
@@ -333,7 +334,7 @@ fn scrubber(app: &App, p: Paint) -> El {
.label("Playback position")
.range_value(app.review.time, 0.0, duration)
.w_full()
.h(26.0)
.h(34.0)
.on_layout(|app: &mut App, [_, _, w, _]| {
app.review.scrubber_width = w;
})
@@ -351,38 +352,77 @@ fn scrubber(app: &App, p: Paint) -> El {
el().key("track")
.w_full()
.h(6.0)
.absolute(0.0, 10.0)
.absolute(0.0, 12.0)
.radius(3.0)
.fill(p.t.control_off)
.a11y_hidden(),
)
.child(
el().key("played")
.w((width * progress).max(2.0))
.h(6.0)
.absolute(0.0, 10.0)
.radius(3.0)
.fill(p.accent)
.a11y_hidden(),
);
// Each highlight as a band on the track, so the clip it exports is visible at a glance.
for (index, clip) in app.review.highlights.iter().enumerate() {
let x = (clip.start / duration).clamp(0.0, 1.0) as f32 * (width - 6.0);
let start = clip.start;
bar = bar.child(
el().key(format!("marker-{index}"))
.role("button")
.label(format!("{} at {}", clip.kind.label(), format::clock(start)))
.w(6.0)
.h(12.0)
.absolute(x, 2.0)
.radius(3.0)
.fill(match clip.kind {
let x = (clip.start / duration).clamp(0.0, 1.0) as f32 * width;
let end = (clip.end / duration).clamp(0.0, 1.0) as f32 * width;
let ink = match clip.kind {
highlight::Kind::Death => p.danger(),
highlight::Kind::Assist => p.muted(),
_ => p.success(),
})
.on_press(move |app: &mut App| app.review.seek(start))
};
bar = bar.child(
el().key(format!("clip-{index}"))
.w((end - x).max(4.0))
.h(6.0)
.absolute(x, 12.0)
.radius(3.0)
.fill(ink.alpha(0.32))
.a11y_hidden(),
);
}
bar = bar.child(
el().key("played")
.w((width * progress).max(2.0))
.h(6.0)
.absolute(0.0, 12.0)
.radius(3.0)
.fill(p.accent.alpha(0.55))
.a11y_hidden(),
);
// One tick per timeline event, below the track: every kill, objective and change the
// recording has, not only the player's own.
for (index, event) in game.events.iter().enumerate() {
let at = event.time();
if !at.is_finite() || at < 0.0 || at > duration {
continue;
}
let x = (at / duration) as f32 * (width - 2.0);
let involvement = player
.as_deref()
.and_then(|name| highlight::involvement(event, name));
let ink = match event.event_type.as_str() {
"kill" => match involvement {
Some(highlight::Kind::Death) => p.danger(),
Some(_) => p.success(),
None => p.muted().alpha(0.75),
},
"objective" | "lp_change" => p.accent,
"game_start" | "game_end" => p.muted(),
_ => p.muted().alpha(0.5),
};
let label = match involvement {
Some(kind) => kind.label().to_string(),
None if event.description.is_empty() => event.event_type.clone(),
None => event.description.clone(),
};
bar = bar.child(
el().key(format!("event-tick-{index}"))
.role("button")
.label(format!("{label} at {}", format::clock(at)))
.w(2.0)
.h(9.0)
.absolute(x, 21.0)
.fill(ink)
.on_press(move |app: &mut App| app.review.seek(at))
.a11y_hidden(),
);
}
@@ -390,7 +430,7 @@ fn scrubber(app: &App, p: Paint) -> El {
bar.child(
el().key("knob")
.size(knob, knob)
.absolute(progress * (width - knob), 6.0)
.absolute(progress * (width - knob), 8.0)
.radius(knob / 2.0)
.fill(p.t.knob)
.shadow(1.0, 3.0, p.t.knob_shadow)
@@ -403,7 +443,11 @@ fn highlights(app: &App, p: Paint, game: &Timeline) -> El {
let mut list = col().key("highlight-rows").w_full().gap(4.0);
if app.review.highlights.is_empty() {
list = list.child(
text("No kills or deaths in this recording.")
text(if game.events.is_empty() {
"No timeline was saved for this recording."
} else {
"No kills or deaths in this recording."
})
.key("no-highlights")
.font(body(12.0))
.color(p.muted())
@@ -517,6 +561,7 @@ fn highlights(app: &App, p: Paint, game: &Timeline) -> El {
.color(p.muted()),
)
.child(
app.highlights_scroll.follow(
col()
.key("highlight-scroller")
.w_full()
@@ -526,10 +571,11 @@ fn highlights(app: &App, p: Paint, game: &Timeline) -> El {
stick_bottom: false,
})
.child(list),
),
)
}
fn events(_app: &App, p: Paint, game: &Timeline) -> El {
fn events(app: &App, p: Paint, game: &Timeline) -> El {
let interesting = |kind: &str| {
matches!(
kind,
@@ -605,6 +651,7 @@ fn events(_app: &App, p: Paint, game: &Timeline) -> El {
.color(p.muted()),
)
.child(
app.events_scroll.follow(
col()
.key("event-scroller")
.w_full()
@@ -614,5 +661,6 @@ fn events(_app: &App, p: Paint, game: &Timeline) -> El {
stick_bottom: false,
})
.child(list),
),
)
}