[gnome-mines/wip/libgames-support: 3/5] Improve category generation function



commit 5078ee250202786fa869f3059eeda742dc098b6d
Author: Michael Catanzaro <mcatanzaro igalia com>
Date:   Sun Feb 14 20:22:26 2016 -0600

    Improve category generation function
    
    Add some more error checking, and attempt to make the name translatable
    (though no doubt this will be difficult for some languages).

 src/gnome-mines.vala |   13 +++++++++++--
 1 files changed, 11 insertions(+), 2 deletions(-)
---
diff --git a/src/gnome-mines.vala b/src/gnome-mines.vala
index 6ac72f6..0619368 100644
--- a/src/gnome-mines.vala
+++ b/src/gnome-mines.vala
@@ -335,11 +335,20 @@ public class Mines : Gtk.Application
     private Games.Scores.Category? create_category_from_key (string key)
     {
         var tokens = key.split ("-");
-
         if (tokens.length != 3)
             return null;
 
-        return new Games.Scores.Category (key, tokens[0] + " × " + tokens[1] + ", " + tokens[2] + " mines");
+        var width = int.parse (tokens[0]);
+        var height = int.parse (tokens[1]);
+        var num_mines = int.parse (tokens[2]);
+
+        if (width <= 0 || height <= 0 || num_mines <= 0)
+            return null;
+
+        /* For the scores dialog. First width, then height, then number of mines. */
+        return new Games.Scores.Category (key, ngettext ("%d × %d, %d mine",
+                                                         "%d × %d, %d mines",
+                                                         num_mines).printf (width, height, num_mines));
     }
 
     private void startup_new_game_screen (Gtk.Builder builder)


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