[gnome-nibbles/arnaudb/command-line: 3/6] Add --disable-fakes and --enable-fakes options.



commit e4ff18ea83a388ac0f19bdfda346906988d1bac2
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Wed Jul 8 12:23:09 2020 +0200

    Add --disable-fakes and --enable-fakes options.

 data/gnome-nibbles.6   |  6 ++++++
 src/gnome-nibbles.vala | 32 ++++++++++++++++++++++++++++----
 2 files changed, 34 insertions(+), 4 deletions(-)
---
diff --git a/data/gnome-nibbles.6 b/data/gnome-nibbles.6
index 8c01fae..90fa606 100644
--- a/data/gnome-nibbles.6
+++ b/data/gnome-nibbles.6
@@ -27,6 +27,12 @@ board, eating diamonds while avoiding the walls placed around it.
 The game can be played against the computer or against other players.
 .SH OPTIONS
 .TP
+.B \-d, \-\-disable-fakes
+Disable fake bonuses; cannot be set with \-\-enable-fakes
+.TP
+.B \-e, \-\-enable-fakes
+Enable fake bonuses; cannot be set with \-\-disable-fakes
+.TP
 .B \-n, \-\-nibbles=NUMBER
 Set number of nibbles (4-6)
 .TP
diff --git a/src/gnome-nibbles.vala b/src/gnome-nibbles.vala
index 44db603..b849017 100644
--- a/src/gnome-nibbles.vala
+++ b/src/gnome-nibbles.vala
@@ -32,11 +32,19 @@ private class Nibbles : Gtk.Application
         {"quit", quit}
     };
 
-    private static int nibbles = int.MIN;
-    private static int players = int.MIN;
-    private static int speed   = int.MIN;
+    private static bool disable_fakes   = false;
+    private static bool enable_fakes    = false;
+    private static int nibbles          = int.MIN;
+    private static int players          = int.MIN;
+    private static int speed            = int.MIN;
     private const OptionEntry[] option_entries =
     {
+        /* Translators: command-line option description, see 'gnome-nibbles --help' */
+        { "disable-fakes",  'd', OptionFlags.NONE, OptionArg.NONE,  null,           N_("Disable fake 
bonuses"),                 null },
+
+        /* Translators: command-line option description, see 'gnome-nibbles --help' */
+        { "enable-fakes",   'e', OptionFlags.NONE, OptionArg.NONE,  null,           N_("Enable fake 
bonuses"),                  null },
+
         /* Translators: command-line option description, see 'gnome-nibbles --help' */
         { "nibbles",        'n', OptionFlags.NONE, OptionArg.INT,   ref nibbles,    N_("Set number of 
nibbles (4-6)"),
 
@@ -105,6 +113,15 @@ private class Nibbles : Gtk.Application
             return Posix.EXIT_FAILURE;
         }
 
+        disable_fakes = options.contains ("disable-fakes");
+        enable_fakes  = options.contains ("enable-fakes");
+        if (disable_fakes && enable_fakes)
+        {
+            /* Translators: command-line error message, displayed for an invalid combination of options; see 
'gnome-nibbles -d -e' */
+            stderr.printf (_("Options --disable-fakes (-d) and --enable-fakes (-e) are mutually exclusive.") 
+ "\n");
+            return Posix.EXIT_FAILURE;
+        }
+
         /* Activate */
         return -1;
     }
@@ -141,7 +158,9 @@ private class Nibbles : Gtk.Application
         bool players_changed = players != int.MIN;
         if (nibbles_changed
          || players_changed
-         || speed != int.MIN)
+         || speed != int.MIN
+         || disable_fakes
+         || enable_fakes)
         {
             GLib.Settings settings = new GLib.Settings ("org.gnome.Nibbles");
             if (nibbles_changed && players_changed)
@@ -163,6 +182,11 @@ private class Nibbles : Gtk.Application
 
             if (speed != int.MIN)
                 settings.set_int ("speed", speed);
+
+            if (disable_fakes)
+                settings.set_boolean ("fakes", false);
+            else if (enable_fakes)
+                settings.set_boolean ("fakes", true);
         }
 
         window = new NibblesWindow ();


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