[gnome-nibbles/wip/vala: 6/16] Remove Properties class. Move it's properties to NibblesGame
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-nibbles/wip/vala: 6/16] Remove Properties class. Move it's properties to NibblesGame
- Date: Sat, 27 Jun 2015 17:03:09 +0000 (UTC)
commit 9af98041be4f66e0f81f8122f3fe96d8b6c03b50
Author: Iulian Radu <iulian radu67 gmail com>
Date: Tue May 26 00:16:17 2015 +0300
Remove Properties class. Move it's properties to NibblesGame
configure.ac | 4 +-
data/org.gnome.nibbles.gschema.xml | 6 ++-
data/pix/Makefile.am | 6 +--
src/Makefile.am | 4 +-
src/config.vapi | 2 +-
src/games-gridframe.c | 2 -
src/gnome-nibbles.vala | 18 +++-----
src/nibbles-game.vala | 24 +++++++++-
src/nibbles-view.vala | 84 +++++++++++++-----------------------
src/properties.vala | 27 -----------
10 files changed, 68 insertions(+), 109 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 198462e..0b1226f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -46,7 +46,7 @@ dnl ###########################################################################
dnl GResources
dnl ###########################################################################
-AC_PATH_PROG(GLIB_COMPILE_RESOURCES, glib-compile-resources)
+AC_PATH_PROG([GLIB_COMPILE_RESOURCES], [glib-compile-resources])
dnl ###########################################################################
dnl Files to generate
@@ -55,6 +55,8 @@ dnl ###########################################################################
AC_CONFIG_FILES([
Makefile
data/Makefile
+data/levels/Makefile
+data/pix/Makefile
src/Makefile
src/gnome-nibbles.gresource.xml
])
diff --git a/data/org.gnome.nibbles.gschema.xml b/data/org.gnome.nibbles.gschema.xml
index 3a7e893..406dc85 100644
--- a/data/org.gnome.nibbles.gschema.xml
+++ b/data/org.gnome.nibbles.gschema.xml
@@ -13,17 +13,19 @@
<key name="window-is-maximized" type="b">
<default>false</default>
<summary>true if the window is maximized</summary>
- <summary>true if the window is maximized.</summary>
+ <description>true if the window is maximized.</description>
</key>
<key name="tile-size" type="i">
<default>7</default>
+ <range min="7"/>
<summary>Size of game tiles</summary>
<description>Size of game tiles.</description>
</key>
<key name="start-level" type="i">
<default>1</default>
+ <range min="1" max="26"/>
<summary>Game level to start on</summary>
- <summary>Game level to start on.</summary>
+ <description>Game level to start on.</description>
</key>
</schema>
</schemalist>
diff --git a/data/pix/Makefile.am b/data/pix/Makefile.am
index 53e5309..3e518b2 100644
--- a/data/pix/Makefile.am
+++ b/data/pix/Makefile.am
@@ -1,4 +1,4 @@
-pixmapdir = $(datadir)/gnome-nibbles/pixmaps
+pixmapdir = $(pkgdatadir)/gnome-nibbles/pixmaps
BONUS_PIX = \
bonus1.svg \
@@ -32,8 +32,6 @@ SMALL_PIX = \
wall-tee-right.svg \
wall-tee-up.svg
-pixmap_DATA = ${BONUS_PIX} ${SMALL_PIX}
-
-EXTRA_DIST = $(pixmap_DATA)
+dist_pixmap_DATA = ${BONUS_PIX} ${SMALL_PIX}
-include $(top_srcdir)/git.mk
diff --git a/src/Makefile.am b/src/Makefile.am
index 777c055..78ed01d 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -7,17 +7,15 @@ gnome_nibbles_SOURCES = \
gnome-nibbles.vala \
nibbles-view.vala \
nibbles-game.vala \
- properties.vala \
games-gridframe.h \
games-gridframe.c \
$(BUILT_SOURCES)
gnome_nibbles_CFLAGS = -w `pkg-config --cflags glib-2.0` `pkg-config --cflags gtk+-3.0` `pkg-config --libs
glib-2.0` `pkg-config --libs gtk+-3.0` `pkg-config --cflags clutter-1.0` `pkg-config --cflags
clutter-gtk-1.0` `pkg-config --libs clutter-1.0` `pkg-config --libs clutter-gtk-1.0`
-
gnome_nibbles_CPPFLAGS = \
-DVERSION=\"$(VERSION)\" \
- -DDATADIR=\"$(datadir)/gnome-nibbles\" \
+ -DPKGDATADIR=\"$(datadir)/gnome-nibbles\" \
-DGETTEXT_PACKAGE=\"$(GETTEXT_PACKAGE)\" \
$(GNOME_NIBBLES_CFLAGS)
diff --git a/src/config.vapi b/src/config.vapi
index e30421d..aa09de5 100644
--- a/src/config.vapi
+++ b/src/config.vapi
@@ -1,3 +1,3 @@
-public const string DATADIR;
+public const string PKGDATADIR;
public const string GETTEXT_PACKAGE;
public const string VERSION;
diff --git a/src/games-gridframe.c b/src/games-gridframe.c
index 56fe00a..4e133ce 100644
--- a/src/games-gridframe.c
+++ b/src/games-gridframe.c
@@ -22,8 +22,6 @@
/* A lot of this was written by following the sorce for GtkFrame and
* GtkAspectFrame. */
-// #include <config.h>
-
#include <gtk/gtk.h>
#include <glib/gi18n.h>
diff --git a/src/gnome-nibbles.vala b/src/gnome-nibbles.vala
index c5d5644..5ef82f2 100644
--- a/src/gnome-nibbles.vala
+++ b/src/gnome-nibbles.vala
@@ -86,7 +86,7 @@ public class Nibbles : Gtk.Application
settings.set_int ("window-width", window_width);
settings.set_int ("window-height", window_height);
settings.set_boolean ("window-is-maximized", is_maximized);
- game.properties.update_settings (settings);
+ game.save_properties (settings);
base.shutdown ();
}
@@ -128,14 +128,14 @@ public class Nibbles : Gtk.Application
ts_y--;
tile_size = int.min (ts_x, ts_y);
- if (game.properties.tile_size != tile_size)
+ if (game.tile_size != tile_size)
{
view.stage.set_size (tile_size * game.width, tile_size * game.height);
view.board_rescale (tile_size);
- game.properties.tile_size = tile_size;
+ game.tile_size = tile_size;
}
return false;
@@ -163,8 +163,7 @@ public class Nibbles : Gtk.Application
SignalHandler.disconnect_matched (game, SignalMatchType.DATA, 0, 0, null, null, this);
}
- game = new NibblesGame ();
- game.properties.update_properties (settings);
+ game = new NibblesGame (settings);
view = new NibblesView (game);
view.configure_event.connect (configure_event_cb);
@@ -175,13 +174,8 @@ public class Nibbles : Gtk.Application
frame.add (view);
frame.show_all ();
- /* TODO Fix problem and remove this call
- * For some reason tile_size gets set to 0 after calling
- * frame.add (view). start_level stays the same
- */
- game.properties.update_properties (settings);
-
- game.current_level = game.properties.start_level;
+ game.load_properties (settings);
+ game.current_level = game.start_level;
view.new_level (game.current_level);
show_game_view ();
}
diff --git a/src/nibbles-game.vala b/src/nibbles-game.vala
index a180a44..31e0c0f 100644
--- a/src/nibbles-game.vala
+++ b/src/nibbles-game.vala
@@ -1,6 +1,12 @@
public class NibblesGame : Object
{
- public Properties properties;
+ public int tile_size;
+ public int start_level;
+
+ public int DEFAULTGAMEDELAY = 35;
+ public int GAMEDELAY = 35;
+ public int NETDELAY = 2;
+ public int BONUSDELAY = 100;
public int width = 92;
public int height = 66;
@@ -11,9 +17,21 @@ public class NibblesGame : Object
public int current_level;
public int[,] walls;
- public NibblesGame ()
+ public NibblesGame (Settings settings)
{
- properties = new Properties ();
walls = new int[width, height];
+ load_properties (settings);
+ }
+
+ public void load_properties (Settings settings)
+ {
+ tile_size = settings.get_int ("tile-size");
+ start_level = settings.get_int ("start-level");
+ }
+
+ public void save_properties (Settings settings)
+ {
+ tile_size = settings.get_int ("tile-size");
+ start_level = settings.get_int ("start-level");
}
}
diff --git a/src/nibbles-view.vala b/src/nibbles-view.vala
index 6455853..841e5da 100644
--- a/src/nibbles-view.vala
+++ b/src/nibbles-view.vala
@@ -3,7 +3,7 @@ public class NibblesView : GtkClutter.Embed
/* Game being played */
public NibblesGame game { get; private set; }
- public Clutter.Actor surface;
+ public GtkClutter.Texture surface;
public Clutter.Stage stage;
private Clutter.Actor level;
@@ -22,7 +22,7 @@ public class NibblesView : GtkClutter.Embed
{
this.game = game;
- stage = get_stage () as Clutter.Stage;
+ stage = (Clutter.Stage) get_stage ();
Clutter.Color stage_color = { 0x00, 0x00, 0x00, 0xff };
stage.set_background_color (stage_color);
@@ -30,9 +30,9 @@ public class NibblesView : GtkClutter.Embed
try
{
- var pixbuf = new Gdk.Pixbuf.from_file (Path.build_filename (DATADIR, "pixmaps",
"wall-small-empty.svg"));
+ var pixbuf = new Gdk.Pixbuf.from_file (Path.build_filename (PKGDATADIR, "pixmaps",
"wall-small-empty.svg"));
surface = new GtkClutter.Texture ();
- ((GtkClutter.Texture) surface).set_from_pixbuf (pixbuf);
+ surface.set_from_pixbuf (pixbuf);
var val = Value (typeof (bool));
val.set_boolean (true);
@@ -46,11 +46,11 @@ public class NibblesView : GtkClutter.Embed
}
catch (Clutter.TextureError e)
{
- warning ("Failed to load textures: %s", e.message);
+ error ("Failed to load textures: %s", e.message);
}
- catch (GLib.Error e)
+ catch (Error e)
{
- warning ("Failed to load textures: %s", e.message);
+ error ("Failed to load textures: %s", e.message);
}
load_pixmap ();
@@ -64,38 +64,22 @@ public class NibblesView : GtkClutter.Embed
string filename;
string tmpboard;
+ warning("%d\n", game.tile_size);
level_name = "level%03d.gnl".printf (level);
- filename = Path.build_filename (DATADIR, "levels", level_name, null);
+ filename = Path.build_filename (PKGDATADIR, "levels", level_name, null);
FileStream file;
if ((file = FileStream.open (filename, "r")) == null) {
- string message =
- (_("Nibbles couldn't load level file:\n%s\n\n" +
- "Please check your Nibbles installation")).printf (filename);
- var dialog = new Gtk.MessageDialog (null,
- Gtk.DialogFlags.MODAL,
- Gtk.MessageType.ERROR,
- Gtk.ButtonsType.OK,
- message);
- dialog.run ();
- dialog.destroy ();
+ /* Fatal console error when the game's data files are missing. */
+ error (_("Nibbles couldn't find pixmap file: %s"), filename);
}
for (int i = 0; i < game.height; i++)
{
if ((tmpboard = file.read_line ()) == null)
{
- string message =
- (_("Level file appears to be damaged:\n%s\n\n" +
- "Please check your Nibbles installation")).printf (filename);
- var dialog = new Gtk.MessageDialog (null,
- Gtk.DialogFlags.MODAL,
- Gtk.MessageType.ERROR,
- Gtk.ButtonsType.OK,
- message);
- dialog.run ();
- dialog.destroy ();
- break;
+ /* Fatal console error when the game's level files are damaged. */
+ error (_("Level file appears to be damaged: %s"), filename);
}
for (int j = 0; j < game.width; j++)
@@ -126,21 +110,12 @@ public class NibblesView : GtkClutter.Embed
private Gdk.Pixbuf load_pixmap_file (string pixmap, int xsize, int ysize)
{
- var filename = Path.build_filename (DATADIR, "pixmaps", pixmap, null);
+ var filename = Path.build_filename (PKGDATADIR, "pixmaps", pixmap, null);
if (filename == null)
{
- string message =
- (_("Nibbles couldn't find pixmap file:\n%s\n\n" +
- "Please check your Nibbles installation")).printf (pixmap);
- var dialog = new Gtk.MessageDialog (null,
- Gtk.DialogFlags.MODAL,
- Gtk.MessageType.ERROR,
- Gtk.ButtonsType.OK,
- message);
- dialog.run ();
- dialog.destroy ();
- Posix.exit (Posix.EXIT_FAILURE);
+ /* Fatal console error when the game's data files are missing. */
+ error (_("Nibbles couldn't find pixmap file: %s"), filename);
}
Gdk.Pixbuf image = null;
@@ -192,7 +167,7 @@ public class NibblesView : GtkClutter.Embed
"snake-grey.svg"
};
- int tile_size = game.properties.tile_size;
+ int tile_size = game.tile_size;
for (int i = 0; i < 8; i++) {
boni_pixmaps[i] = load_pixmap_file (bonus_files[i],
2 * tile_size, 2 * tile_size);
@@ -216,15 +191,16 @@ public class NibblesView : GtkClutter.Embed
bool is_wall = true;
level = new Clutter.Actor ();
- if (level != null)
- {
- level.remove_all_children ();
- stage.remove_child (level);
- }
+ // if (level != null)
+ // {
+ // warning("here");
+ // level.remove_all_children ();
+ // stage.remove_child (level);
+ // }
/* Load wall_pixmaps onto the surface */
for (int i = 0; i < game.height; i++)
{
- y_pos = i * game.properties.tile_size;
+ y_pos = i * game.tile_size;
for (int j = 0; j < game.width; j++)
{
is_wall = true;
@@ -291,10 +267,10 @@ public class NibblesView : GtkClutter.Embed
if (is_wall)
{
- x_pos = j * game.properties.tile_size;
+ x_pos = j * game.tile_size;
- ((Clutter.Actor) tmp).set_size (game.properties.tile_size,
- game.properties.tile_size);
+ ((Clutter.Actor) tmp).set_size (game.tile_size,
+ game.tile_size);
((Clutter.Actor) tmp).set_position (x_pos, y_pos);
((Clutter.Actor) tmp).show ();
level.add_child ((Clutter.Actor) tmp);
@@ -309,7 +285,7 @@ public class NibblesView : GtkClutter.Embed
level.save_easing_state ();
level.set_easing_mode (Clutter.AnimationMode.EASE_OUT_BOUNCE);
- level.set_easing_duration (game.properties.GAMEDELAY * game.properties.GAMEDELAY);
+ level.set_easing_duration (game.GAMEDELAY * game.GAMEDELAY);
level.set_scale (1.0, 1.0);
level.set_pivot_point (0.5f, 0.5f);
level.set_opacity (0xff);
@@ -339,8 +315,8 @@ public class NibblesView : GtkClutter.Embed
{
tmp = level.get_child_at_index (i);
((Clutter.Actor) tmp).get_position (out x_pos, out y_pos);
- ((Clutter.Actor) tmp).set_position ((x_pos / game.properties.tile_size) * tile_size,
- (y_pos / game.properties.tile_size) * tile_size);
+ ((Clutter.Actor) tmp).set_position ((x_pos / game.tile_size) * tile_size,
+ (y_pos / game.tile_size) * tile_size);
((Clutter.Actor) tmp).set_size (tile_size, tile_size);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]