Scripted keys can be held from one time to another

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
localandClaude Opus 5.5 committed 2026-11-25 07:19:34 -06:00
1 parent c618881373
commit 2acfdfb380
1 file changed
+11 -8
+11 -8
View File
@@ -1246,12 +1246,13 @@ mod host {
}
/// Debugging aid: `VICTORY_KEYS=<seconds>:<key>,...` holds each key for
/// 0.2 s that long after input starts, with or without focus. A key is a
/// 0.2 s that long after input starts (`<from>-<to>:<key>`: all that
/// time), with or without focus. A key is a
/// letter, a digit, or `Enter`, `Esc`, `Tab`, `Back`, `Up`, `Down`,
/// `Left`, `Right` (the stand-in pad's table maps them to buttons).
#[cfg(feature = "diagnostics")]
fn scripted() -> Vec<u8> {
static SCRIPT: LazyLock<(Instant, Vec<(Duration, u8)>)> = LazyLock::new(|| {
static SCRIPT: LazyLock<(Instant, Vec<(Duration, Duration, u8)>)> = LazyLock::new(|| {
let list = std::env::var("VICTORY_KEYS").unwrap_or_default();
let keys = list.split(',').filter_map(|entry| {
let (at, key) = entry.split_once(':')?;
@@ -1269,18 +1270,20 @@ mod host {
}
_ => return None,
};
Some((
Duration::try_from_secs_f64(at.trim().parse().ok()?).ok()?,
vk,
))
let time = |t: &str| Duration::try_from_secs_f64(t.trim().parse().ok()?).ok();
let (from, to) = match at.split_once('-') {
Some((from, to)) => (time(from)?, time(to)?),
None => (time(at)?, time(at)? + Duration::from_millis(200)),
};
Some((from, to, vk))
});
(Instant::now(), keys.collect())
});
let (start, keys) = &*SCRIPT;
let now = start.elapsed();
keys.iter()
.filter(|&&(at, _)| (at..at + Duration::from_millis(200)).contains(&now))
.map(|&(_, vk)| vk)
.filter(|&&(from, to, _)| (from..to).contains(&now))
.map(|&(_, _, vk)| vk)
.collect()
}