[swell-foop/arnaudb/history: 1/7] Unduplicate code.
- From: Arnaud B. <arnaudb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [swell-foop/arnaudb/history: 1/7] Unduplicate code.
- Date: Fri, 22 May 2020 22:09:53 +0000 (UTC)
commit 82e7169e8e3feeed98493b647dbebfed12936ddb
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Mon May 18 10:30:53 2020 +0200
Unduplicate code.
src/game.vala | 4 ++--
src/window.vala | 35 +++++++++++------------------------
2 files changed, 13 insertions(+), 26 deletions(-)
---
diff --git a/src/game.vala b/src/game.vala
index 8afb739..1ddee5b 100644
--- a/src/game.vala
+++ b/src/game.vala
@@ -95,10 +95,10 @@ private class Game : Object
internal signal void started ();
/* Constructor */
- internal Game (uint8 rows, uint8 columns, uint8 color_num, Variant? variant = null)
+ internal Game (uint8 rows, uint8 columns, uint8 color_num, Variant? saved_game)
{
Object (rows: rows, columns: columns, color_num: color_num);
- if (variant == null || !load_saved_game ((!) variant))
+ if (saved_game == null || !load_saved_game ((!) saved_game))
create_new_game ();
}
diff --git a/src/window.vala b/src/window.vala
index 74ee0c4..1fad528 100644
--- a/src/window.vala
+++ b/src/window.vala
@@ -123,24 +123,8 @@ private class SwellFoopWindow : ApplicationWindow
{
Object (application: application);
- /* Create an instance of game, either with a saved game, or with initial values for row, column and
color */
- Size size = get_board_size ();
- game = new Game (size.rows, size.columns, (uint8) settings.get_int ("colors"), settings.get_value
("saved-game"));
- update_score_cb (game.score);
- if (game.score != 0)
- game_in_progress = true;
+ new_game (settings.get_value ("saved-game"));
- /* Game score change will be sent to the main window and show in the score label */
- game.update_score.connect (update_score_cb);
- game.complete.connect (complete_cb);
- game.started.connect (started_cb);
-
- /* Initialize the themes needed by actors */
- view.set_theme_name (settings.get_string ("theme"));
- view.set_is_zealous (settings.get_boolean ("zealous"));
- view.set_game ((!) game);
-
- /* When the mouse leaves the window we need to update the view */
init_motion ();
}
@@ -211,25 +195,28 @@ private class SwellFoopWindow : ApplicationWindow
}
/*\
- * * internal calls
+ * * various calls
\*/
- internal void new_game ()
+ private void new_game (Variant? saved_game = null)
{
Size size = get_board_size ();
game = new Game (size.rows,
size.columns,
- (uint8) settings.get_int ("colors"));
+ (uint8) settings.get_int ("colors"),
+ saved_game);
+ game_in_progress = game.score != 0;
+ update_score_cb (game.score);
+
+ /* Game score change will be sent to the main window and show in the score label */
game.update_score.connect (update_score_cb);
game.complete.connect (complete_cb);
game.started.connect (started_cb);
+
+ /* Initialize the themes needed by actors */
view.set_theme_name (settings.get_string ("theme"));
view.set_is_zealous (settings.get_boolean ("zealous"));
view.set_game ((!) game);
-
- game_in_progress = false;
-
- update_score_cb (0);
}
protected override void destroy ()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]