From: Ian Jackson Date: Mon, 23 Nov 2020 19:20:33 +0000 (+0000) Subject: fix leave game to not delete all pieces X-Git-Tag: otter-0.2.0~375 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=dacd0eb325f6fd0a0a4dec316aadd67a783c7540;p=otter.git fix leave game to not delete all pieces Signed-off-by: Ian Jackson --- diff --git a/src/global.rs b/src/global.rs index 938dba6d..ce1ba794 100644 --- a/src/global.rs +++ b/src/global.rs @@ -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(), + log: default(), + pieces: default(), }; 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));