chiark / gitweb /
occult ilks: find piece ilk and record it - BREAKING
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 11 Mar 2021 11:19:45 +0000 (11:19 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 11 Mar 2021 11:29:12 +0000 (11:29 +0000)
This brakes savefiles because we need to put something different in
IPieces.  We can't sensibly mix a Box<dyn PieceTrait> with anything
else.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
daemon/cmdlistener.rs
src/global.rs

index a8f5a7e89e35496626bac9be8043a390522582b0..368d60017f83069243bab312c8e359afe9968fce 100644 (file)
@@ -559,7 +559,7 @@ fn execute_game_insn<'cs, 'igr, 'ig: 'igr>(
 
     MGI::DeletePiece(piece) => {
       let (ig, modperm, _) = cs.check_acl_modify_pieces(ag, ig)?;
-      let IPiece { p } = ig.ipieces.as_mut(modperm)
+      let IPiece { p, occilk } = ig.ipieces.as_mut(modperm)
         .remove(piece).ok_or(ME::PieceNotFound)?;
       let gs = &mut ig.gs;
       let gpc = gs.pieces.as_mut(modperm).remove(piece);
@@ -570,6 +570,7 @@ fn execute_game_insn<'cs, 'igr, 'ig: 'igr>(
         Html::lit("<piece partially missing from game state!>")
       };
       if let Some(gpc) = gpc { p.delete_hook(&gpc, gs); }
+      if let Some(occilk) = occilk { ig.ioccults.ilks.dispose(occilk); }
       (U{ pcs: vec![(piece, PieceUpdateOp::Delete())],
           log: vec![ LogEntry {
             html: Html(format!("A piece {} was removed from the game",
@@ -608,7 +609,10 @@ fn execute_game_insn<'cs, 'igr, 'ig: 'igr>(
       let mut z = gs.max_z.clone_mut();
       for piece_i in count {
         let PieceSpecLoaded { p, occultable } = info.load(piece_i as usize)?;
-        let _ = occultable; // xxx
+        let ilks = &mut ig.ioccults.ilks;
+        let occilk = occultable.map(|(ilkname, p_occ)| {
+          ilks.insert(ilkname, OccultIlkData { p_occ })
+        });
         let face = face.unwrap_or_default();
         if p.nfaces() <= face.into() {
           throw!(SpecError::FaceNotFound);
@@ -628,7 +632,7 @@ fn execute_game_insn<'cs, 'igr, 'ig: 'igr>(
         gpc.pos.clamped(gs.table_size).map_err(|_| SpecError::PosOffTable)?;
         if gpc.zlevel.z > gs.max_z { gs.max_z = gpc.zlevel.z.clone() }
         let piece = gs.pieces.as_mut(modperm).insert(gpc);
-        ig.ipieces.as_mut(modperm).insert(piece, IPiece { p });
+        ig.ipieces.as_mut(modperm).insert(piece, IPiece { p, occilk });
         updates.push((piece, PieceUpdateOp::Insert(())));
         pos = (pos + posd)?;
       }
index 2e093a598b610596345623db9b8976d4ec4b32ed..af8aec63830ebac0cc724575a5f5f416d9c200d8 100644 (file)
@@ -70,8 +70,8 @@ pub struct IPlayer { // usual variable: ipl
 
 #[derive(Debug,Serialize,Deserialize)]
 pub struct IPiece {
-  #[serde(flatten)]
   pub p: Box<dyn PieceTrait>,
+  pub occilk: Option<OccultIlkOwningId>,
 }
 
 #[derive(Debug,Serialize,Deserialize)]