[five-or-more/arnaudb/kill-preferences-dialog: 3/10] Do not share settings with Game.
- From: Arnaud B. <arnaudb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [five-or-more/arnaudb/kill-preferences-dialog: 3/10] Do not share settings with Game.
- Date: Fri, 8 May 2020 16:02:23 +0000 (UTC)
commit 95703f254a4a254420f43b96ea97299359f6d33b
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Thu May 7 13:15:43 2020 +0200
Do not share settings with Game.
src/game.vala | 18 +++++-------------
src/window.vala | 10 ++++++++--
2 files changed, 13 insertions(+), 15 deletions(-)
---
diff --git a/src/game.vala b/src/game.vala
index a9eb387..42edd72 100644
--- a/src/game.vala
+++ b/src/game.vala
@@ -27,9 +27,7 @@ private class Game : Object
internal const int N_ANIMATIONS = 4;
internal const int N_MATCH = 5;
- private Settings settings;
-
- private int size;
+ public int size { private get; internal construct set; }
private NextPiecesGenerator next_pieces_generator;
internal Board? board = null;
@@ -102,16 +100,9 @@ private class Game : Object
internal StatusMessage status_message { get; set; }
- internal Game (Settings settings)
+ internal Game (int size)
{
- this.settings = settings;
-
- size = settings.get_int (FiveOrMoreApp.KEY_SIZE);
- settings.changed[FiveOrMoreApp.KEY_SIZE].connect (() => {
- size = settings.get_int (FiveOrMoreApp.KEY_SIZE);
- restart ();
- });
-
+ Object (size: size);
init_game ();
}
@@ -271,8 +262,9 @@ private class Game : Object
return Source.CONTINUE;
}
- internal void restart ()
+ internal void new_game (int _size)
{
+ size = _size;
init_game ();
}
}
diff --git a/src/window.vala b/src/window.vala
index 53bd882..f2ef94b 100644
--- a/src/window.vala
+++ b/src/window.vala
@@ -77,9 +77,14 @@ private class GameWindow : ApplicationWindow
BoardSize board_size = (BoardSize) settings.get_int (FiveOrMoreApp.KEY_SIZE);
((SimpleAction) board_size_action).set_state (new Variant.string (board_size.to_string ()));
- game = new Game (settings);
+ game = new Game ((int) board_size);
theme = new ThemeRenderer (settings);
+ settings.changed[FiveOrMoreApp.KEY_SIZE].connect (() => {
+ int size = settings.get_int (FiveOrMoreApp.KEY_SIZE);
+ game.new_game (size);
+ });
+
set_default_size (settings.get_int ("window-width"), settings.get_int ("window-height"));
if (settings.get_boolean ("window-is-maximized"))
maximize ();
@@ -214,7 +219,8 @@ private class GameWindow : ApplicationWindow
private inline void new_game (/* SimpleAction action, Variant? parameter */)
{
- game.restart ();
+ int size = settings.get_int (FiveOrMoreApp.KEY_SIZE);
+ game.new_game (size);
}
private inline void show_scores (/* SimpleAction action, Variant? parameter */)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]