[iagno] Use internal, not public.



commit d69586708e30262b4ef99e789e1c4e174daa4191
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Thu Feb 7 23:05:19 2019 +0100

    Use internal, not public.

 src/computer-player.vala | 12 +++++-----
 src/game-view.vala       | 30 ++++++++++++------------
 src/game-window.vala     | 36 ++++++++++++++---------------
 src/game.vala            | 60 ++++++++++++++++++++++++------------------------
 src/iagno.vala           |  4 ++--
 src/player.vala          |  8 +++----
 src/test-iagno.vala      |  4 ++--
 src/themes-dialog.vala   |  4 ++--
 8 files changed, 79 insertions(+), 79 deletions(-)
---
diff --git a/src/computer-player.vala b/src/computer-player.vala
index 1234aba..c0914e0 100644
--- a/src/computer-player.vala
+++ b/src/computer-player.vala
@@ -18,7 +18,7 @@
  * along with Iagno. If not, see <http://www.gnu.org/licenses/>.
  */
 
-public class ComputerPlayer : Object
+private class ComputerPlayer : Object
 {
     private struct PossibleMove
     {
@@ -26,7 +26,7 @@ public class ComputerPlayer : Object
         public int y;
         public int n_tiles;
 
-        public PossibleMove (int x, int y, int n_tiles)
+        private PossibleMove (int x, int y, int n_tiles)
         {
             this.x = x;
             this.y = y;
@@ -82,7 +82,7 @@ public class ComputerPlayer : Object
         }
     }
 
-    public ComputerPlayer (Game game, int difficulty_level = 1)
+    internal ComputerPlayer (Game game, int difficulty_level = 1)
     {
         this.game = game;
         this.difficulty_level = difficulty_level;
@@ -98,7 +98,7 @@ public class ComputerPlayer : Object
     }
 
     /* For tests only. */
-    public void move ()
+    internal void move ()
     {
         int x = 0;
         int y = 0;
@@ -107,7 +107,7 @@ public class ComputerPlayer : Object
         complete_move (x, y);
     }
 
-    public async void move_async (double delay_seconds = 0.0)
+    internal async void move_async (double delay_seconds = 0.0)
     {
         var timer = new Timer ();
         int x = 0;
@@ -151,7 +151,7 @@ public class ComputerPlayer : Object
         });
     }
 
-    public void cancel_move ()
+    internal void cancel_move ()
     {
         if (!move_pending)
             return;
diff --git a/src/game-view.vala b/src/game-view.vala
index e940be9..1cff608 100644
--- a/src/game-view.vala
+++ b/src/game-view.vala
@@ -18,12 +18,12 @@
  * along with Iagno. If not, see <http://www.gnu.org/licenses/>.
  */
 
-public class GameView : Gtk.DrawingArea
+private class GameView : Gtk.DrawingArea
 {
     private Gtk.DrawingArea _scoreboard;
-    [CCode (notify = false)] public Gtk.DrawingArea scoreboard {
+    [CCode (notify = false)] internal Gtk.DrawingArea scoreboard {
         private get { return _scoreboard; }
-        set
+        internal set
         {
             _scoreboard = value;
             _scoreboard.draw.connect (draw_scoreboard);
@@ -60,15 +60,15 @@ public class GameView : Gtk.DrawingArea
 
     // private int margin_width = 0;
 
-    [CCode (notify = false)] public string sound_flip     { get; private set; }
-    [CCode (notify = false)] public string sound_gameover { get; private set; }
+    [CCode (notify = false)] internal string sound_flip     { internal get; private set; }
+    [CCode (notify = false)] internal string sound_gameover { internal get; private set; }
 
     /* Utilities, see calculate () */
     private int paving_size;
     private int tile_size;
     private int board_size;
-    [CCode (notify = false)] private int board_x { get { return (get_allocated_width () - board_size) / 2; }}
-    [CCode (notify = false)] private int board_y { get { return (get_allocated_height () - board_size) / 2; 
}}
+    [CCode (notify = false)] private int board_x { private get { return (get_allocated_width () - 
board_size) / 2; }}
+    [CCode (notify = false)] private int board_y { private get { return (get_allocated_height () - 
board_size) / 2; }}
 
     /* Keyboard */
     private bool show_highlight;
@@ -94,14 +94,14 @@ public class GameView : Gtk.DrawingArea
     // private double cursor = 0;
     private int current_player_number = 0;
 
-    public signal void move (int x, int y);
+    internal signal void move (int x, int y);
 
     /* Used for a delay between the last move and flipping the pieces */
     private bool flip_final_result_now = false;
 
     private bool game_is_set = false;
     private Game _game;
-    [CCode (notify = false)] public Game game
+    [CCode (notify = false)] internal Game game
     {
         get
         {
@@ -135,7 +135,7 @@ public class GameView : Gtk.DrawingArea
     }
 
     private string? _theme = null;
-    [CCode (notify = false)] public string? theme
+    [CCode (notify = false)] internal string? theme
     {
         get { return _theme; }
         set {
@@ -235,7 +235,7 @@ public class GameView : Gtk.DrawingArea
         }
     }
 
-    public GameView ()
+    internal GameView ()
     {
         set_events (Gdk.EventMask.EXPOSURE_MASK | Gdk.EventMask.BUTTON_PRESS_MASK | 
Gdk.EventMask.BUTTON_RELEASE_MASK);
         set_size_request (350, 350);
@@ -251,7 +251,7 @@ public class GameView : Gtk.DrawingArea
         board_size = paving_size * game.size - spacing_width;
     }
 
-    public override bool draw (Cairo.Context cr)
+    internal override bool draw (Cairo.Context cr)
     {
         if (!game_is_set)
             return false;
@@ -502,7 +502,7 @@ public class GameView : Gtk.DrawingArea
         }
     }
 
-    public override bool button_press_event (Gdk.EventButton event)
+    internal override bool button_press_event (Gdk.EventButton event)
     {
         if (!game_is_set)
             return false;
@@ -524,7 +524,7 @@ public class GameView : Gtk.DrawingArea
         return true;
     }
 
-    public override bool key_press_event (Gdk.EventKey event)
+    internal override bool key_press_event (Gdk.EventKey event)
     {
         if (!game_is_set)
             return false;
@@ -695,7 +695,7 @@ public class GameView : Gtk.DrawingArea
         return true;
     }
 
-    public void update_scoreboard ()
+    internal void update_scoreboard ()
         requires (game_is_set)
     {
         current_player_number = (game.current_color == Player.DARK) ? 0 : 1;
diff --git a/src/game-window.vala b/src/game-window.vala
index e48bea8..0b2de4b 100644
--- a/src/game-window.vala
+++ b/src/game-window.vala
@@ -21,7 +21,7 @@
 using Gtk;
 
 [Flags]
-public enum GameWindowFlags {
+private enum GameWindowFlags {
     SHOW_UNDO,
     SHOW_REDO,
     SHOW_HINT,
@@ -29,7 +29,7 @@ public enum GameWindowFlags {
 }
 
 [GtkTemplate (ui = "/org/gnome/Reversi/ui/game-window.ui")]
-public class GameWindow : ApplicationWindow
+private class GameWindow : ApplicationWindow
 {
     /* settings */
     private bool tiled_state;
@@ -63,13 +63,13 @@ public class GameWindow : ApplicationWindow
     private Widget view;
 
     /* signals */
-    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 undo ();
-    public signal void redo ();
-    public signal void hint ();
+    internal signal void undo ();
+    internal signal void redo ();
+    internal signal void hint ();
 
     /* actions */
     private const GLib.ActionEntry win_actions[] =
@@ -87,10 +87,10 @@ public class GameWindow : ApplicationWindow
 
     private SimpleAction back_action;
 
-    public SimpleAction undo_action;
-    public SimpleAction redo_action;
+    internal SimpleAction undo_action;
+    internal SimpleAction redo_action;
 
-    public GameWindow (string? css_resource, string name, int width, int height, bool maximized, bool 
start_now, GameWindowFlags flags, Box new_game_screen, Widget _view)
+    internal GameWindow (string? css_resource, string name, int width, int height, bool maximized, bool 
start_now, GameWindowFlags flags, Box new_game_screen, Widget _view)
     {
         if (css_resource != null)
         {
@@ -216,7 +216,7 @@ public class GameWindow : ApplicationWindow
         return false;
     }
 
-    public void shutdown (GLib.Settings settings)
+    internal void shutdown (GLib.Settings settings)
     {
         settings.delay ();
         settings.set_int ("window-width", window_width);
@@ -227,32 +227,32 @@ public class GameWindow : ApplicationWindow
     }
 
     /*\
-    * * Some public calls
+    * * Some internal calls
     \*/
 
-    public void add_to_sidebox (Widget widget)
+    internal void add_to_sidebox (Widget widget)
     {
         side_box.pack_start (widget, false, false, 0);
     }
 
-    public void cannot_undo_more ()
+    internal void cannot_undo_more ()
     {
         undo_action.set_enabled (false);
         view.grab_focus ();
     }
 
-    public void set_subtitle (string? subtitle)
+    internal void set_subtitle (string? subtitle)
     {
         headerbar.set_subtitle (subtitle);
     }
 
-    public void finish_game ()
+    internal void finish_game ()
     {
         game_finished = true;
         new_game_button.grab_focus ();
     }
 
-    /* public void about ()
+    /* internal void about ()
     {
         TODO
     } */
diff --git a/src/game.vala b/src/game.vala
index 9a858ac..e759d3c 100644
--- a/src/game.vala
+++ b/src/game.vala
@@ -18,15 +18,15 @@
  * along with Iagno. If not, see <http://www.gnu.org/licenses/>.
  */
 
-public class Game : Object
+private class Game : Object
 {
     /* Tiles on the board */
     private Player[,] tiles;
 
     private int _size;
-    [CCode (notify = false)] public int size
+    [CCode (notify = false)] internal int size
     {
-        get { return _size; }
+        internal get { return _size; }
         private set { _size = value; }
     }
 
@@ -36,44 +36,44 @@ public class Game : Object
 
     /* Color to move next; Dark always plays first;
      * should be dark if number_of_moves % 2 == 0 */
-    [CCode (notify = false)] public Player current_color { get; private set; default = Player.DARK; }
-    [CCode (notify = false)] public int number_of_moves { get; private set; default = 0; }
+    [CCode (notify = false)] internal Player current_color { internal get; private set; default = 
Player.DARK; }
+    [CCode (notify = false)] internal int number_of_moves { internal get; private set; default = 0; }
 
     /* Indicate who's the next player who can move */
-    [CCode (notify = false)] public bool current_player_can_move { get; private set; default = true; }
+    [CCode (notify = false)] internal bool current_player_can_move { internal get; private set; default = 
true; }
     // there's a race for the final "counter" turn, and looks like notifying here helps, not sure why // 
TODO fix the race
-    [CCode (notify = true)] public bool is_complete { get; private set; default = false; }
+    [CCode (notify = true)] internal bool is_complete { internal get; private set; default = false; }
 
     /* Indicate that a player should move */
-    public signal void turn_ended ();
+    internal signal void turn_ended ();
     /* Indicate a square has changed */
-    public signal void square_changed (int x, int y, Player new_color);
+    internal signal void square_changed (int x, int y, Player new_color);
 
     /*\
     * * Number of tiles on the board
     \*/
 
-    [CCode (notify = false)] public int initial_number_of_tiles { get; private set; }
-    [CCode (notify = false)] public int n_tiles
+    [CCode (notify = false)] internal int initial_number_of_tiles { internal get; private set; }
+    [CCode (notify = false)] internal int n_tiles
     {
-        get { return n_dark_tiles + n_light_tiles; }
+        internal get { return n_dark_tiles + n_light_tiles; }
     }
 
     private int _n_light_tiles = 2;
-    [CCode (notify = false)] public int n_light_tiles
+    [CCode (notify = false)] internal int n_light_tiles
     {
-        get { return _n_light_tiles; }
+        internal get { return _n_light_tiles; }
     }
 
     private int _n_dark_tiles = 2;
-    [CCode (notify = false)] public int n_dark_tiles
+    [CCode (notify = false)] internal int n_dark_tiles
     {
-        get { return _n_dark_tiles; }
+        internal get { return _n_dark_tiles; }
     }
 
-    [CCode (notify = false)] public int n_current_tiles
+    [CCode (notify = false)] internal int n_current_tiles
     {
-        get { return current_color == Player.LIGHT ? n_light_tiles : n_dark_tiles; }
+        internal get { return current_color == Player.LIGHT ? n_light_tiles : n_dark_tiles; }
         private set {
             if (current_color == Player.LIGHT)
                 _n_light_tiles = value;
@@ -82,9 +82,9 @@ public class Game : Object
         }
     }
 
-    [CCode (notify = false)] public int n_opponent_tiles
+    [CCode (notify = false)] internal int n_opponent_tiles
     {
-        get { return current_color == Player.DARK ? n_light_tiles : n_dark_tiles; }
+        internal get { return current_color == Player.DARK ? n_light_tiles : n_dark_tiles; }
         private set {
             if (current_color == Player.DARK)
                 _n_light_tiles = value;
@@ -97,7 +97,7 @@ public class Game : Object
     * * Creation / exporting
     \*/
 
-    public Game (bool alternative_start = false, int tmp_size = 8)
+    internal Game (bool alternative_start = false, int tmp_size = 8)
         requires (tmp_size >= 4)
     {
         size = tmp_size;
@@ -138,7 +138,7 @@ public class Game : Object
         }
     }
 
-    public Game.from_strings (string[] setup, Player to_move, int tmp_size = 8)
+    internal Game.from_strings (string [] setup, Player to_move, int tmp_size = 8)
         requires (setup.length == tmp_size)
     {
         size = tmp_size;
@@ -158,7 +158,7 @@ public class Game : Object
         warn_if_fail (string.joinv ("\n", setup).strip () == to_string ().strip ());
     }
 
-    public string to_string ()
+    internal string to_string ()
     {
         string s = "\n";
 
@@ -172,7 +172,7 @@ public class Game : Object
         return s;
     }
 
-    public Game.copy (Game game)
+    internal Game.copy (Game game)
     {
         size = game.size;
         tiles = new Player[size, size];
@@ -191,18 +191,18 @@ public class Game : Object
     * * Public information
     \*/
 
-    public bool is_valid_location (int x, int y)
+    internal bool is_valid_location (int x, int y)
     {
         return x >= 0 && x < size && y >= 0 && y < size;
     }
 
-    public Player get_owner (int x, int y)
+    internal Player get_owner (int x, int y)
         requires (is_valid_location (x, y))
     {
         return tiles[x, y];
     }
 
-    public bool can_place (int x, int y, Player color)
+    internal bool can_place (int x, int y, Player color)
         requires (is_valid_location (x, y))
         requires (color != Player.NONE)
     {
@@ -224,7 +224,7 @@ public class Game : Object
     * * Actions (apart undo)
     \*/
 
-    public int place_tile (int x, int y, bool apply = true)
+    internal int place_tile (int x, int y, bool apply = true)
         requires (is_valid_location (x, y))
     {
         if (tiles[x, y] != Player.NONE)
@@ -252,7 +252,7 @@ public class Game : Object
         return tiles_turned;
     }
 
-    public void pass ()
+    internal void pass ()
         requires (!current_player_can_move)
     {
         end_of_turn ();
@@ -347,7 +347,7 @@ public class Game : Object
     * * Undo
     \*/
 
-    public void undo (int count = 1)
+    internal void undo (int count = 1)
         requires (count == 1 || count == 2)
         requires (number_of_moves >= count)
         requires (history_index < undo_stack.length)
diff --git a/src/iagno.vala b/src/iagno.vala
index 27edef4..5e2ea05 100644
--- a/src/iagno.vala
+++ b/src/iagno.vala
@@ -20,7 +20,7 @@
 
 using Gtk;
 
-public class Iagno : Gtk.Application
+private class Iagno : Gtk.Application
 {
     /* Translators: application name, as used in the window manager, the window title, the about dialog... */
     internal const string PROGRAM_NAME = _("Iagno");
@@ -101,7 +101,7 @@ public class Iagno : Gtk.Application
         {"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/player.vala b/src/player.vala
index f369b65..1398cfb 100644
--- a/src/player.vala
+++ b/src/player.vala
@@ -18,13 +18,13 @@
  * along with Iagno. If not, see <http://www.gnu.org/licenses/>.
  */
 
-public enum Player
+private enum Player
 {
     NONE,
     DARK,
     LIGHT;
 
-    public string to_string ()
+    internal string to_string ()
     {
         switch (this)
         {
@@ -38,7 +38,7 @@ public enum Player
         }
     }
 
-    public static Player from_char (char c)
+    internal static Player from_char (char c)
         requires (c == 'L' || c == 'D' || c == '.')
     {
         switch (c)
@@ -55,7 +55,7 @@ public enum Player
         }
     }
 
-    public static Player flip_color (Player p)
+    internal static Player flip_color (Player p)
         requires (p != Player.NONE)
     {
         return p == Player.LIGHT ? Player.DARK : Player.LIGHT;
diff --git a/src/test-iagno.vala b/src/test-iagno.vala
index aa7c706..5a2ed3a 100644
--- a/src/test-iagno.vala
+++ b/src/test-iagno.vala
@@ -18,7 +18,7 @@
  * along with Iagno. If not, see <http://www.gnu.org/licenses/>.
  */
 
-public class TestIagno : Object
+private class TestIagno : Object
 {
     private static void test_undo_after_pass ()
     {
@@ -157,7 +157,7 @@ public class TestIagno : Object
         /* didn't crash */
     }
 
-    public static int main (string[] args) {
+    private static int main (string[] args) {
         Test.init (ref args);
         Test.add_func ("/Iagno/Pass then Undo", test_undo_after_pass);
         Test.add_func ("/Iagno/Undo at Start", test_undo_at_start);
diff --git a/src/themes-dialog.vala b/src/themes-dialog.vala
index cec14e4..a47fb02 100644
--- a/src/themes-dialog.vala
+++ b/src/themes-dialog.vala
@@ -21,7 +21,7 @@
 using Gtk;
 
 [GtkTemplate (ui = "/org/gnome/Reversi/ui/themes.ui")]
-public class ThemesDialog : Dialog
+private class ThemesDialog : Dialog
 {
     private const string PREFIX = "theme-";
 
@@ -30,7 +30,7 @@ public class ThemesDialog : Dialog
     [GtkChild]
     private ListBox listbox;
 
-    public ThemesDialog (GLib.Settings settings, GameView view)
+    internal ThemesDialog (GLib.Settings settings, GameView view)
     {
         Gtk.Settings? gtk_settings = Gtk.Settings.get_default ();
         int use_header_bar;


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