[gnome-tetravex] Add restore command-line option.



commit 5d1e4367401214c511739aea81fab13e57947f47
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Wed Oct 16 03:08:40 2019 +0200

    Add restore command-line option.

 data/gnome-tetravex.6   |  3 +++
 src/gnome-tetravex.vala | 16 +++++++++++++---
 2 files changed, 16 insertions(+), 3 deletions(-)
---
diff --git a/data/gnome-tetravex.6 b/data/gnome-tetravex.6
index bf12d36..dd994b1 100644
--- a/data/gnome-tetravex.6
+++ b/data/gnome-tetravex.6
@@ -33,6 +33,9 @@ Set number of colors (2-10)
 .B \-p, \-\-paused
 Start the game paused
 .TP
+.B \-r, \-\-restore
+Restore last game, if any
+.TP
 .B \-s, \-\-size=SIZE
 Set size of board (2-6)
 .TP
diff --git a/src/gnome-tetravex.vala b/src/gnome-tetravex.vala
index 9715286..f70f0f7 100644
--- a/src/gnome-tetravex.vala
+++ b/src/gnome-tetravex.vala
@@ -29,6 +29,7 @@ private class Tetravex : Gtk.Application
     private const string KEY_GRID_SIZE = "grid-size";
 
     private static bool start_paused = false;
+    private static bool restore_on_start = false;
     private static int game_size = int.MIN;
     private static int colors = 10;
 
@@ -72,6 +73,9 @@ private class Tetravex : Gtk.Application
         /* Translators: command-line option description, see 'gnome-tetravex --help' */
         { "paused",  'p', OptionFlags.NONE, OptionArg.NONE, null,          N_("Start the game paused"),      
    null },
 
+        /* Translators: command-line option description, see 'gnome-tetravex --help' */
+        { "restore", 'r', OptionFlags.NONE, OptionArg.NONE, null,          N_("Restore last game, if any"),  
    null },
+
         /* Translators: command-line option description, see 'gnome-tetravex --help' */
         { "size",    's', OptionFlags.NONE, OptionArg.INT,  ref game_size, N_("Set size of board (2-6)"),
 
@@ -132,6 +136,9 @@ private class Tetravex : Gtk.Application
         if (options.contains ("paused"))
             start_paused = true;
 
+        if (options.contains ("restore"))
+            restore_on_start = true;
+
         if (game_size != int.MIN && (game_size < 2 || game_size > 6))
         {
             /* Translators: command-line error message, displayed on invalid game size request; see 
'gnome-tetravex -s 1' */
@@ -239,7 +246,7 @@ private class Tetravex : Gtk.Application
         undo_redo_box.pack_start (redo_button);
         undo_redo_box.show ();
 
-        if (can_restore)
+        if (can_restore && !restore_on_start)
         {
             restore_stack = new Stack ();
             restore_stack.hhomogeneous = false;
@@ -375,7 +382,10 @@ private class Tetravex : Gtk.Application
         window.show_all ();
 
         tick_cb ();
-        new_game ();
+        if (can_restore && restore_on_start)
+            new_game (saved_game);
+        else
+            new_game ();
     }
     private class BottomButton : Button
     {
@@ -493,7 +503,7 @@ private class Tetravex : Gtk.Application
             undo_action.set_enabled (puzzle.can_undo && !puzzle.is_solved && !puzzle.paused));
         puzzle.notify ["can-redo"].connect (() =>
             redo_action.set_enabled (puzzle.can_redo && !puzzle.is_solved && !puzzle.paused));
-        if (can_restore)
+        if (can_restore && !restore_on_start)
             puzzle.tile_moved.connect (hide_restore_button);
         puzzle.show_end_game.connect (show_end_game_cb);
         view.puzzle = puzzle;


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