From: Ian Jackson Date: Sat, 30 Jan 2021 01:25:32 +0000 (+0000) Subject: wdt: Provide ActionChainExt::move_pc for convenience X-Git-Tag: otter-0.4.0~626 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=13af7399a4edee9ba6fafd2342889a39e3c9f9ce;p=otter.git wdt: Provide ActionChainExt::move_pc for convenience And use it in one place. NFC. Signed-off-by: Ian Jackson --- diff --git a/wdriver.rs b/wdriver.rs index ee832335..ba36e26e 100644 --- a/wdriver.rs +++ b/wdriver.rs @@ -1201,6 +1201,8 @@ pub trait ActionChainExt: Sized { P: TryInto> (self, pos: P) -> Result where Result: anyhow::Context; + + fn move_pc<'g>(self, w: &'g WindowGuard, pc: &str) -> Result; } impl<'a> ActionChainExt for t4::action_chain::ActionChain<'a> { @@ -1225,6 +1227,16 @@ impl<'a> ActionChainExt for t4::action_chain::ActionChain<'a> { .context("find coordinate")?; self.move_pos(pos)? } + + #[throws(AE)] + fn move_pc<'g>(self, w: &'g WindowGuard, pc: &str) -> Self { + (||{ + let p = w.find_piece(pc).context("find")?; + let pos = p.posw().context("get pos")?; + let r = self.move_pos(pos).context("move")?; + Ok::<_,AE>(r) + })().with_context(|| format!("piece {}", pc))? + } } impl Drop for Setup { diff --git a/wdriver/wdt-simple.rs b/wdriver/wdt-simple.rs index a3d1e533..d500409b 100644 --- a/wdriver/wdt-simple.rs +++ b/wdriver/wdt-simple.rs @@ -167,7 +167,7 @@ impl Ctx { let pc = "4.1"; let w = su.w(&self.alice)?; w.action_chain() - .move_w(&w, w.find_piece(pc)?.posg()?)? + .move_pc(&w, pc)? .click(); }