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:
parent
b384f7b792
commit
6724757e09
3 changed files with 96 additions and 1 deletions
|
|
@ -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") {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue