chiark / gitweb /
clock: wip, skeleton
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Tue, 16 Mar 2021 18:16:23 +0000 (18:16 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 19 Mar 2021 20:05:30 +0000 (20:05 +0000)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
specs/penultima.game.toml
src/clock.rs [new file with mode: 0644]
src/lib.rs

index 81000f44ef4f8445d115e411d8f63e79314cdb8d..d55e4f92492d72d0ce967f5aa78386aa2bde2e78 100644 (file)
@@ -142,7 +142,7 @@ items = ["K","Q","R","R","B","B","N","N"]
 posd = [10, 0]
 
 [[pieces]]
-pos = [210, 85]
+pos = [210, 45]
 type = "LibList"
 lib = "wikimedia"
 prefix = "chess-purple-"
@@ -150,7 +150,7 @@ items = ["K","Q","R","R","B","B","N","N"]
 posd = [10, 0]
 
 [[pieces]]
-pos = [205, 115]
+pos = [205, 125]
 type = "LibList"
 lib = "wikimedia"
 prefix = "chess-w-"
@@ -159,7 +159,7 @@ items = ["commoner","elephant","knight-king","mann","zebra",
 posd = [10, 0]
 
 [[pieces]]
-pos = [205, 125]
+pos = [205, 135]
 type = "LibList"
 lib = "wikimedia"
 prefix = "chess-w-"
@@ -168,7 +168,7 @@ items = ["commoner","elephant","knight-king","mann","zebra",
 posd = [10, 0]
 
 [[pieces]]
-pos = [205, 135]
+pos = [205, 145]
 type = "LibList"
 lib = "wikimedia"
 prefix = "chess-b-"
@@ -177,7 +177,7 @@ items = ["commoner","elephant","knight-king","mann","zebra",
 posd = [10, 0]
 
 [[pieces]]
-pos = [205, 145]
+pos = [205, 155]
 type = "LibList"
 lib = "wikimedia"
 prefix = "chess-b-"
@@ -192,3 +192,7 @@ edge = "white"
 colour = "grey"
 shape.type = "Rectangle"
 shape.xy = [20,10]
+
+[[pieces]]
+pos = [240, 100]
+type = "ChessClock"
diff --git a/src/clock.rs b/src/clock.rs
new file mode 100644 (file)
index 0000000..3598af0
--- /dev/null
@@ -0,0 +1,63 @@
+// Copyright 2020-2021 Ian Jackson and contributors to Otter
+// SPDX-License-Identifier: AGPL-3.0-or-later
+// There is NO WARRANTY.
+
+use crate::prelude::*;
+use shapelib::Rectangle;
+
+const W: Coord = 50;
+const H: Coord = 20;
+const OUTLINE: Rectangle = Rectangle { xy: PosC([W as f64, H as f64]) };
+
+#[derive(Debug,Clone,Serialize,Deserialize)]
+pub struct ChessClock { // spec
+}
+
+#[derive(Debug,Serialize,Deserialize)]
+struct Clock { // state
+}
+
+#[typetag::serde]
+impl PieceSpec for ChessClock {
+  #[throws(SpecError)]
+  fn load(&self, _: usize) -> PieceSpecLoaded {
+    let clock = Clock {
+
+    };
+    PieceSpecLoaded {
+      p: Box::new(clock),
+      occultable: None,
+    }
+  }
+}
+
+#[dyn_upcast]
+impl OutlineTrait for Clock {
+  delegate!{
+    to OUTLINE {
+      fn outline_path(&self, scale: f64) -> Result<Html, IE>;
+      fn thresh_dragraise(&self) -> Result<Option<Coord>, IE>;
+      fn bbox_approx(&self) -> Result<[Pos;2], IE>;
+    }
+  }
+}
+
+#[typetag::serde(name="ChessClock")]
+impl PieceTrait for Clock {
+  fn nfaces(&self) -> RawFaceId { 1 }
+
+  #[throws(IE)]
+  fn svg_piece(&self, f: &mut Html, _gpc: &GPiece, id: VisiblePieceId) {
+    dbgc!("rendering", id);
+    write!( &mut f.0, r##"
+        <rect fill="black" width="10" height="10"/>
+    "##)?;
+  }
+
+  #[throws(IE)]
+  fn describe_html(&self, _gpc: &GPiece) -> Html {
+    Html::lit("the chess clock")
+  }
+
+  fn itemname(&self) -> &str { "chess-clock" }
+}
index 1c4072c106151c4f3e47f12a2195bae9d3c76c14..1703862cd1cd4314bb8a3b99e92c888e9118f79b 100644 (file)
@@ -10,6 +10,7 @@ pub mod prelude;
 
 pub mod accounts;
 pub mod authproofs;
+pub mod clock;
 pub mod commands;
 pub mod config;
 pub mod debugreader;