dev hooks: CP_BEST_DELAY / CP_BEST_EXIT_AFTER — the better line on a timer after the notation is drawn

This commit is contained in:
vrubelroman 2026-11-27 14:29:08 +03:00
parent b384f7b792
commit 6724757e09
3 changed files with 96 additions and 1 deletions

View file

@ -944,7 +944,18 @@ impl App {
g.debug_show_report();
}
if let Some(k) = std::env::var("CP_BEST").ok().and_then(|v| v.parse().ok()) {
g.debug_best_line(k);
// `CP_BEST_DELAY=<ms>`: the line opens that long after the notation is first
// drawn (`CP_BEST_EXIT_AFTER=<ms>`: and closes that long after it opened).
let ms = |name| {
std::env::var(name)
.ok()
.and_then(|v| v.parse::<u64>().ok())
.map(|ms| ms as f64 / 1000.0)
};
match ms("CP_BEST_DELAY") {
Some(delay) => g.debug_best_line_later(k, delay, ms("CP_BEST_EXIT_AFTER")),
None => g.debug_best_line(k),
}
}
// CP_REVIEW=ask presses «Analyse», any other value starts the analysis.
if let Ok(v) = std::env::var("CP_REVIEW") {

View file

@ -122,6 +122,19 @@ pub struct GameView {
shapes_hint: Option<bool>,
/// An arrow or a circle went into the game on this frame (the hint has done its job).
shape_drawn: bool,
/// Dev hook `CP_BEST_DELAY`: the better line to open after the notation is drawn.
debug_best: Option<DebugBest>,
}
/// The better line opened on a timer (screenshots of the notation before, during and
/// after the line); times in seconds.
struct DebugBest {
shown: usize,
delay: f64,
exit: Option<f64>,
/// When the notation was first drawn.
start: Option<f64>,
opened: bool,
}
#[derive(Clone, Copy, PartialEq, Eq)]
@ -246,6 +259,7 @@ impl GameView {
shape_counts: None,
shapes_hint: None,
shape_drawn: false,
debug_best: None,
}
}
@ -1721,6 +1735,7 @@ impl GameView {
self.translation.translate(ui.ctx(), settings, hub);
}
self.shape_counts();
self.debug_best_tick(ui.ctx());
egui::ScrollArea::vertical()
.auto_shrink(false)
.show(ui, |ui| {
@ -2302,6 +2317,50 @@ impl GameView {
}
}
/// `debug_best_line` `delay` s after the notation is first drawn; closed (as by a
/// click on the game's move) `exit` s after it opened.
pub fn debug_best_line_later(&mut self, shown: usize, delay: f64, exit: Option<f64>) {
self.debug_best = Some(DebugBest {
shown,
delay,
exit,
start: None,
opened: false,
});
}
fn debug_best_tick(&mut self, ctx: &egui::Context) {
let Some(mut d) = self.debug_best.take() else {
return;
};
let now = ctx.input(|i| i.time);
let start = *d.start.get_or_insert(now);
if !d.opened {
if now - start >= d.delay {
self.debug_best_line(d.shown);
d.opened = true;
d.start = Some(now);
} else {
ctx.request_repaint_after(std::time::Duration::from_secs_f64(
d.delay - (now - start),
));
}
self.debug_best = Some(d);
return;
}
match d.exit {
Some(exit) if now - start >= exit => {
let base = self.cursor;
self.goto(base);
}
Some(exit) => {
ctx.request_repaint_after(std::time::Duration::from_secs_f64(exit - (now - start)));
self.debug_best = Some(d);
}
None => {}
}
}
/// Opens the better line of the first engine-marked move up to its `shown`-th move.
pub fn debug_best_line(&mut self, shown: usize) {
let mark = self

View file

@ -0,0 +1,25 @@
# Экран партии: dev-хуки для снимков
Окна — только через `scripts/dev/headless-run.sh`, профиль изолированный
(`XDG_CONFIG_HOME`, `XDG_DATA_HOME`, `XDG_CACHE_HOME` во временный каталог).
Снимок: `CP_SCREENSHOT=file.png CP_SCREENSHOT_DELAY=<сек>` (по умолчанию 4 с).
| Переменная | Что делает |
| --- | --- |
| `CP_OPEN=<n>` | открыть партию № n (с 0) первой базы на полке |
| `CP_PLY=<n>` | встать на n-й полуход основной линии |
| `CP_SHAPE=Ge2e4,Rd5` | нарисовать стрелки/круги на текущем ходу (как правой кнопкой; подсказка о стрелках считается выполненной) |
| `CP_HINT_RESET=1` | сбросить одноразовые подсказки (`settings.hints`), подсказка о стрелках покажется снова |
| `CP_BEST=<k>` | открыть «лучшую линию» первого отмеченного движком хода до k-го хода — **до** первой отрисовки нотации (нужен готовый анализ партии в кэше профиля) |
| `CP_BEST_DELAY=<мс>` | вместе с `CP_BEST`: открыть линию через столько мс **после** первой отрисовки нотации (подсказка о стрелках успевает решиться и показаться) |
| `CP_BEST_EXIT_AFTER=<мс>` | вместе с `CP_BEST_DELAY`: выйти из просмотра линии через столько мс после её открытия (как щелчок по ходу партии) |
Пример серии для задачи 43, Д1 (верх блока нотации до, во время и после просмотра линии):
```
# до: CP_OPEN=0 CP_PLY=4 CP_HINT_RESET=1 CP_SCREENSHOT_DELAY=4
# во время: … CP_BEST=2 CP_BEST_DELAY=1000 CP_SCREENSHOT_DELAY=4
# после: … CP_BEST=2 CP_BEST_DELAY=1000 CP_BEST_EXIT_AFTER=1000 CP_SCREENSHOT_DELAY=4
```
Время отсчитывается по часам egui; задержка снимка должна быть больше суммы задержек хуков.