chiark / gitweb /
new display for ids etc.
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 26 Jun 2020 16:30:28 +0000 (17:30 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 26 Jun 2020 16:30:28 +0000 (17:30 +0100)
src/bin/server.rs
src/gamestate.rs
src/imports.rs
src/pieces.rs

index 634f936e50e93168167b8cdf34c632625bc33aea..5a3c48191ad452e8e5a72fa1e854390526d5e1de 100644 (file)
@@ -74,7 +74,7 @@ fn session(form : Json<SessionForm>) -> Result<Template,RE> {
     for (gpid, pr) in &g.gs.pieces {
       let id : slotmap::KeyData = gpid.into();
       let pri = PieceRenderInstructions {
-        id : id.as_ffi(),
+        id : VisiblePieceId(id.as_ffi()),
         face : pr.face,
       };
       defs.push(pr.p.svg_defs(&pri));
index ceb2d67b0d3bf3ee4e8abc8f0c61f27b67631da0..6d2c328040e081e691be9f61901d469889e3a718 100644 (file)
@@ -5,14 +5,35 @@ slotmap::new_key_type!{
   pub struct PieceId;
 }
 
-type VisiblePieceId = u64;
+pub struct VisiblePieceId (pub u64);
 
+#[derive(Debug)]
 pub struct PieceRenderInstructions {
   pub id : VisiblePieceId,
   pub face : FaceId,
 }
 
+pub type VisiblePieceIdSvgIds = &'static [&'static str];
+
+impl Display for VisiblePieceId {
+  fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
+    write!(f, "{}-{}", self.0 >> 32, self.0 & 0xffffffff)
+  }
+}
+impl Debug for VisiblePieceId {
+  fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
+    <Self as Display>::fmt(self, f)
+  }
+}
+
+impl PieceRenderInstructions {
+  pub fn id_piece(&self) -> String { format!("piece{:}", self.id) }
+  pub fn id_select(&self) -> String { format!("select{:}", self.id) }
+  pub fn id_other(&self, w : &str) -> String { format!("d{}-{}", self.id, w) }
+}
+
 pub trait Piece : Send + Debug {
+  fn svg_other_ids(&self) -> VisiblePieceIdSvgIds;
   fn svg_defs(&self, pri : &PieceRenderInstructions) -> String;
 }
 
index 478a6663618cf969974bffb652963be14738edba..36f54cda1de30a939605a24e139603d9939e6547 100644 (file)
@@ -1,7 +1,7 @@
 
 pub use std::io;
 pub use std::io::{BufReader,Read};
-pub use std::fmt::Debug;
+pub use std::fmt::{self,Display,Debug};
 pub use std::thread;
 pub use std::time::Duration;
 pub use std::sync::{Arc,Mutex,RwLock};
index 3c3d1c99116996a7512fc13d48153e9e36fbfe29..5ba90784b532ec94013b2c0190fcd63ddccf6906 100644 (file)
@@ -12,8 +12,9 @@ struct SimpleShape {
 }
 
 impl Piece for SimpleShape {
+  fn svg_other_ids(&self) -> VisiblePieceIdSvgIds { &["base"] }
   fn svg_defs(&self, pri : &PieceRenderInstructions) -> String {
-    format!(r#"<g id=base{}>{}</g>"#, pri.id, self.shape)
+    format!(r#"<g id={}>{}</g>"#, pri.id_other("base"), self.shape)
   }
 }