[gnome-mines/wip/libgames-support: 5/8] Improve category generation function
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-mines/wip/libgames-support: 5/8] Improve category generation function
- Date: Mon, 15 Feb 2016 16:06:04 +0000 (UTC)
commit 1d17d71d008ed54371aec83a49feb5797d27cd8b
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 f94c3e7..31924c4 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]