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));
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;
}
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};
}
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)
}
}