[gnome-nibbles/arnaudb/command-line: 6/6] Add --start option.
- From: Arnaud B. <arnaudb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-nibbles/arnaudb/command-line: 6/6] Add --start option.
- Date: Wed, 8 Jul 2020 15:21:23 +0000 (UTC)
commit 4a78a149d867d25f16565582a39b9b0b54325428
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Wed Jul 8 14:45:28 2020 +0200
Add --start option.
Fixes #46.
data/gnome-nibbles.6 | 3 +++
src/gnome-nibbles.vala | 9 ++++++++-
src/nibbles-window.vala | 19 +++++++++++++++----
3 files changed, 26 insertions(+), 5 deletions(-)
---
diff --git a/data/gnome-nibbles.6 b/data/gnome-nibbles.6
index 936ff7b..4f907d2 100644
--- a/data/gnome-nibbles.6
+++ b/data/gnome-nibbles.6
@@ -44,6 +44,9 @@ Set number of players (1-4)
.TP
.B \-p, \-\-speed=NUMBER
Set worms speed (4-1: 4 for slowest and 1 for fastest)
+.TP
+.B \-\-start
+Start playing immediately
.PP
.B \-\-mute
.br
diff --git a/src/gnome-nibbles.vala b/src/gnome-nibbles.vala
index a18bd34..670580e 100644
--- a/src/gnome-nibbles.vala
+++ b/src/gnome-nibbles.vala
@@ -34,6 +34,7 @@ private class Nibbles : Gtk.Application
private static bool disable_fakes = false;
private static bool enable_fakes = false;
+ private static bool start = false;
private static int level = int.MIN;
private static int nibbles = int.MIN;
private static int players = int.MIN;
@@ -74,6 +75,9 @@ private class Nibbles : Gtk.Application
/* Translators: in the command-line options description, text to indicate the user should specify
the worms speed, see 'gnome-nibbles --help' */
N_("NUMBER") },
+ /* Translators: command-line option description, see 'gnome-nibbles --help' */
+ { "start", 0, OptionFlags.NONE, OptionArg.NONE, null, N_("Start playing"),
null },
+
/* Translators: command-line option description, see 'gnome-nibbles --help' */
{ "unmute", 0, OptionFlags.NONE, OptionArg.NONE, null, N_("Turn on the sound"),
null },
@@ -147,6 +151,9 @@ private class Nibbles : Gtk.Application
else if (options.contains ("unmute"))
sound = true;
+ if (options.contains ("start"))
+ start = true;
+
/* Activate */
return -1;
}
@@ -218,7 +225,7 @@ private class Nibbles : Gtk.Application
settings.set_boolean ("sound", (!) sound);
}
- window = new NibblesWindow (level == int.MIN ? 0 : level);
+ window = new NibblesWindow (level == int.MIN ? 0 : level, start);
add_window (window);
}
internal bool on_f1_pressed (Gdk.ModifierType state)
diff --git a/src/nibbles-window.vala b/src/nibbles-window.vala
index f76902d..4676075 100644
--- a/src/nibbles-window.vala
+++ b/src/nibbles-window.vala
@@ -62,6 +62,7 @@ private class NibblesWindow : ApplicationWindow
private NibblesGame? game = null;
public int cli_start_level { private get; internal construct; }
private int start_level { private get { return cli_start_level == 0 ? settings.get_int ("start-level") :
cli_start_level; }}
+ public bool start_playing { private get; internal construct; }
/* Used for handling the game's scores */
private Games.Scores.Context scores_context;
@@ -91,9 +92,9 @@ private class NibblesWindow : ApplicationWindow
{ "back", back_cb } // called on Escape pressed; disabled only during countdown
(TODO pause?)
};
- internal NibblesWindow (int cli_start_level)
+ internal NibblesWindow (int cli_start_level, bool start_playing)
{
- Object (cli_start_level: cli_start_level);
+ Object (cli_start_level: cli_start_level, start_playing: start_playing);
}
construct
@@ -176,8 +177,18 @@ private class NibblesWindow : ApplicationWindow
controls.load_pixmaps (view.tile_size);
/* Check whether to display the first run screen */
- var first_run = settings.get_boolean ("first-run");
- if (first_run)
+ if (start_playing)
+ {
+ game.numhumans = settings.get_int ("players");
+ game.numai = settings.get_int ("ai");
+ game.speed = settings.get_int ("speed");
+ game.fakes = settings.get_boolean ("fakes");
+ game.create_worms ();
+ game.load_worm_properties (worm_settings);
+
+ start_game ();
+ }
+ else if (settings.get_boolean ("first-run"))
{
FirstRun first_run_panel = new FirstRun ();
first_run_panel.show ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]