[lightsoff/arnaudb/save-state: 3/5] Use internal instead of public.




commit b5ecf6e2ebc5e51233d3cd833438073b62e1661e
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Wed Oct 28 16:49:27 2020 +0100

    Use internal instead of public.

 src/board-view-gtk.vala   | 25 ++++++++++---------------
 src/board-view.vala       | 32 ++++++++++++++++----------------
 src/game-view-gtk.vala    | 25 ++++++++++++-------------
 src/game-view.vala        | 33 ++++++++++++++++-----------------
 src/lightsoff-window.vala |  8 ++++----
 src/puzzle-generator.vala |  7 +++----
 6 files changed, 61 insertions(+), 69 deletions(-)
---
diff --git a/src/board-view-gtk.vala b/src/board-view-gtk.vala
index 1673b02..6f314d3 100644
--- a/src/board-view-gtk.vala
+++ b/src/board-view-gtk.vala
@@ -10,21 +10,17 @@
 
 using Gtk;
 
-public class BoardViewGtk : Grid, BoardView
+private class BoardViewGtk : Grid, BoardView
 {
     private PuzzleGenerator puzzle_generator;
     private ToggleButton[,] lights;
 
-    public bool playable = true;
+    internal bool playable { private get; internal set; default = true; }
     private const int MIN_TOGGLE_SIZE = 48;
     private int _moves = 0;
-    public int moves
-    {
-        get { return _moves;}
-    }
-    public int get_moves() { return _moves;}
+    internal int get_moves () { return _moves; }
 
-    public BoardViewGtk ()
+    internal BoardViewGtk ()
     {
         get_style_context ().add_class ("grid");
         row_homogeneous = true;
@@ -58,7 +54,7 @@ public class BoardViewGtk : Grid, BoardView
     // symmetry for some levels.
 
      // Toggle a light and those in each cardinal direction around it.
-    public void toggle_light (int x, int y, bool clicked = true)
+    internal void toggle_light (int x, int y, bool clicked = true)
     {
         if (!playable)
             return;
@@ -82,7 +78,7 @@ public class BoardViewGtk : Grid, BoardView
         @foreach((light) => ((ToggleButton)light).toggled.connect (handle_toggle));
     }
 
-    public void clear_level ()
+    internal void clear_level ()
     {
         /* Clear level */
         for (var x = 0; x < size; x++)
@@ -90,24 +86,23 @@ public class BoardViewGtk : Grid, BoardView
                 lights[x, y].active = false;
     }
 
-    public PuzzleGenerator get_puzzle_generator ()
+    internal PuzzleGenerator get_puzzle_generator ()
     {
         return puzzle_generator;
     }
 
-    public bool is_light_active (int x, int y)
+    internal bool is_light_active (int x, int y)
     {
         return lights[x, y].active;
     }
 
-    public GLib.Object get_light_at (int x, int y)
+    internal GLib.Object get_light_at (int x, int y)
     {
         return lights[x, y];
     }
 
-    public void increase_moves ()
+    internal void increase_moves ()
     {
         _moves += 1;
     }
-
 }
diff --git a/src/board-view.vala b/src/board-view.vala
index 4ae8b28..3893586 100644
--- a/src/board-view.vala
+++ b/src/board-view.vala
@@ -8,27 +8,27 @@
  * license.
  */
 
-public interface BoardView: GLib.Object {
+private interface BoardView: GLib.Object {
 
-    public new const int size = 5;
+    internal new const int size = 5;
 
-    public abstract int get_moves ();
-    public abstract PuzzleGenerator get_puzzle_generator ();
-    public abstract void clear_level ();
-    public abstract void toggle_light (int x, int y, bool user_initiated = true);
-    public abstract void increase_moves ();
-    public abstract bool is_light_active (int x, int y);
+    internal abstract int get_moves ();
+    internal abstract PuzzleGenerator get_puzzle_generator ();
+    internal abstract void clear_level ();
+    internal abstract void toggle_light (int x, int y, bool user_initiated = true);
+    internal abstract void increase_moves ();
+    internal abstract bool is_light_active (int x, int y);
 
-    public abstract GLib.Object get_light_at (int x, int y);
+    internal abstract GLib.Object get_light_at (int x, int y);
 
-    public signal void game_won ();
-    public signal void light_toggled ();
+    internal signal void game_won ();
+    internal signal void light_toggled ();
 
         // Pseudorandomly generates and sets the state of each light based on
     // a level number; hopefully this is stable between machines, but that
     // depends on GLib's PRNG stability. Also, provides some semblance of
     // symmetry for some levels.
-    public void load_level (int level)
+    internal void load_level (int level)
     {
         /* We *must* not have level < 1, as the following assumes a nonzero, nonnegative number */
         if (level < 1)
@@ -49,14 +49,14 @@ public interface BoardView: GLib.Object {
                     toggle_light (x, y, false);
     }
 
-    public void handle_toggle (GLib.Object light)
+    internal void handle_toggle (GLib.Object light)
     {
         int x, y;
         find_light (light, out x, out y);
         move_to (x, y);
     }
 
-    public void find_light (GLib.Object light, out int x, out int y)
+    internal void find_light (GLib.Object light, out int x, out int y)
     {
         x = y = 0;
         for (x = 0; x < size; x++)
@@ -65,7 +65,7 @@ public interface BoardView: GLib.Object {
                     return;
     }
 
-    public void move_to (int x, int y)
+    internal void move_to (int x, int y)
     {
         toggle_light (x, y);
         increase_moves ();
@@ -80,7 +80,7 @@ public interface BoardView: GLib.Object {
         return GLib.Source.REMOVE;
     }
 
-    public bool is_completed ()
+    internal bool is_completed ()
     {
         for (var x = 0; x < size; x++)
             for (var y = 0; y < size; y++)
diff --git a/src/game-view-gtk.vala b/src/game-view-gtk.vala
index 5844c32..df18bf4 100644
--- a/src/game-view-gtk.vala
+++ b/src/game-view-gtk.vala
@@ -8,13 +8,13 @@
 
 using Gtk;
 
-public class GtkGameView : Stack, GameView {
+private class GtkGameView : Stack, GameView {
 
     private BoardViewGtk board_view;
     private int current_level;
     private GLib.Queue<ulong> handlers = new GLib.Queue<ulong>();
 
-    public void replace_board (BoardView old_board, BoardView new_board, GameView.ReplaceStyle style, bool 
fast = true)
+    internal void replace_board (BoardView old_board, BoardView new_board, GameView.ReplaceStyle style, bool 
fast = true)
     {
         transition_duration = fast ? 500 : 1000;
         switch (style)
@@ -42,7 +42,7 @@ public class GtkGameView : Stack, GameView {
         level_changed (current_level);
     }
 
-    public void board_replaced (BoardViewGtk old_board, BoardViewGtk new_board)
+    internal void board_replaced (BoardViewGtk old_board, BoardViewGtk new_board)
     {
         @foreach((board) => { if (board != get_visible_child ()) remove(board);});
         new_board.playable = true;
@@ -51,21 +51,21 @@ public class GtkGameView : Stack, GameView {
             disconnect(handlers.pop_head());
     }
 
-    public bool hide_cursor ()
+    internal bool hide_cursor ()
     {
         queue_draw ();
         return false;
     }
-    public bool activate_cursor ()
+    internal bool activate_cursor ()
     {
         return false;
     }
-    public bool move_cursor (int x, int y)
+    internal bool move_cursor (int x, int y)
     {
         return false;
     }
 
-    public void reset_game ()
+    internal void reset_game ()
     {
         if (is_transitioning())
             return;
@@ -73,14 +73,14 @@ public class GtkGameView : Stack, GameView {
         replace_board (get_board_view (), create_board_view (1), GameView.ReplaceStyle.REFRESH);
     }
 
-    public GtkGameView (int level)
+    internal GtkGameView (int level)
     {
         board_view = (BoardViewGtk)create_board_view (level);
         board_view.playable = true;
         add (board_view);
     }
 
-    public BoardView create_board_view (int level)
+    internal BoardView create_board_view (int level)
     {
         current_level = level;
 
@@ -92,19 +92,18 @@ public class GtkGameView : Stack, GameView {
         return (BoardView)view;
     }
 
-   public BoardView get_board_view ()
+   internal BoardView get_board_view ()
     {
         return (BoardView)board_view;
     }
 
-    public int next_level (int direction) {
+    internal int next_level (int direction) {
         current_level += direction;
         return current_level;
     }
 
-    public bool is_transitioning ()
+    internal bool is_transitioning ()
     {
         return transition_running;
     }
-
 }
diff --git a/src/game-view.vala b/src/game-view.vala
index 00637ab..87e9ec4 100644
--- a/src/game-view.vala
+++ b/src/game-view.vala
@@ -8,31 +8,31 @@
  * license.
  */
 
-public interface GameView : GLib.Object {
+private interface GameView : GLib.Object {
 
-    public enum ReplaceStyle {
+    internal enum ReplaceStyle {
         REFRESH, // crossfade
         SLIDE_FORWARD, // slide out-in
         SLIDE_BACKWARD, // slide in-out
         SLIDE_NEXT // slide over
     }
 
-    public abstract void replace_board (BoardView board_biew, BoardView new_board_view, ReplaceStyle style, 
bool fast = true);
+    internal abstract void replace_board (BoardView board_biew, BoardView new_board_view, ReplaceStyle 
style, bool fast = true);
 
-    public abstract bool hide_cursor ();
-    public abstract bool activate_cursor ();
-    public abstract bool move_cursor (int x, int y);
-    public abstract void reset_game ();
-    public abstract BoardView get_board_view ();
-    public abstract bool is_transitioning ();
-    public abstract int next_level (int direction);
-    public abstract BoardView create_board_view (int level);
+    internal abstract bool hide_cursor ();
+    internal abstract bool activate_cursor ();
+    internal abstract bool move_cursor (int x, int y);
+    internal abstract void reset_game ();
+    internal abstract BoardView get_board_view ();
+    internal abstract bool is_transitioning ();
+    internal abstract int next_level (int direction);
+    internal abstract BoardView create_board_view (int level);
 
     // The player asked to swap to a different level without completing
     // the one in progress; this can occur either by clicking an arrow
     // or by requesting a new game from the menu. Animate the new board
     // in, depthwise, in the direction indicated by 'context'.
-    public void swap_board (int direction)
+    internal void swap_board (int direction)
     {
         if (is_transitioning ())
             return;
@@ -44,7 +44,7 @@ public interface GameView : GLib.Object {
 
     // The player won the game; create a new board, update the level count,
     // and transition between the two boards in a random direction.
-    public void game_won_cb ()
+    internal void game_won_cb ()
     {
         if (is_transitioning ())
             return;
@@ -52,12 +52,11 @@ public interface GameView : GLib.Object {
         replace_board (get_board_view (), create_board_view (next_level (1)), 
GameView.ReplaceStyle.SLIDE_NEXT);
     }
 
-    public void light_toggled_cb ()
+    internal void light_toggled_cb ()
     {
         moves_changed (get_board_view ().get_moves ());
     }
 
-    public signal void level_changed (int level);
-    public signal void moves_changed (int moves);
-
+    internal signal void level_changed (int level);
+    internal signal void moves_changed (int moves);
 }
diff --git a/src/lightsoff-window.vala b/src/lightsoff-window.vala
index e9c432f..408bc7d 100644
--- a/src/lightsoff-window.vala
+++ b/src/lightsoff-window.vala
@@ -13,7 +13,7 @@
 using Gtk;
 
 [GtkTemplate (ui = "/org/gnome/LightsOff/ui/lightsoff.ui")]
-public class LightsoffWindow : ApplicationWindow
+private class LightsoffWindow : ApplicationWindow
 {
     [GtkChild] private HeaderBar headerbar;
     [GtkChild] private MenuButton menu_button;
@@ -36,7 +36,7 @@ public class LightsoffWindow : ApplicationWindow
         key_controller.key_pressed.connect (on_key_pressed);
     }
 
-    public Gtk.Widget build_game_container (int level, out GameView out_game_view)
+    private Gtk.Widget build_game_container (int level, out GameView out_game_view)
     {
         var aspect_frame = new Gtk.AspectFrame (null, 0.5f, 0.5f, 1.0f, false);
         aspect_frame.set_shadow_type (ShadowType.NONE);
@@ -58,7 +58,7 @@ public class LightsoffWindow : ApplicationWindow
         return aspect_frame;
     }
 
-    public LightsoffWindow ()
+    internal LightsoffWindow ()
     {
         settings = new GLib.Settings ("org.gnome.LightsOff");
 
@@ -145,4 +145,4 @@ public class LightsoffWindow : ApplicationWindow
     {
         game_view.reset_game ();
     }
- }
+}
diff --git a/src/puzzle-generator.vala b/src/puzzle-generator.vala
index 1871fc4..b954e70 100644
--- a/src/puzzle-generator.vala
+++ b/src/puzzle-generator.vala
@@ -31,14 +31,14 @@
 // (Certainly, on average, at most half the lights which belong to at least
 // one null set may be used.)
 
-public class PuzzleGenerator : Object
+private class PuzzleGenerator : Object
 {
     private int size;
     private int max_solution_length;
     private int[] region_of;
     private int[] region_size;
 
-    public PuzzleGenerator (int size)
+    internal PuzzleGenerator (int size)
     {
         this.size = size;
         var adj_matrix = new int[size * size, size * size];
@@ -144,7 +144,7 @@ public class PuzzleGenerator : Object
             max_solution_length += (int) Math.floor (region_size[j] / 2);
     }
 
-    public bool[,] minimal_solution (int solution_length)
+    internal bool[,] minimal_solution (int solution_length)
     {
         var sol = new bool[size, size];
         for (var x = 0; x < size; x++)
@@ -205,4 +205,3 @@ public class PuzzleGenerator : Object
         return sol;
     }
 }
-


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