gnome-games r8546 - in trunk: glines gnibbles gnobots2 gnometris gnomine gnotravex gnotski gtali libgames-support mahjongg same-gnome



Author: chpe
Date: Sat Jan 10 15:35:38 2009
New Revision: 8546
URL: http://svn.gnome.org/viewvc/gnome-games?rev=8546&view=rev

Log:
Refactor games_scores_new() to have arguments instead of taking just one
big struct with the arguments. Adapt callers accordingly.

Modified:
   trunk/glines/glines.c
   trunk/gnibbles/main.c
   trunk/gnobots2/gnobots.c
   trunk/gnometris/highscores.cpp
   trunk/gnomine/gnomine.c
   trunk/gnotravex/gnotravex.c
   trunk/gnotski/gnotski.c
   trunk/gtali/gyahtzee.c
   trunk/libgames-support/games-scores.c
   trunk/libgames-support/games-scores.h
   trunk/mahjongg/mahjongg.c
   trunk/same-gnome/same-gnome.c

Modified: trunk/glines/glines.c
==============================================================================
--- trunk/glines/glines.c	(original)
+++ trunk/glines/glines.c	Sat Jan 10 15:35:38 2009
@@ -87,15 +87,7 @@
 static const GamesScoresCategory scorecats[] = {
   { "Small",  N_("Small") },
   { "Medium", N_("glines|Medium") },
-  { "Large",  N_("Large") },
-  GAMES_SCORES_LAST_CATEGORY
-};
-
-static const GamesScoresDescription scoredesc = {
-  scorecats,
-  "Small",
-  "glines",
-  GAMES_SCORES_STYLE_PLAIN_DESCENDING
+  { "Large",  N_("Large") }
 };
 
 static GamesScores *highscores;
@@ -1830,7 +1822,11 @@
 
   games_conf_initialise ("GLines");
 
-  highscores = games_scores_new (&scoredesc);
+  highscores = games_scores_new ("glines",
+                                 scorecats, G_N_ELEMENTS (scorecats),
+                                 NULL, NULL,
+                                 0 /* default category */,
+                                 GAMES_SCORES_STYLE_PLAIN_DESCENDING);
 
   init_config ();
 

Modified: trunk/gnibbles/main.c
==============================================================================
--- trunk/gnibbles/main.c	(original)
+++ trunk/gnibbles/main.c	Sat Jan 10 15:35:38 2009
@@ -63,20 +63,15 @@
 GtkWidget *notebook;
 GtkWidget *chat = NULL;
 
-static const GamesScoresCategory scorecats[] = { {"4.0", N_("Beginner")},
+static const GamesScoresCategory scorecats[] = {
+{"4.0", N_("Beginner")},
 {"3.0", N_("Slow")},
 {"2.0", N_("gnibbles|Medium")},
 {"1.0", N_("Fast")},
 {"4.1", N_("Beginner with Fakes")},
 {"3.1", N_("Slow with Fakes")},
 {"2.1", N_("Medium with Fakes")},
-{"1.1", N_("Fast with Fakes")},
-GAMES_SCORES_LAST_CATEGORY
-};
-static const GamesScoresDescription scoredesc = { scorecats,
-  "4.0",
-  "gnibbles",
-  GAMES_SCORES_STYLE_PLAIN_DESCENDING
+{"1.1", N_("Fast with Fakes")}
 };
 
 GamesScores *highscores;
@@ -1071,7 +1066,11 @@
   gtk_window_set_default_icon_name ("gnome-gnibbles");
   srand (time (NULL));
 
-  highscores = games_scores_new (&scoredesc);
+  highscores = games_scores_new ("gnibbles",
+                                 scorecats, G_N_ELEMENTS (scorecats),
+                                 NULL, NULL,
+                                 0 /* default category */,
+                                 GAMES_SCORES_STYLE_PLAIN_DESCENDING);
 
   games_conf_initialise ("Gnibbles");
 

Modified: trunk/gnobots2/gnobots.c
==============================================================================
--- trunk/gnobots2/gnobots.c	(original)
+++ trunk/gnobots2/gnobots.c	Sat Jan 10 15:35:38 2009
@@ -108,14 +108,7 @@
   {"robots2_easy-super-safe", N_("Robots2 easy with super-safe moves")},
   {"robots_with_safe_teleport", N_("Robots with safe teleport")},
   {"robots_with_safe_teleport-safe", N_("Robots with safe teleport with safe moves")},
-  {"robots_with_safe_teleport-super-safe", N_("Robots with safe teleport with super-safe moves")},
-  GAMES_SCORES_LAST_CATEGORY
-};
-
-static const GamesScoresDescription scoredesc = { scorecats,
-  "classic_robots",
-  "gnobots2",
-  GAMES_SCORES_STYLE_PLAIN_DESCENDING
+  {"robots_with_safe_teleport-super-safe", N_("Robots with safe teleport with super-safe moves")}
 };
 
 /**********************************************************************/
@@ -245,7 +238,11 @@
 
   g_set_application_name (_("Robots"));
 
-  highscores = games_scores_new (&scoredesc);
+  highscores = games_scores_new ("gnobots2",
+                                 scorecats, G_N_ELEMENTS (scorecats),
+                                 NULL, NULL,
+                                 0 /* default category */,
+                                 GAMES_SCORES_STYLE_PLAIN_DESCENDING);
 
   games_conf_initialise ("Gnobots2");
 

Modified: trunk/gnometris/highscores.cpp
==============================================================================
--- trunk/gnometris/highscores.cpp	(original)
+++ trunk/gnometris/highscores.cpp	Sat Jan 10 15:35:38 2009
@@ -26,14 +26,13 @@
 #include <games-scores-dialog.h>
 #include "highscores.h"
 
-static const GamesScoresDescription scoredesc = {NULL, NULL,
-						 "gnometris",
-						 GAMES_SCORES_STYLE_PLAIN_DESCENDING};
-
-
 HighScores::HighScores ()
 {
-	highscores = games_scores_new (&scoredesc);
+	highscores = games_scores_new ("gnometris",
+                                       NULL, 0,
+                                       NULL, NULL,
+                                       0,
+                                       GAMES_SCORES_STYLE_PLAIN_DESCENDING);
 
 	dialog = NULL;
 }

Modified: trunk/gnomine/gnomine.c
==============================================================================
--- trunk/gnomine/gnomine.c	(original)
+++ trunk/gnomine/gnomine.c	Sat Jan 10 15:35:38 2009
@@ -38,6 +38,7 @@
 #include <libgames-support/games-runtime.h>
 #include <libgames-support/games-scores.c>
 #include <libgames-support/games-scores-dialog.h>
+#include <libgames-support/games-sound.h>
 #include <libgames-support/games-stock.h>
 
 #ifdef WITH_SMCLIENT
@@ -95,17 +96,11 @@
 
 /*GstElement *sound_player;*/
 
-static const GamesScoresCategory scorecats[] = { {"Small", N_("Small")},
+static const GamesScoresCategory scorecats[] = {
+{"Small", N_("Small")},
 {"Medium", N_("gnomine|Medium")},
 {"Large", N_("Large")},
-{"Custom", N_("Custom")},
-GAMES_SCORES_LAST_CATEGORY
-};
-
-static const GamesScoresDescription scoredesc = { scorecats,
-  "Small",
-  APP_NAME,
-  GAMES_SCORES_STYLE_TIME_ASCENDING
+{"Custom", N_("Custom")}
 };
 
 GamesScores *highscores;
@@ -1005,6 +1000,7 @@
 #ifdef WITH_SMCLIENT
   g_option_context_add_group (context, egg_sm_client_get_option_group ());
 #endif /* WITH_SMCLIENT */
+  games_sound_add_option_group (context);
   g_option_context_add_main_entries (context, options, GETTEXT_PACKAGE);
 
   retval = g_option_context_parse (context, &argc, &argv, &error);
@@ -1019,9 +1015,11 @@
     
   games_conf_initialise (APP_NAME);
 
-  highscores = games_scores_new (&scoredesc);
-
-  /* sound_init (&argc, &argv); */
+  highscores = games_scores_new (APP_NAME,
+                                 scorecats, G_N_ELEMENTS (scorecats),
+                                 NULL, NULL,
+                                 0 /* default category */,
+                                 GAMES_SCORES_STYLE_TIME_ASCENDING);
 
   g_signal_connect (games_conf_get_default (), "value-changed",
                     G_CALLBACK (conf_value_changed_cb), NULL);

Modified: trunk/gnotravex/gnotravex.c
==============================================================================
--- trunk/gnotravex/gnotravex.c	(original)
+++ trunk/gnotravex/gnotravex.c	Sat Jan 10 15:35:38 2009
@@ -62,10 +62,10 @@
 #define DEFAULT_WIDTH 320
 #define DEFAULT_HEIGHT 240
 
-/* i18n in-game numbers, replaceable with single-character local ideograms. */
-static const char *translatable_number[10] =
-  { N_("0"), N_("1"), N_("2"), N_("3"), N_("4"), N_("5"), N_("6"), N_("7"),
-N_("8"), N_("9") };
+static const char *translatable_number[10] = {
+  /* Translators: in-game numbers, replaceable with single-character local ideograms */
+  N_("0"), N_("1"), N_("2"), N_("3"), N_("4"), N_("5"), N_("6"), N_("7"), N_("8"), N_("9")
+};
 
 static GtkWidget *window;
 static GtkWidget *statusbar;
@@ -73,17 +73,12 @@
 static GtkWidget *timer;
 static GdkGC *bg_gc;
 
-static const GamesScoresCategory scorecats[] = { {"2x2", N_("2\303\2272")},
+static const GamesScoresCategory scorecats[] = {
+{"2x2", N_("2\303\2272")},
 {"3x3", N_("3\303\2273")},
 {"4x4", N_("4\303\2274")},
 {"5x5", N_("5\303\2275")},
-{"6x6", N_("6\303\2276")},
-GAMES_SCORES_LAST_CATEGORY
-};
-static const GamesScoresDescription scoredesc = { scorecats,
-  "3x3",
-  "gnotravex",
-  GAMES_SCORES_STYLE_TIME_ASCENDING
+{"6x6", N_("6\303\2276")}
 };
 
 static GamesScores *highscores;
@@ -444,7 +439,11 @@
 
   games_conf_initialise (APPNAME);
 
-  highscores = games_scores_new (&scoredesc);
+  highscores = games_scores_new ("gnotravex",
+                                 scorecats, G_N_ELEMENTS (scorecats),
+                                 NULL, NULL,
+                                 1 /* default category */,
+                                 GAMES_SCORES_STYLE_TIME_ASCENDING);
 
   games_stock_init ();
 

Modified: trunk/gnotski/gnotski.c
==============================================================================
--- trunk/gnotski/gnotski.c	(original)
+++ trunk/gnotski/gnotski.c	Sat Jan 10 15:35:38 2009
@@ -99,7 +99,8 @@
 guint redraw_all_idle_id = 0;
 guint configure_idle_id = 0;
 
-static const GamesScoresCategory scorecats[] = { {"1", N_("Only 18 steps")},
+static const GamesScoresCategory scorecats[] = {
+{"1", N_("Only 18 steps")},
 {"2", N_("Daisy")},
 {"3", N_("Violet")},
 {"4", N_("Poppy")},
@@ -126,14 +127,7 @@
 {"25", N_("Baltic Sea")},
 {"26", N_("American Pie")},
 {"27", N_("Traffic Jam")},
-{"28", N_("Sunshine")},
-GAMES_SCORES_LAST_CATEGORY
-};
-
-static const GamesScoresDescription scoredesc = { scorecats,
-  "1",
-  "gnotski",
-  GAMES_SCORES_STYLE_PLAIN_ASCENDING
+{"28", N_("Sunshine")}
 };
 
 GamesScores *highscores;
@@ -530,7 +524,11 @@
                     G_CALLBACK (quit_cb), NULL);
 #endif /* WITH_SMCLIENT */
 
-  highscores = games_scores_new (&scoredesc);
+  highscores = games_scores_new ("gnotski",
+                                 scorecats, G_N_ELEMENTS (scorecats),
+                                 NULL, NULL,
+                                 0 /* default category */,
+                                 GAMES_SCORES_STYLE_PLAIN_ASCENDING);
 
   window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
   gtk_window_set_title (GTK_WINDOW (window), _(APPNAME_LONG));

Modified: trunk/gtali/gyahtzee.c
==============================================================================
--- trunk/gtali/gyahtzee.c	(original)
+++ trunk/gtali/gyahtzee.c	Sat Jan 10 15:35:38 2009
@@ -120,13 +120,8 @@
 };
 
 static const GamesScoresCategory category_array[] = {
-    {"Regular", "Regular"}, {"Colors", "Colors"}, GAMES_SCORES_LAST_CATEGORY };
-
-static const GamesScoresDescription scoredesc = { 
-  category_array,
-  "Regular",
-  "gtali",
-  GAMES_SCORES_STYLE_PLAIN_DESCENDING
+  {"Regular", "Regular"},
+  {"Colors", "Colors"}
 };
 
 GamesScores *highscores;
@@ -941,7 +936,11 @@
       exit(0);
   }
 
-  highscores = games_scores_new (&scoredesc);
+  highscores = games_scores_new ("gtali",
+                                 category_array, G_N_ELEMENTS (category_array),
+                                 NULL, NULL,
+                                 0 /* default category */,
+                                 GAMES_SCORES_STYLE_PLAIN_DESCENDING);
 
   gtk_window_set_default_icon_name ("gnome-tali");
 

Modified: trunk/libgames-support/games-scores.c
==============================================================================
--- trunk/libgames-support/games-scores.c	(original)
+++ trunk/libgames-support/games-scores.c	Sat Jan 10 15:35:38 2009
@@ -100,55 +100,68 @@
 G_DEFINE_TYPE (GamesScores, games_scores, G_TYPE_OBJECT);
 
 /** 
- * new:
- * @description: A GamesScoresDescription structure with the information
- *               about this games scoring system. 
- *
- * Create an object to handle a set of scores. Normally you will make one
- * global object. Creating and destroying these objects is inefficient. 
- * Using multipl objects referring to the same set of scores at the same
- * time should work but is unnecessary liable to be buggy.
+ * games_scores_new:
+ * @app_name: the (old) app name (for backward compatibility),
+ *   used as the basename of the category filenames
+ * @categories: the score categories, or %NULL to use an anonymous category
+ * @n_categories: the number of category entries in @categories
+ * @categories_context: the translation context to use for the category names,
+ *   or %NULL to use no translation context
+ * @categories_domain: the translation domain to use for the category names,
+ *   or %NULL to use the default domain
+ * @default_category: the key of the default category, or %NULL
+ * @style: the category style
+ * 
+ *
+ * Returns: a new #GamesScores object
  */
 GamesScores *
-games_scores_new (const GamesScoresDescription * description)
+games_scores_new (const char *app_name,
+                  const GamesScoresCategory *categories,
+                  int n_categories,
+                  const char *categories_context,
+                  const char *categories_domain,
+                  int default_category_index,
+                  GamesScoreStyle style)
 {
   GamesScores *self;
   GamesScoresPrivate *priv;
-  const GamesScoresCategory *cats;
 
   self = GAMES_SCORES (g_object_new (GAMES_TYPE_SCORES, NULL));
   priv = self->priv;
 
   /* FIXME: Input sanity checks. */
 
-  priv->categories =
-    g_hash_table_new_full (g_str_hash, g_str_equal,
-			   g_free,
-			   (GDestroyNotify) games_scores_category_free);
+  priv->categories = g_hash_table_new_full (g_str_hash, g_str_equal,
+                                            g_free,
+                                            (GDestroyNotify) games_scores_category_free);
 
   /* catsordered is a record of the ordering of the categories. 
    * Its data is shared with the hash table. */
   priv->catsordered = NULL;
 
-  if (description->categories) {
-    cats = description->categories;
-    while (cats->key) {
-      games_scores_add_category (self, cats->key, cats->name);
-      cats++;
+  if (n_categories > 0) {
+    int i;
+
+    g_return_val_if_fail (default_category_index >= 0 && default_category_index < n_categories, NULL);
+
+    for (i = 0; i < n_categories; ++i) {
+      const GamesScoresCategory *category = &categories[i];
+
+      games_scores_add_category (self, category->key, category->name);
     }
 
-    priv->defcat = g_strdup (description->deflt);
+    priv->defcat = g_strdup (categories[default_category_index].key);
     priv->currentcat = g_strdup (priv->defcat);
   } else {
     priv->currentcat = NULL;
     priv->defcat = NULL;
-    priv->catsordered = NULL;
   }
 
-  priv->basename = g_strdup (description->basename);
+  priv->basename = g_strdup (app_name);
   /* FIXME: Do some sanity checks on the default and the like. */
 
-  priv->style = description->style;
+  priv->style = style;
 
   /* Set up the anonymous category for use when no categories are specified. */
   priv->dummycat.key = "";

Modified: trunk/libgames-support/games-scores.h
==============================================================================
--- trunk/libgames-support/games-scores.h	(original)
+++ trunk/libgames-support/games-scores.h	Sat Jan 10 15:35:38 2009
@@ -45,15 +45,6 @@
 
 #define GAMES_SCORES_LAST_CATEGORY {NULL, NULL}
 
-/* All elements get copied so the creator stays the owner. */
-typedef struct {
-  const GamesScoresCategory *categories;	/* Array of categories, terminate
-						 * with GAMES_SCORES_LAST_CATEGORY. */
-  const gchar *deflt;			/* The key of the default category. */
-  const gchar *basename;		/* The base of the filename. The old appname. */
-  GamesScoreStyle style;
-} GamesScoresDescription;
-
 #define GAMES_TYPE_SCORES (games_scores_get_type())
 #define GAMES_SCORES(obj) G_TYPE_CHECK_INSTANCE_CAST((obj), games_scores_get_type(), GamesScores)
 #define GAMES_SCORES_CONST(obj)	G_TYPE_CHECK_INSTANCE_CAST((obj), games_scores_get_type(), GamesScores const)
@@ -77,7 +68,13 @@
 
 GType games_scores_get_type (void);
 
-GamesScores *games_scores_new (const GamesScoresDescription * description);
+GamesScores *games_scores_new (const char *app_name,
+                               const GamesScoresCategory *categories,
+                               int n_categories,
+                               const char *categories_context,
+                               const char *categories_domain,
+                               int default_category_index,
+                               GamesScoreStyle style);
 
 void games_scores_set_category (GamesScores * self, gchar * category);
 

Modified: trunk/mahjongg/mahjongg.c
==============================================================================
--- trunk/mahjongg/mahjongg.c	(original)
+++ trunk/mahjongg/mahjongg.c	Sat Jan 10 15:35:38 2009
@@ -104,12 +104,6 @@
 
 static GamesScores *highscores;
 
-static const GamesScoresDescription scoredesc = { NULL,
-  "Easy",
-  "mahjongg",
-  GAMES_SCORES_STYLE_TIME_ASCENDING
-};
-
 enum {
   GAME_RUNNING = 0,
   GAME_WAITING,
@@ -1358,10 +1352,14 @@
 {
   int i;
 
-  highscores = games_scores_new (&scoredesc);
+  highscores = games_scores_new ("mahjongg",
+                                 NULL, 0,
+                                 NULL, NULL,
+                                 0 /* default category; FIXMEchpe: was: "Easy" */,
+                                 GAMES_SCORES_STYLE_TIME_ASCENDING);
 
   for (i = 0; i < nmaps; i++) {
-    games_scores_add_category (highscores, maps[i].score_name, maps[i].name);
+    games_scores_add_category (highscores, maps[i].score_name, maps[i].name); // FIXMEchpe
   }
 }
 

Modified: trunk/same-gnome/same-gnome.c
==============================================================================
--- trunk/same-gnome/same-gnome.c	(original)
+++ trunk/same-gnome/same-gnome.c	Sat Jan 10 15:35:38 2009
@@ -50,16 +50,10 @@
 {45, 30, 4}
 };
 
-const GamesScoresCategory scorecats[] = { {"Small", N_("Small")},
-{"Medium", N_("same-gnome|Medium")},
-{"Large", N_("Large")},
-GAMES_SCORES_LAST_CATEGORY
-};
-
-static const GamesScoresDescription scoredesc = { scorecats,
-  "Small",
-  "same-gnome",
-  GAMES_SCORES_STYLE_PLAIN_DESCENDING
+const GamesScoresCategory scorecats[] = {
+  { "Small",  N_("Small") },
+  { "Medium", N_("same-gnome|Medium") },
+  { "Large",  N_("Large") }
 };
 
 GamesScores *highscores;
@@ -168,7 +162,11 @@
 
   games_stock_init ();
 
-  highscores = games_scores_new (&scoredesc);
+  highscores = games_scores_new ("same-gnome",
+                                 scorecats, G_N_ELEMENTS (scorecats),
+                                 NULL, NULL,
+                                 0 /* default category */,
+                                 GAMES_SCORES_STYLE_PLAIN_DESCENDING);
 
   initialise_options (requested_size, requested_theme);
 



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