[iagno] Improve code.



commit ffd10a4dde4916de2415b613130fc531816bb233
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Sat Feb 9 13:15:15 2019 +0100

    Improve code.

 src/game-window.vala   | 26 +++++++++-----------------
 src/iagno.vala         | 13 ++++++++-----
 src/themes-dialog.vala |  3 +--
 3 files changed, 18 insertions(+), 24 deletions(-)
---
diff --git a/src/game-window.vala b/src/game-window.vala
index 0b2de4b..a071db2 100644
--- a/src/game-window.vala
+++ b/src/game-window.vala
@@ -40,25 +40,17 @@ private class GameWindow : ApplicationWindow
     private bool game_finished = false;
 
     /* private widgets */
-    [GtkChild]
-    private HeaderBar headerbar;
-    [GtkChild]
-    private Stack stack;
+    [GtkChild] private HeaderBar headerbar;
+    [GtkChild] private Stack stack;
 
     private Button? start_game_button = null;
-    [GtkChild]
-    private Button new_game_button;
-    [GtkChild]
-    private Button back_button;
-
-    [GtkChild]
-    private Box controls_box;
-    [GtkChild]
-    private Box game_box;
-    [GtkChild]
-    private Box new_game_box;
-    [GtkChild]
-    private Box side_box;
+    [GtkChild] private Button new_game_button;
+    [GtkChild] private Button back_button;
+
+    [GtkChild] private Box controls_box;
+    [GtkChild] private Box game_box;
+    [GtkChild] private Box new_game_box;
+    [GtkChild] private Box side_box;
 
     private Widget view;
 
diff --git a/src/iagno.vala b/src/iagno.vala
index 5e2ea05..d4d07ff 100644
--- a/src/iagno.vala
+++ b/src/iagno.vala
@@ -341,7 +341,7 @@ private class Iagno : Gtk.Application
         if (game.current_color != player_one && computer != null && !game.is_complete)
             ((!) computer).move_async.begin (SLOW_MOVE_DELAY);
         else if (game.is_complete)
-            game_complete (false);
+            game_complete (/* play sound */ false);
     }
 
     private void wait_cb ()
@@ -430,7 +430,7 @@ private class Iagno : Gtk.Application
         if (game.current_player_can_move)
             prepare_move ();
         else if (game.is_complete)
-            game_complete ();
+            game_complete (/* play sound */ true);
         else
             pass ();
     }
@@ -471,7 +471,7 @@ private class Iagno : Gtk.Application
         }
     }
 
-    private void game_complete (bool play_gameover_sound = true)
+    private void game_complete (bool play_gameover_sound)
         requires (game_is_set)
     {
         window.finish_game ();
@@ -522,9 +522,12 @@ private class Iagno : Gtk.Application
 
     private void play_sound (Sound sound)
     {
-        if (!settings.get_boolean ("sound"))
-            return;
+        if (settings.get_boolean ("sound"))
+            _play_sound (sound, ref view);
+    }
 
+    private static void _play_sound (Sound sound, ref GameView view)
+    {
         string name;
         switch (sound)
         {
diff --git a/src/themes-dialog.vala b/src/themes-dialog.vala
index a47fb02..701b875 100644
--- a/src/themes-dialog.vala
+++ b/src/themes-dialog.vala
@@ -27,8 +27,7 @@ private class ThemesDialog : Dialog
 
     private GameView view;
 
-    [GtkChild]
-    private ListBox listbox;
+    [GtkChild] private ListBox listbox;
 
     internal ThemesDialog (GLib.Settings settings, GameView view)
     {


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