[gnome-video-arcade] 2009-03-03 Matthew Barnes <mbarnes redhat com>



commit 9a8ec1092991d29ca1353943c0b473041a99167b
Author: Matthew Barnes <mbarnes redhat com>
Date:   Tue Mar 3 23:15:19 2009 -0500

    2009-03-03  Matthew Barnes  <mbarnes redhat com>
    
    	* docs/reference:
    	Update developer documentation.
    
    	* src/gva-columns.c:
    	Add "Player (Alt.)" and "Player (Sim.)" columns (if NPLAYERS_FILE
    	is defined), which shows only the number of alternating players or
    	simultaneous players a game supports (respectively).
    
    	* src/gva-db.c:
    	Add "input_players_alt" and "input_players_sim" columns (if
    	NPLAYERS_FILE is defined).
    
    	* src/gva-db.c (db_parser_start_element_input):
    	If NPLAYERS_FILE is defined, fetch player information from the
    	NPLAYERS_FILE for the "input_players_alt" and "input_players_sim"
    	columns.  Also override "input_players" with the maximum of the
    	"alt" and "sim" columns.  Surprisingly, the file seems to be more
    	accurate than MAME's own XML data.
    
    	* src/gva-game-store.c:
    	* src/gva-game-store.h:
    	Add GVA_GAME_STORE_COLUMN_INPUT_PLAYERS_ALT.
    	Add GVA_GAME_STORE_COLUMN_INPUT_PLAYERS_SIM.
    
    	* src/gva-nplayers.c (gva_nplayers_describe):
    	New function returns a human-readable description of the number of
    	players a game supports.  Description is used as the tooltip in all
    	"Players" columns, whether NPLAYERS_FILE is defined or not.
---
 ChangeLog                                      |   31 ++++
 config.h.in                                    |    3 +
 docs/reference/Makefile.am                     |    1 +
 docs/reference/gnome-video-arcade-docs.sgml    |    1 +
 docs/reference/gnome-video-arcade-sections.txt |    7 +
 docs/reference/tmpl/gva-game-store.sgml        |    2 +
 src/gva-columns.c                              |  110 +++++++++----
 src/gva-db.c                                   |   56 ++++++
 src/gva-game-store.c                           |    2 +
 src/gva-game-store.h                           |    6 +
 src/gva-nplayers.c                             |  212 +++++++++++++++++++++---
 src/gva-nplayers.h                             |    6 +
 12 files changed, 377 insertions(+), 60 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 1f2a803..e5c3569 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,34 @@
+2009-03-03  Matthew Barnes  <mbarnes redhat com>
+
+	* docs/reference:
+	Update developer documentation.
+
+	* src/gva-columns.c:
+	Add "Player (Alt.)" and "Player (Sim.)" columns (if NPLAYERS_FILE
+	is defined), which shows only the number of alternating players or
+	simultaneous players a game supports (respectively).
+
+	* src/gva-db.c:
+	Add "input_players_alt" and "input_players_sim" columns (if
+	NPLAYERS_FILE is defined).
+
+	* src/gva-db.c (db_parser_start_element_input):
+	If NPLAYERS_FILE is defined, fetch player information from the
+	NPLAYERS_FILE for the "input_players_alt" and "input_players_sim"
+	columns.  Also override "input_players" with the maximum of the
+	"alt" and "sim" columns.  Surprisingly, the file seems to be more
+	accurate than MAME's own XML data.
+
+	* src/gva-game-store.c:
+	* src/gva-game-store.h:
+	Add GVA_GAME_STORE_COLUMN_INPUT_PLAYERS_ALT.
+	Add GVA_GAME_STORE_COLUMN_INPUT_PLAYERS_SIM.
+
+	* src/gva-nplayers.c (gva_nplayers_describe):
+	New function returns a human-readable description of the number of
+	players a game supports.  Description is used as the tooltip in all
+	"Players" columns, whether NPLAYERS_FILE is defined or not.
+
 2009-03-02  Matthew Barnes  <mbarnes redhat com>
 
 	* README:
diff --git a/config.h.in b/config.h.in
index 79629f8..cf909a3 100644
--- a/config.h.in
+++ b/config.h.in
@@ -63,6 +63,9 @@
 /* Location of the MAME program */
 #undef MAME_PROGRAM
 
+/* Location of the number of players file */
+#undef NPLAYERS_FILE
+
 /* Name of package */
 #undef PACKAGE
 
diff --git a/docs/reference/Makefile.am b/docs/reference/Makefile.am
index 835b26b..4146791 100644
--- a/docs/reference/Makefile.am
+++ b/docs/reference/Makefile.am
@@ -99,6 +99,7 @@ GTKDOC_LIBS=							\
 	$(top_builddir)/src/gva-mame-common.o			\
 	$(top_builddir)/src/gva-mame-process.o			\
 	$(top_builddir)/src/gva-mute-button.o			\
+	$(top_builddir)/src/gva-nplayers.o			\
 	$(top_builddir)/src/gva-play-back.o			\
 	$(top_builddir)/src/gva-preferences.o			\
 	$(top_builddir)/src/gva-process.o			\
diff --git a/docs/reference/gnome-video-arcade-docs.sgml b/docs/reference/gnome-video-arcade-docs.sgml
index e06e2bf..8d3c33d 100644
--- a/docs/reference/gnome-video-arcade-docs.sgml
+++ b/docs/reference/gnome-video-arcade-docs.sgml
@@ -28,6 +28,7 @@
     <xi:include href="xml/gva-history.xml"/>
     <xi:include href="xml/gva-mame-common.xml"/>
     <xi:include href="xml/gva-mame.xml"/>
+    <xi:include href="xml/gva-nplayers.xml"/>
     <xi:include href="xml/gva-time.xml"/>
     <xi:include href="xml/gva-util.xml"/>
     <xi:include href="xml/gva-wnck.xml"/>
diff --git a/docs/reference/gnome-video-arcade-sections.txt b/docs/reference/gnome-video-arcade-sections.txt
index 2fa0099..66cad10 100644
--- a/docs/reference/gnome-video-arcade-sections.txt
+++ b/docs/reference/gnome-video-arcade-sections.txt
@@ -252,6 +252,13 @@ gva_mute_button_get_type
 </SECTION>
 
 <SECTION>
+<FILE>gva-nplayers</FILE>
+gva_nplayers_init
+gva_nplayers_lookup
+gva_nplayers_describe
+</SECTION>
+
+<SECTION>
 <FILE>gva-play-back</FILE>
 gva_play_back_init
 gva_play_back_show
diff --git a/docs/reference/tmpl/gva-game-store.sgml b/docs/reference/tmpl/gva-game-store.sgml
index e26b113..9a7a678 100644
--- a/docs/reference/tmpl/gva-game-store.sgml
+++ b/docs/reference/tmpl/gva-game-store.sgml
@@ -47,6 +47,8 @@
 @GVA_GAME_STORE_COLUMN_INPUT_SERVICE: 
 @GVA_GAME_STORE_COLUMN_INPUT_TILT: 
 @GVA_GAME_STORE_COLUMN_INPUT_PLAYERS: 
+ GVA_GAME_STORE_COLUMN_INPUT_PLAYERS_ALT: 
+ GVA_GAME_STORE_COLUMN_INPUT_PLAYERS_SIM: 
 @GVA_GAME_STORE_COLUMN_INPUT_BUTTONS: 
 @GVA_GAME_STORE_COLUMN_INPUT_COINS: 
 @GVA_GAME_STORE_COLUMN_DRIVER_STATUS: 
diff --git a/src/gva-columns.c b/src/gva-columns.c
index 6d0455b..f60bece 100644
--- a/src/gva-columns.c
+++ b/src/gva-columns.c
@@ -24,6 +24,7 @@
 #include "gva-cell-renderer-pixbuf.h"
 #include "gva-error.h"
 #include "gva-favorites.h"
+#include "gva-nplayers.h"
 #include "gva-tree-view.h"
 #include "gva-ui.h"
 
@@ -504,6 +505,26 @@ columns_factory_input_players (GvaGameStoreColumn column_id)
 }
 
 static GtkTreeViewColumn *
+columns_factory_input_players_alt (GvaGameStoreColumn column_id)
+{
+#ifdef NPLAYERS_FILE
+        return columns_factory_input_players (column_id);
+#else
+        return NULL;
+#endif
+}
+
+static GtkTreeViewColumn *
+columns_factory_input_players_sim (GvaGameStoreColumn column_id)
+{
+#ifdef NPLAYERS_FILE
+        return columns_factory_input_players (column_id);
+#else
+        return NULL;
+#endif
+}
+
+static GtkTreeViewColumn *
 columns_factory_manufacturer (GvaGameStoreColumn column_id)
 {
         GtkTreeViewColumn *column;
@@ -787,11 +808,12 @@ columns_tooltip_favorite (GtkTreeModel *model,
                           GtkTreeIter *iter,
                           GtkTooltip *tooltip)
 {
+        GvaGameStoreColumn column_id;
         const gchar *text;
         gboolean favorite;
 
-        gtk_tree_model_get (
-                model, iter, GVA_GAME_STORE_COLUMN_FAVORITE, &favorite, -1);
+        column_id = GVA_GAME_STORE_COLUMN_FAVORITE;
+        gtk_tree_model_get (model, iter, column_id, &favorite, -1);
 
         if (favorite)
                 text = _("Click here to remove from favorites");
@@ -809,54 +831,66 @@ columns_tooltip_input_players (GtkTreeModel *model,
                                GtkTooltip *tooltip)
 {
         const gchar *text;
+        gint max_alternating;
+        gint max_simultaneous;
         gint max_players;
 
         gtk_tree_model_get (
                 model, iter,
+                GVA_GAME_STORE_COLUMN_INPUT_PLAYERS_ALT, &max_alternating,
+                GVA_GAME_STORE_COLUMN_INPUT_PLAYERS_SIM, &max_simultaneous,
                 GVA_GAME_STORE_COLUMN_INPUT_PLAYERS, &max_players, -1);
 
-        /* Keep this in sync with MAX_PLAYER_ICONS. */
-        switch (max_players)
-        {
-                case 1:
-                        text = _("One player only");
-                        break;
+        /* Fall back to "input_players" if we have to. */
+        if (max_alternating == 0 && max_simultaneous == 0)
+                max_alternating = max_simultaneous = max_players;
 
-                case 2:
-                        text = _("One or two players");
-                        break;
+        text = gva_nplayers_describe (max_alternating, max_simultaneous);
 
-                case 3:
-                        text = _("Up to three players");
-                        break;
+        /* This handles NULL for text. */
+        gtk_tooltip_set_text (tooltip, text);
 
-                case 4:
-                        text = _("Up to four players");
-                        break;
+        return (text != NULL);
+}
 
-                case 5:
-                        text = _("Up to five players");
-                        break;
+static gboolean
+columns_tooltip_input_players_alt (GtkTreeModel *model,
+                                   GtkTreeIter *iter,
+                                   GtkTooltip *tooltip)
+{
+        GvaGameStoreColumn column_id;
+        const gchar *text;
+        gint max_alternating;
 
-                case 6:
-                        text = _("Up to six players");
-                        break;
+        column_id = GVA_GAME_STORE_COLUMN_INPUT_PLAYERS_ALT;
+        gtk_tree_model_get (model, iter, column_id, &max_alternating, -1);
 
-                case 7:
-                        text = _("Up to seven players");
-                        break;
+        text = gva_nplayers_describe (max_alternating, 0);
 
-                case 8:
-                        text = _("Up to eight players");
-                        break;
+        /* This handles NULL for text. */
+        gtk_tooltip_set_text (tooltip, text);
 
-                default:
-                        return FALSE;
-        }
+        return (text != NULL);
+}
 
+static gboolean
+columns_tooltip_input_players_sim (GtkTreeModel *model,
+                                   GtkTreeIter *iter,
+                                   GtkTooltip *tooltip)
+{
+        GvaGameStoreColumn column_id;
+        const gchar *text;
+        gint max_simultaneous;
+
+        column_id = GVA_GAME_STORE_COLUMN_INPUT_PLAYERS_SIM;
+        gtk_tree_model_get (model, iter, column_id, &max_simultaneous, -1);
+
+        text = gva_nplayers_describe (0, max_simultaneous);
+
+        /* This handles NULL for text. */
         gtk_tooltip_set_text (tooltip, text);
 
-        return TRUE;
+        return (text != NULL);
 }
 
 static gboolean
@@ -940,6 +974,12 @@ column_info[GVA_GAME_STORE_NUM_COLUMNS] =
         { "input_players",      N_("Players"),
                                 columns_factory_input_players,
                                 columns_tooltip_input_players },
+        { "input_players_alt",  N_("Players (Alt.)"),
+                                columns_factory_input_players_alt,
+                                columns_tooltip_input_players_alt },
+        { "input_players_sim",  N_("Players (Sim.)"),
+                                columns_factory_input_players_sim,
+                                columns_tooltip_input_players_sim },
         { "input_buttons",      NULL },
         { "input_coins",        NULL },
         { "driver_status",      N_("Status"),
@@ -973,6 +1013,10 @@ static gchar *default_column_order[] =
         "bios",
         "driver_status",
         "input_players",
+#ifdef NPLAYERS_FILE
+        "input_players_alt",
+        "input_players_sim",
+#endif
         "name",
         "sourcefile",
         "sampleset"
diff --git a/src/gva-db.c b/src/gva-db.c
index 45367bf..2522acb 100644
--- a/src/gva-db.c
+++ b/src/gva-db.c
@@ -24,6 +24,7 @@
 #include "gva-error.h"
 #include "gva-favorites.h"
 #include "gva-mame.h"
+#include "gva-nplayers.h"
 #include "gva-util.h"
 
 #define ASSERT_OK(code) \
@@ -65,6 +66,8 @@
                 "input_tilt DEFAULT 'no' " \
                 "CHECK (input_tilt in ('yes', 'no')), " \
                 "input_players, " \
+                "input_players_alt, " \
+                "input_players_sim, " \
                 "input_buttons, " \
                 "input_coins, " \
                 "driver_status " \
@@ -240,6 +243,8 @@
                 "@input_service, " \
                 "@input_tilt, " \
                 "@input_players, " \
+                "@input_players_alt, " \
+                "@input_players_sim, " \
                 "@input_buttons, " \
                 "@input_coins, " \
                 "@driver_status, " \
@@ -436,6 +441,25 @@ static struct
 static sqlite3 *db = NULL;
 
 static void
+db_parser_bind_int (sqlite3_stmt *stmt,
+                    const gchar *param,
+                    gint value)
+{
+        gint index;
+        gint errcode;
+        GError *error = NULL;
+
+        index = sqlite3_bind_parameter_index (stmt, param);
+        errcode = sqlite3_bind_int (stmt, index, value);
+
+        if (errcode != SQLITE_OK)
+        {
+                gva_db_set_error (&error, 0, NULL);
+                gva_error_handle (&error);
+        }
+}
+
+static void
 db_parser_bind_text (sqlite3_stmt *stmt,
                      const gchar *param,
                      const gchar *value)
@@ -816,6 +840,13 @@ db_parser_start_element_input (ParserData *data,
         sqlite3_stmt *stmt = data->insert_game_stmt;
         gint ii;
 
+#ifdef NPLAYERS_FILE
+        gint error_code;
+        gint max_alternating = 0;
+        gint max_simultaneous = 0;
+        GError *local_error = NULL;
+#endif
+
         /* Bind default values. */
         db_parser_bind_text (stmt, "@input_service", "no");
         db_parser_bind_text (stmt, "@input_tilt", "no");
@@ -839,6 +870,31 @@ db_parser_start_element_input (ParserData *data,
 
                 db_parser_bind_text (stmt, param, attribute_value[ii]);
         }
+
+#ifdef NPLAYERS_FILE
+        /* Lookup players info from the nplayers.ini file. */
+        g_return_if_fail (data->game != NULL);
+        gva_nplayers_lookup (
+                data->game, &max_alternating,
+                &max_simultaneous, &local_error);
+
+        /* Silence "key not found" errors. */
+        error_code = G_KEY_FILE_ERROR_KEY_NOT_FOUND;
+        if (g_error_matches (local_error, G_KEY_FILE_ERROR, error_code))
+                g_clear_error (&local_error);
+ 
+        db_parser_bind_int (stmt, "@input_players_alt", max_alternating);
+        db_parser_bind_int (stmt, "@input_players_sim", max_simultaneous);
+
+        /* Override "input_players" if we can, because nplayers.ini
+         * seems to be more accurate than MAME's own XML data. */
+        if (max_alternating > 0 || max_simultaneous > 0)
+                db_parser_bind_int (
+                        stmt, "@input_players",
+                        MAX (max_alternating, max_simultaneous));
+        else if (local_error != NULL)
+                g_propagate_error (error, local_error);
+#endif
 }
 
 static void
diff --git a/src/gva-game-store.c b/src/gva-game-store.c
index e46249d..e3fb7e0 100644
--- a/src/gva-game-store.c
+++ b/src/gva-game-store.c
@@ -140,6 +140,8 @@ game_store_constructor (GType type,
         types[column++] = G_TYPE_BOOLEAN;    /* COLUMN_INPUT_SERVICE */
         types[column++] = G_TYPE_BOOLEAN;    /* COLUMN_INPUT_TILT */
         types[column++] = G_TYPE_INT;        /* COLUMN_INPUT_PLAYERS */
+        types[column++] = G_TYPE_INT;        /* COLUMN_INPUT_PLAYERS_ALT */
+        types[column++] = G_TYPE_INT;        /* COLUMN_INPUT_PLAYERS_SIM */
         types[column++] = G_TYPE_INT;        /* COLUMN_INPUT_BUTTONS */
         types[column++] = G_TYPE_INT;        /* COLUMN_INPUT_COINS */
         types[column++] = G_TYPE_STRING;     /* COLUMN_DRIVER_STATUS */
diff --git a/src/gva-game-store.h b/src/gva-game-store.h
index 1744e87..cbf4f70 100644
--- a/src/gva-game-store.h
+++ b/src/gva-game-store.h
@@ -93,6 +93,10 @@ typedef struct _GvaGameStoreClass GvaGameStoreClass;
  *      Corresponds to the "available.input_tile" database field.
  * @GVA_GAME_STORE_COLUMN_INPUT_PLAYERS:
  *      Corresponds to the "available.input_players" database field.
+ * @GVA_GAME_STORE_COLUMN_INPUT_PLAYERS_ALT:
+ *      Corresponds to the "available.input_players_alt" database field.
+ * @GVA_GAME_STORE_COLUMN_INPUT_PLAYERS_SIM:
+ *      Corresponds to the "available.input_players_sim" database field.
  * @GVA_GAME_STORE_COLUMN_INPUT_BUTTONS:
  *      Corresponds to the "available.input_buttons" database field.
  * @GVA_GAME_STORE_COLUMN_INPUT_COINS:
@@ -149,6 +153,8 @@ typedef enum
         GVA_GAME_STORE_COLUMN_INPUT_SERVICE,      /* G_TYPE_BOOLEAN */
         GVA_GAME_STORE_COLUMN_INPUT_TILT,         /* G_TYPE_BOOLEAN */
         GVA_GAME_STORE_COLUMN_INPUT_PLAYERS,      /* G_TYPE_INT */
+        GVA_GAME_STORE_COLUMN_INPUT_PLAYERS_ALT,  /* G_TYPE_INT */
+        GVA_GAME_STORE_COLUMN_INPUT_PLAYERS_SIM,  /* G_TYPE_INT */
         GVA_GAME_STORE_COLUMN_INPUT_BUTTONS,      /* G_TYPE_INT */
         GVA_GAME_STORE_COLUMN_INPUT_COINS,        /* G_TYPE_INT */
         GVA_GAME_STORE_COLUMN_DRIVER_STATUS,      /* G_TYPE_STRING */
diff --git a/src/gva-nplayers.c b/src/gva-nplayers.c
index 839ef11..50cf884 100644
--- a/src/gva-nplayers.c
+++ b/src/gva-nplayers.c
@@ -18,19 +18,20 @@
 
 #include "gva-nplayers.h"
 
+#include "gva-error.h"
+
 static GKeyFile *keyfile = NULL;
 
 static void
 nplayers_parse (const gchar *string,
-                guint *max_alt,
-                guint *max_sim)
+                gint *max_alternating,
+                gint *max_simultaneous)
 {
-        guint max_players;
+        gint max_players;
         gboolean parsable;
 
         /* Sanity check the string. */
-        parsable =
-                (strlen (string) > 2) &&
+        parsable = (strlen (string) >= 2) &&
                 g_ascii_isdigit (string[0]) &&
                 string[1] == 'P';
 
@@ -39,11 +40,15 @@ nplayers_parse (const gchar *string,
 
         max_players = string[0] - '0';
 
-        if (max_alt != NULL && g_str_has_suffix (string, " alt"))
-                *max_alt = max_players;
+        /* "1P" is a special case.  We'll return it as alternating. */
+        if (max_alternating != NULL && max_players == 1)
+                *max_alternating = max_players;
+
+        if (max_alternating != NULL && g_str_has_suffix (string, " alt"))
+                *max_alternating = max_players;
 
-        if (max_sim != NULL && g_str_has_suffix (string, " sim"))
-                *max_sim = max_players;
+        if (max_simultaneous != NULL && g_str_has_suffix (string, " sim"))
+                *max_simultaneous = max_players;
 }
 
 /**
@@ -91,7 +96,7 @@ gva_nplayers_init (GError **error)
         g_free (contents);
 #else
         g_message (
-                _("This program is not configured to show"
+                _("This program is not configured to show "
                   "detailed number of players information."));
 #endif
 
@@ -101,26 +106,26 @@ gva_nplayers_init (GError **error)
 /**
  * gva_nplayers_lookup:
  * @game: the name of a game
- * @max_alt: return location for the maximum number of alternating players
- * @max_sim: return location for the maximum number of simultaneous players
+ * @max_alternating: return location for the maximum alternating players
+ * @max_simultaneous: return location for the maximum simultaneous players
  * @error: return location for a #GError, or %NULL
  *
- * Returns the maximum number of alternating and/or simultaneous players
- * for @game.  If @game only allows alternating players, @max_sim will be
- * zero.  If @game only allows simultaneous players, @max_alt will be zero.
- * If @game is listed in the file but the number of players is unknown or
- * cannot be parsed, both @max_alt and @max_sim will be zero.  In all of
- * these cases the function returns %TRUE.
+ * Returns the maximum number of alternating and/or simultaneous players for
+ * @game.  If @game only allows alternating players, @max_simultaneous will
+ * be zero.  If @game only allows simultaneous players, @max_alternating will
+ * be zero.  If @game is listed in the file but the number of players is
+ * unknown or cannot be parsed, both @max_alternating and @max_simultaneous
+ * will be zero.  In all of these cases the function returns %TRUE.
  *
  * If an error occurs, the function returns %FALSE and sets @error, leaving
- * @max_alt and @max_sim unaltered.
+ * @max_alternating and @max_simultaneous unaltered.
  *
  * Returns: %TRUE on success, %FALSE if an error occurred
  **/
 gboolean
 gva_nplayers_lookup (const gchar *game,
-                     guint *max_alt,
-                     guint *max_sim,
+                     gint *max_alternating,
+                     gint *max_simultaneous,
                      GError **error)
 {
         gchar *nplayers;
@@ -130,20 +135,173 @@ gva_nplayers_lookup (const gchar *game,
         if (nplayers == NULL)
                 return FALSE;
 
-        if (max_alt != NULL)
-                *max_alt = 0;
+        if (max_alternating != NULL)
+                *max_alternating = 0;
 
-        if (max_sim != NULL)
-                *max_sim = 0;
+        if (max_simultaneous != NULL)
+                *max_simultaneous = 0;
 
         cp = strchr (nplayers, '/');
         if (cp != NULL)
         {
                 *cp++ = '\0';
-                nplayers_parse (g_strstrip (cp), max_alt, max_sim);
+                nplayers_parse (
+                        g_strstrip (cp), max_alternating, max_simultaneous);
         }
 
-        nplayers_parse (g_strstrip (nplayers), max_alt, max_sim);
+        nplayers_parse (
+                g_strstrip (nplayers), max_alternating, max_simultaneous);
 
         return TRUE;
 }
+
+/**
+ * gva_nplayers_describe:
+ * @max_alternating: the maximum alternating players
+ * @max_simultaneous: the maximum simultaneous players
+ *
+ * Returns a human-readable description of the number of players a game
+ * supports and whether the players alternate, play simultaneously, or
+ * both.  If a description can not be formed, the function returns %NULL.
+ *
+ * Returns: a human-readable description
+ **/
+const gchar *
+gva_nplayers_describe (gint max_alternating,
+                       gint max_simultaneous)
+{
+        g_return_val_if_fail (max_alternating >= 0, NULL);
+        g_return_val_if_fail (max_simultaneous >= 0, NULL);
+
+        /* XXX Known combinations are hard-coded. */
+
+        if (max_alternating == 4 && max_simultaneous == 2)
+                return _("Up to four players alternating "
+                         "or two players simultaneously");
+
+        if (max_alternating == 8 && max_simultaneous == 2)
+                return _("Up to eight players alternating "
+                         "or two players simultaneously");
+
+        /* XXX This is a stupid hack, but it works for now and keeps all
+         *     the descriptions in one place.  Should only get triggered
+         *     if we're getting player information from database queries
+         *     instead of an nplayers.ini file. */
+        if (max_alternating == max_simultaneous)
+        {
+                switch (max_alternating)
+                {
+                        case 0:
+                                break;
+
+                        case 1:
+                                return _("One player only");
+
+                        case 2:
+                                return _("One or two players");
+
+                        case 3:
+                                return _("Up to three players");
+
+                        case 4:
+                                return _("Up to four players");
+
+                        case 5:
+                                return _("Up to five players");
+
+                        case 6:
+                                return _("Up to six players");
+
+                        case 7:
+                                return _("Up to seven players");
+
+                        case 8:
+                                return _("Up to eight players");
+
+                        default:
+                                break;
+                }
+        }
+
+        if (max_alternating != 0 && max_simultaneous != 0)
+        {
+                g_warning (
+                        "Can't describe number of players: "
+                        "%dP alt / %dP sim", max_alternating,
+                        max_simultaneous);
+                return NULL;
+        }
+
+        switch (max_alternating)
+        {
+                case 0:
+                        break;
+
+                case 1:
+                        return _("One player only");
+
+                case 2:
+                        return _("One or two players alternating");
+
+                case 3:
+                        return _("Up to three players alternating");
+
+                case 4:
+                        return _("Up to four players alternating");
+
+                case 5:
+                        return _("Up to five players alternating");
+
+                case 6:
+                        return _("Up to six players alternating");
+
+                case 7:
+                        return _("Up to seven players alternating");
+
+                case 8:
+                        return _("Up to eight players alternating");
+
+                default:
+                        g_warning (
+                                "Can't describe number of players: "
+                                "%dP alt", max_alternating);
+                        break;
+        }
+
+        switch (max_simultaneous)
+        {
+                case 0:
+                        break;
+
+                case 1:
+                        return _("One player only");
+
+                case 2:
+                        return _("One or two players simultaneously");
+
+                case 3:
+                        return _("Up to three players simultaneously");
+
+                case 4:
+                        return _("Up to four players simultaneously");
+
+                case 5:
+                        return _("Up to five players simultaneously");
+
+                case 6:
+                        return _("Up to six players simultaneously");
+
+                case 7:
+                        return _("Up to seven players simultaneously");
+
+                case 8:
+                        return _("Up to eight players simultaneously");
+
+                default:
+                        g_warning (
+                                "Can't describe number of players: "
+                                "%dP sim", max_simultaneous);
+        }
+
+        return NULL;
+}
diff --git a/src/gva-nplayers.h b/src/gva-nplayers.h
index b701171..928c4c7 100644
--- a/src/gva-nplayers.h
+++ b/src/gva-nplayers.h
@@ -33,6 +33,12 @@
 G_BEGIN_DECLS
 
 gboolean        gva_nplayers_init               (GError **error);
+gboolean        gva_nplayers_lookup             (const gchar *game,
+                                                 gint *max_alternating,
+                                                 gint *max_simultaneous,
+                                                 GError **error);
+const gchar *   gva_nplayers_describe           (gint max_alternating,
+                                                 gint max_simultaneous);
 
 G_END_DECLS
 



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