chiark / gitweb /
fix leave game to not delete all pieces
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 23 Nov 2020 19:20:33 +0000 (19:20 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 23 Nov 2020 19:20:37 +0000 (19:20 +0000)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/global.rs

index 938dba6d96ce9fa2655a7cd0e333d3b7ecf2e2bd..ce1ba7943d29d39fef95da627e819c7c0b52cc73 100644 (file)
@@ -544,13 +544,13 @@ impl<'ig> InstanceGuard<'ig> {
     // New state
     let mut gs = GameState {
       // These parts are straightforward and correct
-      table_size : self.c.g.gs.table_size,
-      gen : self.c.g.gs.gen,
-      max_z : self.gs.max_z.clone(),
+      table_size: self.c.g.gs.table_size,
+      gen: self.c.g.gs.gen,
+      max_z: self.gs.max_z.clone(),
       players,
       // These have special handling
-      log : Default::default(),
-      pieces : Default::default(),
+      logdefault(),
+      piecesdefault(),
     };
 
     let held_by_old = |p: &PieceState| if_chain! {
@@ -580,10 +580,11 @@ impl<'ig> InstanceGuard<'ig> {
     }));
 
     // Handle gs.log:
-    // Installs gs as the new game state, stealing the log
+    // Installs gs as the new game state, stealing the log and pieces
     let mut swap_things = |ig: &mut InstanceGuard| {
-      mem::swap(&mut ig.c.g.gs.log, &mut gs.log);
-      mem::swap(&mut ig.c.g.gs,     &mut gs,   );
+      mem::swap(&mut ig.c.g.gs.log,    &mut gs.log   );
+      mem::swap(&mut ig.c.g.gs.pieces, &mut gs.pieces);
+      mem::swap(&mut ig.c.g.gs,        &mut gs,   );
     };
     swap_things(self);
     undo.push(Box::new(swap_things));