[gnome-nibbles/arnaudb/modernize-code: 11/58] Never share settings with game.
- From: Arnaud B. <arnaudb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-nibbles/arnaudb/modernize-code: 11/58] Never share settings with game.
- Date: Wed, 10 Jun 2020 17:13:51 +0000 (UTC)
commit 678b374f9ba7c080b8eb9fb962349e04f8c84fe6
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Tue May 26 20:16:53 2020 +0200
Never share settings with game.
src/gnome-nibbles.vala | 14 +++++++++++---
src/nibbles-game.vala | 32 ++++++++------------------------
2 files changed, 19 insertions(+), 27 deletions(-)
---
diff --git a/src/gnome-nibbles.vala b/src/gnome-nibbles.vala
index 2827e21..50adce4 100644
--- a/src/gnome-nibbles.vala
+++ b/src/gnome-nibbles.vala
@@ -221,8 +221,10 @@ private class Nibbles : Gtk.Application
add_window (window);
/* Create game */
- game = new NibblesGame ();
- game.load_properties (settings);
+ game = new NibblesGame (settings.get_int ("tile-size"),
+ settings.get_int ("start-level"),
+ settings.get_int ("speed"),
+ settings.get_boolean ("fakes"));
game.log_score.connect (log_score_cb);
game.level_completed.connect (level_completed_cb);
game.notify["is-paused"].connect (() => {
@@ -281,10 +283,16 @@ private class Nibbles : Gtk.Application
protected override void shutdown ()
{
settings.delay ();
+ // window state
settings.set_int ("window-width", window_width);
settings.set_int ("window-height", window_height);
settings.set_boolean ("window-is-maximized", is_maximized);
- game.save_properties (settings);
+
+ // game properties
+ settings.set_int ("tile-size", game.tile_size);
+ settings.set_int ("start-level", game.start_level);
+ settings.set_int ("speed", game.speed);
+ settings.set_boolean ("fakes", game.fakes);
settings.apply ();
base.shutdown ();
diff --git a/src/nibbles-game.vala b/src/nibbles-game.vala
index 285ebf0..8b27b76 100644
--- a/src/nibbles-game.vala
+++ b/src/nibbles-game.vala
@@ -49,12 +49,12 @@ private class NibblesGame : Object
internal const int MAX_LEVEL = 26;
- internal int start_level { internal get; private set; }
- internal int current_level { internal get; private set; }
- internal int speed { internal get; internal set; }
+ public int start_level { internal get; protected construct; }
+ public int current_level { internal get; protected construct set; }
+ public int speed { internal get; internal construct set; }
/* Board data */
- internal int tile_size { internal get; internal set; }
+ public int tile_size { internal get; internal construct set; }
internal int[,] board;
/* Worms data */
@@ -75,7 +75,7 @@ private class NibblesGame : Object
private uint main_id = 0;
private uint add_bonus_id = 0;
- internal bool fakes { internal get; internal set; }
+ public bool fakes { internal get; internal construct set; }
internal signal void worm_moved (Worm worm);
internal signal void bonus_applied (Bonus bonus, Worm worm);
@@ -83,8 +83,10 @@ private class NibblesGame : Object
internal signal void animate_end_game ();
internal signal void level_completed ();
- internal NibblesGame ()
+ internal NibblesGame (int tile_size, int start_level, int speed, bool fakes)
{
+ Object (tile_size: tile_size, start_level: start_level, current_level: start_level, speed: speed,
fakes: fakes);
+
boni = new Boni (numworms);
warp_manager = new WarpManager ();
board = new int[WIDTH, HEIGHT];
@@ -534,24 +536,6 @@ private class NibblesGame : Object
* * Saving / Loading properties
\*/
- internal void load_properties (Settings settings)
- {
- tile_size = settings.get_int ("tile-size");
- start_level = settings.get_int ("start-level");
- speed = settings.get_int ("speed");
- fakes = settings.get_boolean ("fakes");
- current_level = start_level;
- }
-
- internal void save_properties (Settings settings)
- {
- // settings is already in delay mode, and apply is managed
- settings.set_int ("tile-size", tile_size);
- settings.set_int ("start-level", start_level);
- settings.set_int ("speed", speed);
- settings.set_boolean ("fakes", fakes);
- }
-
internal void load_worm_properties (Gee.ArrayList<Settings> worm_settings)
{
worm_props.clear ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]