[gnome-taquin] Do not use public.



commit 23e5c5a2954cc60f9f56f3ebd9e4bb01323bc1a8
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Sat Feb 16 20:45:56 2019 +0100

    Do not use public.

 src/config.vapi          | 10 +++++-----
 src/game-headerbar.vala  | 10 +++++-----
 src/game-window.vala     | 18 +++++++++---------
 src/new-game-screen.vala |  4 ++--
 src/taquin-game.vala     | 38 ++++++++++++++++++++------------------
 src/taquin-main.vala     |  2 +-
 src/taquin-view.vala     | 36 ++++++++++++++++++------------------
 src/test-taquin.vala     |  2 +-
 8 files changed, 61 insertions(+), 59 deletions(-)
---
diff --git a/src/config.vapi b/src/config.vapi
index fe76ec0..f2fe20d 100644
--- a/src/config.vapi
+++ b/src/config.vapi
@@ -18,8 +18,8 @@
  * along with Taquin. If not, see <http://www.gnu.org/licenses/>.
  */
 
-public const string VERSION;
-public const string GETTEXT_PACKAGE;
-public const string DATA_DIRECTORY;
-public const string SOUND_DIRECTORY;
-public const string LOCALEDIR;
+private const string VERSION;
+private const string GETTEXT_PACKAGE;
+private const string DATA_DIRECTORY;
+private const string SOUND_DIRECTORY;
+private const string LOCALEDIR;
diff --git a/src/game-headerbar.vala b/src/game-headerbar.vala
index c510ad9..52eb7db 100644
--- a/src/game-headerbar.vala
+++ b/src/game-headerbar.vala
@@ -27,12 +27,12 @@ private class GameHeaderBar : BaseHeaderBar
     [GtkChild] private Button       new_game_button;
     [GtkChild] private Button       back_button;
 
-    public bool window_has_name { private get; protected construct; default = false; }
-    public string window_name   { private get; internal  construct; default = ""; }
+    [CCode (notify = false)] public bool window_has_name { private get; protected construct; default = 
false; }
+    [CCode (notify = false)] public string window_name   { private get; internal  construct; default = ""; }
 
-    public bool show_undo { private get; protected construct; default = false; }
-    public bool show_redo { private get; protected construct; default = false; }
-    public bool show_hint { private get; protected construct; default = false; }    // TODO something
+    [CCode (notify = false)] public bool show_undo { private get; protected construct; default = false; }
+    [CCode (notify = false)] public bool show_redo { private get; protected construct; default = false; }
+    [CCode (notify = false)] public bool show_hint { private get; protected construct; default = false; }    
// TODO something
 
     construct
     {
diff --git a/src/game-window.vala b/src/game-window.vala
index 66d5417..f2ec03d 100644
--- a/src/game-window.vala
+++ b/src/game-window.vala
@@ -21,7 +21,7 @@
 using Gtk;
 
 [Flags]
-public enum GameWindowFlags {
+private enum GameWindowFlags {
     SHORTCUTS,
     SHOW_HELP,
     SHOW_HINT,
@@ -39,7 +39,7 @@ private class GameWindow : BaseWindow, AdaptativeWidget
     private GameView        game_view;
     private Box             new_game_screen;
 
-    public GameWindow (string? css_resource, string name, string about_action_label, bool start_now, 
GameWindowFlags flags, Box _new_game_screen, Widget view_content, NightLightMonitor night_light_monitor)
+    internal GameWindow (string? css_resource, string name, string about_action_label, bool start_now, 
GameWindowFlags flags, Box _new_game_screen, Widget view_content, NightLightMonitor night_light_monitor)
     {
         GameHeaderBar _headerbar = new GameHeaderBar (name, about_action_label, flags, night_light_monitor);
         GameView      _game_view = new GameView (flags, _new_game_screen, view_content);
@@ -146,14 +146,14 @@ private class GameWindow : BaseWindow, AdaptativeWidget
     * * actions
     \*/
 
-    public signal void play ();
-    public signal void wait ();
-    public signal void back ();
+    internal signal void play ();
+    internal signal void wait ();
+    internal signal void back ();
 
-    public signal void restart ();
-    public signal void undo ();
-    public signal void redo ();
-    public signal void hint ();
+    internal signal void restart ();
+    internal signal void undo ();
+    internal signal void redo ();
+    internal signal void hint ();
 
     private SimpleAction restart_action;
     private SimpleAction    undo_action;
diff --git a/src/new-game-screen.vala b/src/new-game-screen.vala
index ddb54f3..546285d 100644
--- a/src/new-game-screen.vala
+++ b/src/new-game-screen.vala
@@ -30,13 +30,13 @@ private class NewGameScreen : Box, AdaptativeWidget
     [GtkChild] private MenuButton size_button;
     [GtkChild] private MenuButton theme_button;
 
-    public void update_size_button_label (int size)
+    internal void update_size_button_label (int size)
     {
         /* Translators: when configuring a new game, button label for the size of the game ("3 × 3", or 4, 
or 5) */
         size_button.set_label (_("Size: %d × %d ▾").printf (size, size));
     }
 
-    public void update_theme (string theme)
+    internal void update_theme (string theme)
     {
         switch (theme)
         {
diff --git a/src/taquin-game.vala b/src/taquin-game.vala
index f1c331c..90247cf 100644
--- a/src/taquin-game.vala
+++ b/src/taquin-game.vala
@@ -18,12 +18,12 @@
  * along with Taquin. If not, see <http://www.gnu.org/licenses/>.
  */
 
-public enum GameType
+private enum GameType
 {
     FIFTEEN,
     SIXTEEN;
 
-    public string to_string ()
+    internal string to_string ()
     {
         switch (this)
         {
@@ -37,12 +37,14 @@ public enum GameType
     }
 }
 
-public class Game : Object
+private class Game : Object
 {
+    [CCode (notify = false)] public int size            { internal get; protected construct; }
+    [CCode (notify = false)] public GameType game_type  { internal get; protected construct; }
+
     /* tiles: -1 is the empty tile, if any */
-    public int[,] tiles { get; private set; }
-    public int size { get; private set; }
-    public GameType game_type { get; private set; }
+    private int [,] tiles;
+    internal int get_tile_value (uint x, uint y) { return tiles [x, y]; }
 
     /* undoing */
     private UndoItem? state = null;
@@ -54,11 +56,11 @@ public class Game : Object
     private int y_gap = 0;
 
     /* signals */
-    public signal void complete ();
-    public signal void move (bool x_axis, int number, int x_gap, int y_gap, uint moves_count, bool 
disable_animation);
-    public signal void bad_click (BadClick reason, bool keyboard_call);
+    internal signal void complete ();
+    internal signal void move (bool x_axis, int number, int x_gap, int y_gap, uint moves_count, bool 
disable_animation);
+    internal signal void bad_click (BadClick reason, bool keyboard_call);
 
-    public enum BadClick {
+    internal enum BadClick {
         EMPTY_TILE,
         NOT_MOVING,
         IS_OUTSIDE,
@@ -69,12 +71,12 @@ public class Game : Object
     * * Creation / exporting
     \*/
 
-    public Game (GameType game_type = GameType.FIFTEEN, int size = 4)
+    internal Game (GameType game_type = GameType.FIFTEEN, int size = 4)
         requires (size >= 2)
     {
-        this.size = size;
-        this.game_type = game_type;
-        tiles = new int[size, size];
+        Object (game_type: game_type, size: size);
+
+        tiles = new int [size, size];
 
         do { generate_game (); } while (check_complete ());
     }
@@ -124,7 +126,7 @@ public class Game : Object
         }
     }
 
-    public string to_string ()
+    internal string to_string ()
     {
         string s = "\n";
 
@@ -142,7 +144,7 @@ public class Game : Object
     * * Game code
     \*/
 
-    public void request_move (int x, int y, bool keyboard_call)
+    internal void request_move (int x, int y, bool keyboard_call)
     {
         if (game_type == GameType.FIFTEEN)
         {
@@ -310,7 +312,7 @@ public class Game : Object
         public UndoItem? previous;
     }
 
-    public void undo ()
+    internal void undo ()
     {
         if (state == null)
             return;
@@ -324,7 +326,7 @@ public class Game : Object
         previous_state = state == null ? null : ((!) state).previous;
     }
 
-    public void restart ()
+    internal void restart ()
     {
         while (state != null)
         {
diff --git a/src/taquin-main.vala b/src/taquin-main.vala
index 7a1849f..20f7e96 100644
--- a/src/taquin-main.vala
+++ b/src/taquin-main.vala
@@ -80,7 +80,7 @@ private class Taquin : Gtk.Application, BaseApplication
         {"quit", quit}
     };
 
-    public static int main (string[] args)
+    private static int main (string [] args)
     {
         Intl.setlocale (LocaleCategory.ALL, "");
         Intl.bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
diff --git a/src/taquin-view.vala b/src/taquin-view.vala
index 6df48c5..35808f4 100644
--- a/src/taquin-view.vala
+++ b/src/taquin-view.vala
@@ -20,7 +20,7 @@
 
 using Gdk;
 
-public enum Direction
+private enum Direction
 {
     TOP,
     LEFT,
@@ -29,7 +29,7 @@ public enum Direction
     NONE;
 }
 
-public class TaquinView : Gtk.DrawingArea
+private class TaquinView : Gtk.DrawingArea
 {
     /* Theme */
     private const int GRID_SPACING = 1;
@@ -40,8 +40,8 @@ public class TaquinView : Gtk.DrawingArea
     /* Utilities */
     private int tile_size;
     private int board_size;
-    private int x_offset { get { return (get_allocated_width () - board_size) / 2 - grid_border_main; }}
-    private int y_offset { get { return (get_allocated_height () - board_size) / 2 - grid_border_main; }}
+    [CCode (notify = false)] private int x_offset { get { return (get_allocated_width ()  - board_size) / 2 
- grid_border_main; }}
+    [CCode (notify = false)] private int y_offset { get { return (get_allocated_height () - board_size) / 2 
- grid_border_main; }}
 
     private void calculate ()
     {
@@ -73,17 +73,17 @@ public class TaquinView : Gtk.DrawingArea
     private bool finished = false;
     private double animation_end_offset;
 
-    public TaquinView ()
+    internal TaquinView ()
     {
         can_focus = true;
         set_events (EventMask.EXPOSURE_MASK | EventMask.BUTTON_PRESS_MASK | EventMask.BUTTON_RELEASE_MASK | 
EventMask.KEY_PRESS_MASK);
     }
 
     private Game? _game = null;
-    public Game game
+    [CCode (notify = false)] internal Game game
     {
-        get { if (_game == null) assert_not_reached (); return (!) _game; }
-        set
+        private get { if (_game == null) assert_not_reached (); return (!) _game; }
+        internal set
         {
             if (_game != null)
                 SignalHandler.disconnect_by_func (_game, null, this);
@@ -106,10 +106,10 @@ public class TaquinView : Gtk.DrawingArea
     }
 
     private string? _theme = null;
-    public string theme
+    [CCode (notify = false)] internal string theme
     {
-        get { if (_theme == null) assert_not_reached (); return (!) _theme; }
-        set
+        private get { if (_theme == null) assert_not_reached (); return (!) _theme; }
+        internal set
         {
             _theme = value;
             if (_theme == null)
@@ -119,7 +119,7 @@ public class TaquinView : Gtk.DrawingArea
         }
     }
 
-    public override bool draw (Cairo.Context cr)
+    protected override bool draw (Cairo.Context cr)
     {
 //        if (game == null)
 //            return false;
@@ -160,8 +160,8 @@ public class TaquinView : Gtk.DrawingArea
 
         if (animate && game.game_type == GameType.SIXTEEN)  // TODO less verbose
         {
-            var texture_x = game.tiles[x_gap, y_gap] % game.size * tile_size;
-            var texture_y = game.tiles[x_gap, y_gap] / game.size * tile_size;
+            var texture_x = game.get_tile_value (x_gap, y_gap) % game.size * tile_size;
+            var texture_y = game.get_tile_value (x_gap, y_gap) / game.size * tile_size;
 
             /* the uncovered tile */
             var tile_x = x_gap * tile_size;
@@ -214,8 +214,8 @@ public class TaquinView : Gtk.DrawingArea
                     }
                 }
 
-                var texture_x = game.tiles[x, y] % game.size * tile_size;
-                var texture_y = game.tiles[x, y] / game.size * tile_size;
+                var texture_x = game.get_tile_value (x, y) % game.size * tile_size;
+                var texture_y = game.get_tile_value (x, y) / game.size * tile_size;
 
                 var matrix = Cairo.Matrix.identity ();
                 matrix.translate (texture_x - tile_x, texture_y - tile_y);
@@ -474,7 +474,7 @@ public class TaquinView : Gtk.DrawingArea
             });
     }
 
-    public override bool button_press_event (EventButton event)
+    internal override bool button_press_event (EventButton event)
     {
         if (animate || animate_end)
             return true;
@@ -488,7 +488,7 @@ public class TaquinView : Gtk.DrawingArea
         return true;
     }
 
-    public override bool key_press_event (Gdk.EventKey event)
+    protected override bool key_press_event (Gdk.EventKey event)
     {
         if (finished)
             return false;
diff --git a/src/test-taquin.vala b/src/test-taquin.vala
index 80273de..7665ab4 100644
--- a/src/test-taquin.vala
+++ b/src/test-taquin.vala
@@ -98,6 +98,6 @@ private class TestTaquin : Object
     }
     private static bool compare_value (ref Game game, uint x, uint y, uint k)
     {
-        return game.tiles [x, y] + 1 == k;
+        return game.get_tile_value (x, y) + 1 == k;
     }
 }


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