[gnome-tetravex] Use --enable-experimental-non-null.
- From: Arnaud B. <arnaudb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-tetravex] Use --enable-experimental-non-null.
- Date: Wed, 18 Sep 2019 00:45:56 +0000 (UTC)
commit 975b080b5511a48d0b38fc46a29b9baf61c2484d
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Tue Sep 17 06:36:42 2019 +0200
Use --enable-experimental-non-null.
src/gnome-tetravex.vala | 77 +++++++++++++++++++++++++++++++++++--------------
src/history.vala | 2 +-
src/meson.build | 3 +-
src/puzzle-view.vala | 51 +++++++++++++++++---------------
src/puzzle.vala | 41 +++++++++++++-------------
src/score-dialog.vala | 2 +-
src/theme.vala | 2 +-
7 files changed, 109 insertions(+), 69 deletions(-)
---
diff --git a/src/gnome-tetravex.vala b/src/gnome-tetravex.vala
index 39ae451..b27e2e3 100644
--- a/src/gnome-tetravex.vala
+++ b/src/gnome-tetravex.vala
@@ -13,6 +13,9 @@ using Gtk;
private class Tetravex : Gtk.Application
{
+ /* Translators: that is the name of the program, as seen in the headerbar, in GNOME Shell, or in the
about dialog */
+ private const string PROGRAM_NAME = _("Tetravex");
+
private const string KEY_GRID_SIZE = "grid-size";
private static bool start_paused = false;
@@ -21,6 +24,7 @@ private class Tetravex : Gtk.Application
private GLib.Settings settings;
private Puzzle puzzle;
+ private bool puzzle_init_done = false;
private Label clock_label;
private History history;
@@ -38,12 +42,12 @@ private class Tetravex : Gtk.Application
private SimpleAction pause_action;
private SimpleAction solve_action;
- private const OptionEntry[] option_entries =
+ private const OptionEntry [] option_entries =
{
{ "version", 'v', 0, OptionArg.NONE, null, N_("Print release version and exit"), null },
{ "paused", 'p', 0, OptionArg.NONE, null, N_("Start the game paused"), null },
{ "size", 's', 0, OptionArg.INT, null, N_("Set size of board (2-6)"), null },
- { null }
+ {}
};
private const GLib.ActionEntry[] action_entries =
@@ -84,7 +88,7 @@ private class Tetravex : Gtk.Application
{
base.startup ();
- Environment.set_application_name (_("Tetravex"));
+ Environment.set_application_name (PROGRAM_NAME);
Window.set_default_icon_name ("org.gnome.Tetravex");
add_action_entries (action_entries, this);
@@ -120,7 +124,7 @@ private class Tetravex : Gtk.Application
((SimpleAction) lookup_action ("size")).set_state ("%d".printf (game_size));
HeaderBar headerbar = new HeaderBar ();
- headerbar.title = _("Tetravex");
+ headerbar.title = PROGRAM_NAME;
headerbar.show_close_button = true;
window.set_titlebar (headerbar);
@@ -214,7 +218,9 @@ private class Tetravex : Gtk.Application
pause_action = (SimpleAction) lookup_action ("pause");
solve_action = (SimpleAction) lookup_action ("solve");
view.tile_selected.connect ((/* bool */ selected) => {
- if (puzzle == null || ((!) puzzle).is_solved)
+ if (!puzzle_init_done)
+ return;
+ if (puzzle.is_solved)
return;
solve_action.set_enabled (!selected);
});
@@ -289,11 +295,12 @@ private class Tetravex : Gtk.Application
solve_action.set_enabled (true);
new_game_solve_stack.set_visible_child_name ("solve");
- if (puzzle != null)
+ if (puzzle_init_done)
SignalHandler.disconnect_by_func (puzzle, null, this);
int size = settings.get_int (KEY_GRID_SIZE);
puzzle = new Puzzle ((uint8) size);
+ puzzle_init_done = true;
puzzle.tick.connect (tick_cb);
puzzle.solved.connect (solved_cb);
view.puzzle = puzzle;
@@ -310,7 +317,7 @@ private class Tetravex : Gtk.Application
private void tick_cb ()
{
int elapsed = 0;
- if (puzzle != null)
+ if (puzzle_init_done)
elapsed = (int) (puzzle.elapsed + 0.5);
int hours = elapsed / 3600;
int minutes = (elapsed - hours * 3600) / 60;
@@ -417,22 +424,48 @@ private class Tetravex : Gtk.Application
private void about_cb ()
{
- string[] authors = { "Lars Rydlinge", "Robert Ancell", null };
- string[] documenters = { "Rob Bradford", null };
+ string [] authors = {
+ /* Translators: text crediting a game author, seen in the About dialog */
+ _("Lars Rydlinge"),
+
+
+ /* Translators: text crediting a game author, seen in the About dialog */
+ _("Robert Ancell")
+ };
+
+ /* Translators: text crediting a game documenter, seen in the About dialog */
+ string [] documenters = { _("Rob Bradford") };
+
+
+ /* Translators: short description of the application, seen in the About dialog */
+ string comments = _("Position pieces so that the same numbers are touching each other");
+
+
+ /* Translators: text crediting a maintainer, seen in the About dialog; the %u are replaced with the
years of start and end */
+ string copyright = _("Copyright \xc2\xa9 %u-%u – Lars Rydlinge").printf (1999, 2008) + "\n" +
+
+
+ /* Translators: text crediting a maintainer, seen in the About dialog; the %u are replaced with the
years of start and end */
+ _("Copyright \xc2\xa9 %u-%u – Arnaud Bonatti").printf (2019, 2020);
+
+
+ /* Translators: about dialog text; label of the website link */
+ string website_label = _("Page on GNOME wiki");
+
show_about_dialog (window,
- "program-name", _("Tetravex"),
- "version", VERSION,
- "comments",
- _("Position pieces so that the same numbers are touching each other"),
- "copyright",
- "Copyright © 1999–2008 Lars Rydlinge",
- "license-type", License.GPL_2_0,
- "wrap-license", true,
- "authors", authors,
- "documenters", documenters,
- "translator-credits", _("translator-credits"),
- "logo-icon-name", "org.gnome.Tetravex",
- "website", "https://wiki.gnome.org/Apps/Tetravex",
+ "program-name", PROGRAM_NAME,
+ "version", VERSION,
+ "comments", comments,
+ "copyright", copyright,
+ "license-type", License.GPL_2_0,
+ "wrap-license", true,
+ "authors", authors,
+ "documenters", documenters,
+ /* Translators: about dialog text; this string should be replaced by a text crediting yourselves and
your translation team, or should be left empty. Do not translate literally! */
+ "translator-credits", _("translator-credits"),
+ "logo-icon-name", "org.gnome.Tetravex",
+ "website", "https://wiki.gnome.org/Apps/Tetravex",
+ "website-label", website_label,
null);
}
diff --git a/src/history.vala b/src/history.vala
index 4d88dda..822df20 100644
--- a/src/history.vala
+++ b/src/history.vala
@@ -57,7 +57,7 @@ private class History : Object
// FIXME use try_parse
- add (new HistoryEntry (date, size, duration));
+ add (new HistoryEntry ((!) date, size, duration));
}
}
diff --git a/src/meson.build b/src/meson.build
index 2b258f8..5aaf72b 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -13,7 +13,8 @@ gnome_tetravex = executable ('gnome-tetravex',
dependencies: [ glib_dep,
gtk_dep,
libm_dep ],
- vala_args: [ '--pkg=posix' ],
+ vala_args: [ '--pkg=posix',
+ '--enable-experimental-non-null' ],
c_args: [ '-DVERSION="@0@"'.format (meson.project_version ()),
'-DGETTEXT_PACKAGE="gnome-tetravex"',
'-DLOCALEDIR="@0@"'.format (localedir) ],
diff --git a/src/puzzle-view.vala b/src/puzzle-view.vala
index 5db3a3d..dcf1f7d 100644
--- a/src/puzzle-view.vala
+++ b/src/puzzle-view.vala
@@ -45,31 +45,32 @@ private class PuzzleView : Gtk.DrawingArea
/* Puzzle being rendered */
private Puzzle? _puzzle = null;
+ [CCode (notify = false)] private bool puzzle_init_done { get { return _puzzle != null; }}
[CCode (notify = false)] internal Puzzle puzzle
{
- private get { return _puzzle; }
+ private get { if (!puzzle_init_done) assert_not_reached (); return (!) _puzzle; }
internal set
{
- if (_puzzle != null)
- SignalHandler.disconnect_by_func (_puzzle, null, this);
+ if (puzzle_init_done)
+ SignalHandler.disconnect_by_func ((!) _puzzle, null, this);
_puzzle = value;
tiles.remove_all ();
- for (uint8 y = 0; y < puzzle.size; y++)
+ for (uint8 y = 0; y < ((!) _puzzle).size; y++)
{
- for (uint8 x = 0; x < puzzle.size * 2; x++)
+ for (uint8 x = 0; x < ((!) _puzzle).size * 2; x++)
{
- Tile? tile = puzzle.get_tile (x, y);
+ Tile? tile = ((!) _puzzle).get_tile (x, y);
if (tile == null)
continue;
- TileImage image = new TileImage (tile);
+ TileImage image = new TileImage ((!) tile);
move_tile_to_location (image, x, y);
- tiles.insert (tile, image);
+ tiles.insert ((!) tile, image);
}
}
- _puzzle.tile_moved.connect (tile_moved_cb);
- _puzzle.notify ["paused"].connect (() => { queue_draw (); });
+ ((!) _puzzle).tile_moved.connect (tile_moved_cb);
+ ((!) _puzzle).notify ["paused"].connect (() => { queue_draw (); });
queue_resize ();
}
}
@@ -222,7 +223,7 @@ private class PuzzleView : Gtk.DrawingArea
protected override void get_preferred_width (out int minimum, out int natural)
{
int size = 0;
- if (puzzle != null)
+ if (puzzle_init_done)
size = (int) ((puzzle.size * 2 + 1.5) * minimum_size);
minimum = natural = int.max (size, 500);
}
@@ -230,7 +231,7 @@ private class PuzzleView : Gtk.DrawingArea
protected override void get_preferred_height (out int minimum, out int natural)
{
int size = 0;
- if (puzzle != null)
+ if (puzzle_init_done)
size = (int) ((puzzle.size + 1) * minimum_size);
minimum = natural = int.max (size, 300);
}
@@ -273,7 +274,7 @@ private class PuzzleView : Gtk.DrawingArea
protected override bool draw (Cairo.Context context)
{
- if (puzzle == null)
+ if (!puzzle_init_done)
return false;
uint x_offset, y_offset, size, gap;
@@ -312,7 +313,9 @@ private class PuzzleView : Gtk.DrawingArea
if (!iter.next (out tile, out image))
break;
- if (image == selected_tile || image.x != image.target_x || image.y != image.target_y)
+ if ((selected_tile != null && image == (!) selected_tile)
+ || (image.x != image.target_x)
+ || (image.y != image.target_y))
continue;
context.save ();
@@ -333,7 +336,9 @@ private class PuzzleView : Gtk.DrawingArea
if (!iter.next (out tile, out image))
break;
- if (image != selected_tile && image.x == image.target_x && image.y == image.target_y)
+ if ((selected_tile != null && image != (!) selected_tile)
+ && (image.x == image.target_x)
+ && (image.y == image.target_y))
continue;
context.save ();
@@ -442,16 +447,16 @@ private class PuzzleView : Gtk.DrawingArea
/* Drop the tile here, or move it back if can't */
uint8 selected_x, selected_y;
- puzzle.get_tile_location (selected_tile.tile, out selected_x, out selected_y);
+ puzzle.get_tile_location (((!) selected_tile).tile, out selected_x, out selected_y);
if (puzzle.can_switch (selected_x, selected_y, (uint8) tile_x, (uint8) tile_y))
puzzle.switch_tiles (selected_x, selected_y, (uint8) tile_x, (uint8) tile_y);
else
- move_tile_to_location (selected_tile, selected_x, selected_y, 0.2);
+ move_tile_to_location ((!) selected_tile, selected_x, selected_y, 0.2);
selected_tile = null;
tile_selected (false);
}
- private void move_tile_to_right_half (TileImage image)
+ private void move_tile_to_right_half (Tile tile)
{
/* Pick the first open spot on the right side of the board */
for (uint8 y = 0; y < puzzle.size; y++)
@@ -461,7 +466,7 @@ private class PuzzleView : Gtk.DrawingArea
if (puzzle.get_tile (x, y) == null)
{
uint8 source_x, source_y;
- puzzle.get_tile_location (image.tile, out source_x, out source_y);
+ puzzle.get_tile_location (tile, out source_x, out source_y);
puzzle.switch_tiles (source_x, source_y, x, y);
return;
}
@@ -481,15 +486,15 @@ private class PuzzleView : Gtk.DrawingArea
{
if (selected_tile == null)
pick_tile (event.x, event.y);
- else if (selected_tile != null)
+ else
drop_tile (event.x, event.y);
}
else if (event.type == Gdk.EventType.DOUBLE_BUTTON_PRESS)
{
/* Move tile from left to right on double click */
pick_tile (event.x, event.y);
- if (selected_tile != null && !on_right_half (selected_tile.x))
- move_tile_to_right_half (selected_tile);
+ if (selected_tile != null && !on_right_half (((!) selected_tile).x))
+ move_tile_to_right_half (((!) selected_tile).tile);
selected_tile = null;
tile_selected (false);
}
@@ -516,7 +521,7 @@ private class PuzzleView : Gtk.DrawingArea
protected override bool motion_notify_event (Gdk.EventMotion event)
{
if (selected_tile != null)
- move_tile (selected_tile, (int) (event.x - selected_x_offset), (int) (event.y -
selected_y_offset));
+ move_tile ((!) selected_tile, (int) (event.x - selected_x_offset), (int) (event.y -
selected_y_offset));
return false;
}
diff --git a/src/puzzle.vala b/src/puzzle.vala
index 5b7805c..05f9f0c 100644
--- a/src/puzzle.vala
+++ b/src/puzzle.vala
@@ -30,7 +30,7 @@ private class Tile : Object
private class Puzzle : Object
{
[CCode (notify = false)] public uint8 size { internal get; protected construct; }
- private Tile [,] board;
+ private Tile? [,] board;
/* Game timer */
private double clock_elapsed;
@@ -43,7 +43,7 @@ private class Puzzle : Object
{
if (clock == null)
return 0.0;
- return clock_elapsed + clock.elapsed ();
+ return clock_elapsed + ((!) clock).elapsed ();
}
}
@@ -95,7 +95,7 @@ private class Puzzle : Object
construct
{
- board = new Tile [size * 2, size];
+ board = new Tile? [size * 2, size];
for (uint8 x = 0; x < size; x++)
for (uint8 y = 0; y < size; y++)
board [x, y] = new Tile (x, y);
@@ -107,9 +107,9 @@ private class Puzzle : Object
{
uint8 n = (uint8) Random.int_range (0, 10);
if (y >= 1)
- board [x, y - 1].south = n;
+ ((!) board [x, y - 1]).south = n;
if (y < size)
- board [x, y].north = n;
+ ((!) board [x, y]).north = n;
}
}
for (uint8 x = 0; x <= size; x++)
@@ -118,9 +118,9 @@ private class Puzzle : Object
{
uint8 n = (uint8) Random.int_range (0, 10);
if (x >= 1)
- board [x - 1, y].east = n;
+ ((!) board [x - 1, y]).east = n;
if (x < size)
- board [x, y].west = n;
+ ((!) board [x, y]).west = n;
}
}
@@ -130,7 +130,7 @@ private class Puzzle : Object
{
for (uint8 y = 0; y < size; y++)
{
- tiles.append (board [x, y]);
+ tiles.append ((!) board [x, y]);
board [x, y] = null;
}
}
@@ -170,13 +170,13 @@ private class Puzzle : Object
if (tile == null)
return false;
- if (x1 > 0 && !(x1 - 1 == x0 && y1 == y0) && board [x1 - 1, y1] != null && board [x1 - 1, y1].east
!= tile.west)
+ if (x1 > 0 && !(x1 - 1 == x0 && y1 == y0) && board [x1 - 1, y1] != null && ((!) board [x1 - 1,
y1]).east != ((!) tile).west)
return false;
- if (x1 < size - 1 && !(x1 + 1 == x0 && y1 == y0) && board [x1 + 1, y1] != null && board [x1 + 1,
y1].west != tile.east)
+ if (x1 < size - 1 && !(x1 + 1 == x0 && y1 == y0) && board [x1 + 1, y1] != null && ((!) board [x1 +
1, y1]).west != ((!) tile).east)
return false;
- if (y1 > 0 && !(x1 == x0 && y1 - 1 == y0) && board [x1, y1 - 1] != null && board [x1, y1 - 1].south
!= tile.north)
+ if (y1 > 0 && !(x1 == x0 && y1 - 1 == y0) && board [x1, y1 - 1] != null && ((!) board [x1, y1 -
1]).south != ((!) tile).north)
return false;
- if (y1 < size - 1 && !(x1 == x0 && y1 + 1 == y0) && board [x1, y1 + 1] != null && board [x1, y1 +
1].north != tile.south)
+ if (y1 < size - 1 && !(x1 == x0 && y1 + 1 == y0) && board [x1, y1 + 1] != null && ((!) board [x1, y1
+ 1]).north != ((!) tile).south)
return false;
return true;
@@ -214,9 +214,9 @@ private class Puzzle : Object
board [x1, y1] = t0;
if (t0 != null)
- tile_moved (t0, x1, y1);
+ tile_moved ((!) t0, x1, y1);
if (t1 != null)
- tile_moved (t1, x0, y0);
+ tile_moved ((!) t1, x0, y0);
if (is_solved)
{
@@ -303,14 +303,14 @@ private class Puzzle : Object
internal void solve ()
{
- List<Tile> wrong_tiles = null;
+ List<Tile> wrong_tiles = new List<Tile> ();
for (uint8 x = 0; x < size * 2; x++)
{
for (uint8 y = 0; y < size; y++)
{
Tile? tile = board [x, y];
- if (tile != null && (tile.x != x || tile.y != y))
- wrong_tiles.append (tile);
+ if (tile != null && (((!) tile).x != x || ((!) tile).y != y))
+ wrong_tiles.append ((!) tile);
board [x, y] = null;
}
}
@@ -342,7 +342,7 @@ private class Puzzle : Object
if (clock_timeout != 0)
Source.remove (clock_timeout);
clock_timeout = 0;
- clock.stop ();
+ ((!) clock).stop ();
tick ();
}
@@ -351,14 +351,15 @@ private class Puzzle : Object
if (clock == null)
clock = new Timer ();
else
- clock.@continue ();
+ ((!) clock).@continue ();
timeout_cb ();
}
private bool timeout_cb ()
+ requires (clock != null)
{
/* Notify on the next tick */
- double elapsed = clock.elapsed ();
+ double elapsed = ((!) clock).elapsed ();
int next = (int) (elapsed + 1.0);
double wait = (double) next - elapsed;
clock_timeout = Timeout.add ((int) (wait * 1000), timeout_cb);
diff --git a/src/score-dialog.vala b/src/score-dialog.vala
index 31d219e..8bbccc3 100644
--- a/src/score-dialog.vala
+++ b/src/score-dialog.vala
@@ -172,7 +172,7 @@ private class ScoreDialog : Gtk.Dialog
size_combo.set_active_iter (iter);
/* Select this entry if the same category as the selected one */
- if (selected_entry != null && entry.size == selected_entry.size)
+ if (selected_entry != null && entry.size == ((!) selected_entry).size)
size_combo.set_active_iter (iter);
}
}
diff --git a/src/theme.vala b/src/theme.vala
index b2c404d..cb3291d 100644
--- a/src/theme.vala
+++ b/src/theme.vala
@@ -137,7 +137,7 @@ private class Theme : Object
draw_tile_background (context, size, paused_color, paused_color, paused_color, paused_color);
}
- internal void draw_tile (Cairo.Context context, uint size, Tile? tile)
+ internal void draw_tile (Cairo.Context context, uint size, Tile tile)
{
draw_tile_background (context, size, tile_colors [tile.north], tile_colors [tile.east], tile_colors
[tile.south], tile_colors [tile.west]);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]