chiark / gitweb /
new itemname regime
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 26 Sep 2020 19:18:37 +0000 (20:18 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 26 Sep 2020 19:18:37 +0000 (20:18 +0100)
itemnames are now global in scope, and there is no separate "category"

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
library/wikimedia.toml
src/cmdlistener.rs
src/commands.rs
src/gamestate.rs
src/pieces.rs
src/shapelib.rs
src/spec.rs

index 23e61e240cf6af613b7601052c1496d879097181..a646de19be6a543fa3ca4cd9ca6e99e87fafc948 100644 (file)
@@ -19,7 +19,6 @@ outline = "Circle"
 scale = 0.20
 size = [45]
 centre = [22.5, 22.5]
-category = "chess"
 item_prefix = "chess-"
 stem_prefix = "Chess_"
 files = """
@@ -101,8 +100,6 @@ outline = "Square"
 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
 """
index 7f2983999b91004e36498689af63cb771bd1b2bd..5ec818460bf96683cdd21da60c934c29ca12eac3 100644 (file)
@@ -163,8 +163,10 @@ fn execute_game_insn(cs: &CommandStream,
     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)
     }),
index b14083562ee1643210e879055d17f65680f9a27b..aa0d932fcfb50e1ddbbe8113ed1ab23bc51bfb8b 100644 (file)
@@ -62,6 +62,7 @@ pub struct MgmtGameResponseGameInfo {
 #[derive(Debug,Clone,Serialize,Deserialize)]
 pub struct MgmtGamePieceInfo {
   pub piece: PieceId,
+  pub itemname: String,
   pub pos: Pos,
   pub face: FaceId,
   pub desc_html: Html,
index 0d231c54fd6755f38cadfab5bd40906fc223016e..9cabc5aa7e9159daf8e58471c01d0075bf94a065 100644 (file)
@@ -103,6 +103,8 @@ pub trait Piece : Outline + Send + Debug {
                  -> ExecuteGameChangeUpdates { 
     ExecuteGameChangeUpdates{ pcs: vec![], log: vec![], raw: None }
   }
+
+  fn itemname(&self) -> &str;
 }
 
 #[derive(Debug,Copy,Clone)]
index 36d9ab9ce249934f5cb36f05d00554a1e7d54387..f313cbeea4efc5880199d479edce7d0779493190 100644 (file)
@@ -16,6 +16,7 @@ struct SimpleShape {
   scaled_path : Html,
   approx_dia : Coord,
   colours : ColourMap,
+  itemname: String,
 }
 
 pub const SELECT_SCALE : f64 = 1.1;
@@ -134,11 +135,14 @@ impl Piece for SimpleShape {
     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
@@ -146,7 +150,7 @@ impl SimpleShape {
       .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
     }))
   }
 }
@@ -156,8 +160,10 @@ impl PieceSpec for piece_specs::Disc {
   #[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)?
   }
 }
 
@@ -172,7 +178,9 @@ impl PieceSpec for piece_specs::Square {
     };
     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)?
   }
 } 
index 53c324e1222f49582b4f28c84591e63348b8760f..50d339dc6974e425df1913d5cdb5ef4e141a1002 100644 (file)
@@ -132,6 +132,7 @@ struct ItemFace {
 
 #[derive(Debug,Serialize,Deserialize)]
 struct Item {
+  itemname: String,
   faces: IndexVec<FaceId, ItemFace>,
   desc_hidden: DescId,
   descs: IndexVec<DescId, Html>,
@@ -171,6 +172,8 @@ impl Piece for Item {
       None => self.desc_hidden,
     }].clone()
   }
+
+  fn itemname(&self) -> &str { &self.itemname }
 }
 
 impl ItemSpec {
@@ -204,7 +207,8 @@ 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))
   }
 }
index b0a033e7a0867d3b83598f7a4d50f1d2036aff4c..6e217ff94b1890d8214d902a3206706012e4a9fb 100644 (file)
@@ -91,12 +91,14 @@ pub mod piece_specs {
 
   #[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>,
   }