#[derive(Serialize,Debug)]
struct SessionRenderContext {
clientid : u64,
+ defs : Vec<String>,
}
#[derive(Deserialize)]
let user = g.users.get_mut(iad.user).ok_or_else(|| anyhow!("user deleted"))?;
let client = Client { };
let clientid : slotmap::KeyData = user.clients.insert(client).into();
- SessionRenderContext { clientid : clientid.as_ffi() }
+
+ let mut defs = vec![];
+ for (gpid, pr) in &g.gs.pieces {
+ let id : slotmap::KeyData = gpid.into();
+ let pri = PieceRenderInstructions {
+ id : id.as_ffi(),
+ face : pr.face,
+ };
+ defs.push(pr.p.svg_defs(&pri));
+ }
+
+ SessionRenderContext {
+ clientid : clientid.as_ffi(),
+ defs,
+ }
};
Ok(Template::render("test",&c))
}
let _ = {
let mut g = iad.i.lock().map_err(|e| anyhow!("lock poison {:?}",&e))?;
let user = g.users.get_mut(iad.user).ok_or_else(|| anyhow!("user deleted"))?;
- let client = user.clients.get_mut(clientid).ok_or_else(|| anyhow!("client deleted"))?;
+ let _client = user.clients.get_mut(clientid).ok_or_else(|| anyhow!("client deleted"))?;
};
let tc = TestCounterInner { next : 0 };
let tc = BufReader::new(tc);
pub struct PieceId;
}
+type VisiblePieceId = u64;
+
+pub struct PieceRenderInstructions {
+ pub id : VisiblePieceId,
+ pub face : FaceId,
+}
+
pub trait Piece : Send + Debug {
+ fn svg_defs(&self, pri : &PieceRenderInstructions) -> String;
}
#[derive(Debug)]
pub struct PieceRecord {
- pos : Pos,
- p : Box<dyn Piece>,
- face : FaceId,
- held : Option<UserId>,
+ pub pos : Pos,
+ pub p : Box<dyn Piece>,
+ pub face : FaceId,
+ pub held : Option<UserId>,
}
#[derive(Debug)]
}
impl Piece for SimpleShape {
+ fn svg_defs(&self, pri : &PieceRenderInstructions) -> String {
+ format!(r#"<g id=base{}>{}</g>"#, pri.id, self.shape)
+ }
}
pub fn xxx_make_pieces() -> Vec<(Pos, Box<dyn Piece>)> {
vec![
- ([ 50, 80 ],
+ ([ 90, 80 ],
Box::new(SimpleShape {
shape : r#"<circle cx="0" cy="0" r="10"/>"#.to_owned(),
colours : index_vec![ "red".to_string(), "grey".to_string() ],
})),
- ([ 50, 60 ],
+ ([ 90, 60 ],
Box::new(SimpleShape {
shape : r#"<rect x="-10" y="-10" width="20" height="20"/>"#.to_owned(),
colours : index_vec![ "blue".to_string(), "grey".to_string() ],
<use href="#piece43" data-p="43" x="50" y="60" />
<use href="#select43" x="50" y="60" />
<defs>
+{% for piece in defs %}{{piece}}{% endfor %}
<g id="piece42">
<circle
cx="0" cy="0"