scale = 0.20
size = [45]
centre = [22.5, 22.5]
-category = "chess"
item_prefix = "chess-"
stem_prefix = "Chess_"
files = """
size = [448,326]
centre = [224, 163]
scale = 0.025
-category = "management/library-load-marker"
-# xxx this is clumsy, we want to use [[files]]
files = """
-library-load-marker Box_with_polygons a library load area marker
+mgmt-library-load-marker Box_with_polygons a library load area marker
"""
Insn::ListPieces => readonly(ig, {
let pieces = ig.gs.pieces.iter().map(|(piece,p)|{
let &PieceState { pos, face, .. } = p;
- let desc_html = ig.pieces.get(piece)?.describe_html(None);
- Some(MgmtGamePieceInfo { piece, pos, face, desc_html })
+ let pinfo = ig.pieces.get(piece)?;
+ let desc_html = pinfo.describe_html(None);
+ let itemname = pinfo.itemname().to_string();
+ Some(MgmtGamePieceInfo { piece, pos, face, desc_html, itemname })
}).flatten().collect();
Resp::Pieces(pieces)
}),
#[derive(Debug,Clone,Serialize,Deserialize)]
pub struct MgmtGamePieceInfo {
pub piece: PieceId,
+ pub itemname: String,
pub pos: Pos,
pub face: FaceId,
pub desc_html: Html,
-> ExecuteGameChangeUpdates {
ExecuteGameChangeUpdates{ pcs: vec![], log: vec![], raw: None }
}
+
+ fn itemname(&self) -> &str;
}
#[derive(Debug,Copy,Clone)]
scaled_path : Html,
approx_dia : Coord,
colours : ColourMap,
+ itemname: String,
}
pub const SELECT_SCALE : f64 = 1.1;
self.colours.get(face).ok_or(SpecError::FaceNotFound)?;
face
}
+
+ fn itemname(&self) -> &str { &self.itemname }
}
impl SimpleShape {
fn new_from_path(desc: Html, path: Html, approx_dia: Coord,
- faces: &IndexVec<FaceId,ColourSpec>)
+ faces: &IndexVec<FaceId,ColourSpec>,
+ itemname: String)
-> Result<Box<dyn Piece>,SpecError> {
let scaled_path = svg_rescale_path(&path, SELECT_SCALE)?;
let colours = faces
.map(|s| s.try_into())
.collect::<Result<_,SpecError>>()?;
Ok(Box::new(SimpleShape {
- scaled_path, desc, approx_dia, path, colours,
+ scaled_path, desc, approx_dia, path, colours, itemname
}))
}
}
#[throws(SpecError)]
fn load(&self) -> Box<dyn Piece> {
let path = svg_circle_path(self.diam as f64)?;
+ let itemname = self.itemname.clone()
+ .unwrap_or_else(||"simple-disc".to_string());
SimpleShape::new_from_path(Html::lit("circle"), path, self.diam,
- &self.faces)?
+ &self.faces, itemname)?
}
}
};
let path = Html(format!("M {} {} h {} v {} h {} z",
-(x as f64)*0.5, -(y as f64)*0.5, x, y, -x));
+ let itemname = self.itemname.clone()
+ .unwrap_or_else(||"simple-square".to_string());
SimpleShape::new_from_path(Html::lit("square"), path, (x+y+1)/2,
- &self.faces)?
+ &self.faces, itemname)?
}
}
#[derive(Debug,Serialize,Deserialize)]
struct Item {
+ itemname: String,
faces: IndexVec<FaceId, ItemFace>,
desc_hidden: DescId,
descs: IndexVec<DescId, Html>,
None => self.desc_hidden,
}].clone()
}
+
+ fn itemname(&self) -> &str { &self.itemname }
}
impl ItemSpec {
let scale = idata.group.d.scale;
let face = ItemFace { svg: Html(svg_data), desc, centre, scale };
let faces = index_vec![ face ];
- let it = Item { faces, descs, outline, desc_hidden };
+ let it = Item { faces, descs, outline, desc_hidden,
+ itemname: self.item.clone() };
Ok(Box::new(it))
}
}
#[derive(Debug,Serialize,Deserialize)]
pub struct Disc {
+ pub itemname: Option<String>,
pub diam : Coord,
pub faces : IndexVec<FaceId,ColourSpec>,
}
#[derive(Debug,Serialize,Deserialize)]
pub struct Square {
+ pub itemname: Option<String>,
pub size : Vec<Coord>,
pub faces : IndexVec<FaceId,ColourSpec>,
}