chiark / gitweb /
wip pos thing
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 31 Dec 2020 00:51:56 +0000 (00:51 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 31 Dec 2020 00:51:56 +0000 (00:51 +0000)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
wdriver.rs
wdriver/wdt-simple.rs

index 5665af3854f125f70d8cd3ae41135fd5af2f80bb..836ec68cb72f8e64ba7c21b8bc2d94f4e2d0a4f0 100644 (file)
@@ -44,9 +44,10 @@ pub use std::time;
 pub use otter::commands::{MgmtCommand, MgmtResponse};
 pub use otter::commands::{MgmtGameInstruction, MgmtGameResponse};
 pub use otter::commands::{MgmtGameUpdateMode};
-pub use otter::gamestate::Generation;
+pub use otter::gamestate::{self, Generation};
 pub use otter::global::InstanceName;
 pub use otter::mgmtchannel::MgmtChannel;
+pub use otter::spec::{Coord, Pos, PosC};
 
 pub type T4d = t4::WebDriver;
 pub type WDE = t4::error::WebDriverError;
@@ -737,7 +738,7 @@ impl Debug for WindowGuard<'_> {
 
 impl<'g> WindowGuard<'g> {
   #[throws(AE)]
-  fn find_piece(&'g self, pieceid: &'g str) -> PieceElement<'g> {
+  pub fn find_piece(&'g self, pieceid: &'g str) -> PieceElement<'g> {
     let id = format!("use{}", pieceid);
     let elem = self.su.driver.find_element(By::Id(&id))?;
     PieceElement {
@@ -765,7 +766,18 @@ impl<'g> Deref for PieceElement<'g> {
 
 impl<'g> PieceElement<'g> {
   #[throws(AE)]
-  fn pos(&self) -> WebPos {
+  pub fn posg(&self) -> Pos {
+    (||{
+      let x = self.get_attribute("x")?.ok_or(anyhow!("x"))?.parse()?;
+      let y = self.get_attribute("x")?.ok_or(anyhow!("y"))?.parse()?;
+      Ok::<_,AE>(PosC([x,y]))
+    })()
+      .with_context(|| self.pieceid.to_owned())
+      .context("read position of piece out of x,y attributes")?
+  }
+
+  #[throws(AE)]
+  pub fn pos(&self) -> WebPos {
     (||{
       Ok::<_,AE>( todo!() )
     })()
index 99df7246dc3e7c5a4f48ec70958f657dea6905f5..b615bd02a2f2ede3a33de63846cba5591df1248a 100644 (file)
@@ -19,18 +19,17 @@ fn main(){
     {
       let mut w = su.w(&alice)?;
       w.synch()?;
-      let p1 = w.find_element(By::Id("use1.1"))?;
+      let p1 = w.find_piece("1.1")?;
       let p2 = w.find_element(By::Id("use2.1"))?;
 
       dbg!(p1.rect()?,
            p1.tag_name(),
            p1.class_name(),
            p1.id(),
-           p1.text(),
+           p1.get_attribute("x"),
+           p1.get_attribute("y"),
+           p1.posg(),
       );
-      dbg!(p2.rect()?);
-      dbg!(w.find_element(By::Id("use3.1"))?.rect()?);
-      dbg!(w.find_element(By::Id("use4.1"))?.rect()?);
       
       w.action_chain()
         .move_to_element_center(&p1)