From 251773035e7c374139b1a56d2113d4c0d412da63 Mon Sep 17 00:00:00 2001
From: Robert Roth <robert.roth.off@gmail.com>
Date: Sat, 26 Dec 2015 23:12:33 +0200
Subject: [PATCH 2/3] Undo score change with undo move (bgo#756758)
---
src/game.vala | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/src/game.vala b/src/game.vala
index a7dbdf7..732122e 100644
--- a/src/game.vala
+++ b/src/game.vala
@@ -52,6 +52,7 @@ public class Game : GLib.Object
private bool _allow_undo;
private uint _undo_stack_max_size;
private Gee.LinkedList<Grid> _undo_stack;
+ private Gee.LinkedList<uint> _undo_score_stack;
private GLib.Settings _settings;
@@ -83,6 +84,7 @@ public class Game : GLib.Object
_to_show = new Gee.LinkedList<Tile?> ();
_undo_stack = new Gee.LinkedList<Grid> ();
+ _undo_score_stack = new Gee.LinkedList<uint> ();
_allow_undo = _settings.get_boolean ("allow-undo");
_undo_stack_max_size = _settings.get_int ("allow-undo-max");
@@ -107,6 +109,7 @@ public class Game : GLib.Object
{
_grid.clear ();
_undo_stack.clear ();
+ _undo_score_stack.clear ();
// new_game could be called without an existing game
if (_background == null)
_init_background ();
@@ -121,9 +124,12 @@ public class Game : GLib.Object
public void undo ()
{
Grid grid = _undo_stack.poll_head ();
+ uint delta_score = _undo_score_stack.poll_head ();
+
_clear_foreground ();
_grid = grid;
_restore_foreground (false);
+ score -= delta_score;
if (_undo_stack.size == 0)
undo_disabled ();
@@ -204,6 +210,7 @@ public class Game : GLib.Object
allow_undo = _settings.get_boolean ("allow-undo");
if (_allow_undo && !allow_undo) {
_undo_stack.clear ();
+ _undo_score_stack.clear ();
undo_disabled ();
}
_allow_undo = allow_undo;
@@ -649,6 +656,7 @@ public class Game : GLib.Object
delta_score += e.val;
}
score += delta_score;
+ _store_score_update (delta_score);
_create_random_tile ();
@@ -737,4 +745,13 @@ public class Game : GLib.Object
}
}
}
+
+ private void _store_score_update (uint delta_score)
+ {
+ if (_allow_undo) {
+ if (_undo_score_stack.size == _undo_stack_max_size)
+ _undo_score_stack.poll_tail ();
+ _undo_score_stack.offer_head (delta_score);
+ }
+ }
}
--
2.7.0