[gnome-2048] Range allow-undo-max.



commit 0a91d88be28b262ed12137d88ad75887bf503af5
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Sat Jan 26 09:54:29 2019 +0100

    Range allow-undo-max.
    
    Disallow setting unmeaningful values.

 data/org.gnome.2048.gschema.xml | 3 ++-
 src/game.vala                   | 8 ++++----
 2 files changed, 6 insertions(+), 5 deletions(-)
---
diff --git a/data/org.gnome.2048.gschema.xml b/data/org.gnome.2048.gschema.xml
index ab64a13..5c58fc0 100644
--- a/data/org.gnome.2048.gschema.xml
+++ b/data/org.gnome.2048.gschema.xml
@@ -65,8 +65,9 @@
       <!-- Translators: description of a settings key, see 'dconf-editor /org/gnome/2048/allow-undo' -->
       <description>Whether tile movements can be undone.</description>
     </key>
-    <key name="allow-undo-max" type="i">
+    <key name="allow-undo-max" type="u">
       <default>10</default>
+      <range min="1"/>
       <!-- Translators: summary of a settings key, see 'dconf-editor /org/gnome/2048/allow-undo-max' -->
       <summary>Number of undo movements</summary>
       <!-- Translators: description of a settings key, see 'dconf-editor /org/gnome/2048/allow-undo-max' -->
diff --git a/src/game.vala b/src/game.vala
index e0aee9a..da896ad 100644
--- a/src/game.vala
+++ b/src/game.vala
@@ -95,7 +95,7 @@ public class Game : Object
         _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");
+        _undo_stack_max_size = _settings.get_uint ("allow-undo-max");
 
         _saved_path = Path.build_filename (Environment.get_user_data_dir (), "gnome-2048", "saved");
 
@@ -223,7 +223,7 @@ public class Game : Object
             undo_disabled ();
         }
         _allow_undo = allow_undo;
-        _undo_stack_max_size = _settings.get_int ("allow-undo-max");
+        _undo_stack_max_size = _settings.get_uint ("allow-undo-max");
 
         rows = _settings.get_int ("rows");
         cols = _settings.get_int ("cols");
@@ -764,7 +764,7 @@ public class Game : Object
         if (!_allow_undo)
             return;
 
-        if (_undo_stack.size == _undo_stack_max_size)
+        if (_undo_stack.size >= _undo_stack_max_size)
             _undo_stack.poll_tail ();
         _undo_stack.offer_head (_grid.clone ());
         if (_undo_stack.size == 1)
@@ -776,7 +776,7 @@ public class Game : Object
         if (!_allow_undo)
             return;
 
-        if (_undo_score_stack.size == _undo_stack_max_size)
+        if (_undo_score_stack.size >= _undo_stack_max_size)
             _undo_score_stack.poll_tail ();
         _undo_score_stack.offer_head (delta_score);
     }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]