After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 736238 - Warn user when changing board size
Warn user when changing board size
Status: RESOLVED FIXED
Product: gnome-tetravex
Classification: Applications
Component: general
3.12.x
Other Linux
: Normal minor
: ---
Assigned To: gnome-tetravex-maint
gnome-tetravex-maint
Depends on:
Blocks:
 
 
Reported: 2014-09-07 19:29 UTC by Michael Catanzaro
Modified: 2014-10-14 21:36 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Warning user when changing board size (2.85 KB, patch)
2014-09-08 14:28 UTC, amisha
needs-work Details | Review
Warning user when changing board size (2.86 KB, patch)
2014-09-08 18:16 UTC, amisha
needs-work Details | Review
Warning user when changing board size (2.48 KB, patch)
2014-09-08 20:26 UTC, amisha
none Details | Review
Warning user when changing board size (2.43 KB, patch)
2014-09-08 20:44 UTC, amisha
reviewed Details | Review
Warning user when changing board size (2.43 KB, patch)
2014-09-10 16:51 UTC, amisha
committed Details | Review

Description Michael Catanzaro 2014-09-07 19:29:32 UTC
When changing board size from the app menu, we need to show a warning dialog before restarting the game if there are any game pieces on the left side of the map.
Comment 1 amisha 2014-09-08 14:28:09 UTC
Created attachment 285651 [details] [review]
Warning user when changing board size
Comment 2 Mario Wenzel 2014-09-08 14:40:17 UTC
Review of attachment 285651 [details] [review]:

::: src/gnome-tetravex.vala
@@ +476,3 @@
+        {
+            action.change_state (parameter);
+        }

I think this all should happen in size_changed ( ... ) (~:429) and not in the general radio_cb.

@@ +479,3 @@
+        else
+        {
+            var size = ((string) parameter)[0] - '0';

This is taken straight from size_changed(). This is the hint that the code actually belongs there.

::: src/puzzle-view.vala
@@ +106,3 @@
     }
+
+    public bool has_tile_on_left ()

This should be something more like "game is underway" and should also return false if the game is finished (you can use is_solved for that).
Comment 3 amisha 2014-09-08 18:16:07 UTC
Created attachment 285667 [details] [review]
Warning user when changing board size
Comment 4 Mario Wenzel 2014-09-08 18:41:01 UTC
Review of attachment 285667 [details] [review]:

I think we're getting there. :)

::: src/gnome-tetravex.vala
@@ +441,3 @@
+                                                _("Are you sure you want to select new board size?"));
+            dialog.add_buttons (_("_Keep Playing"), Gtk.ResponseType.REJECT,
+                                                Gtk.DialogFlags.MODAL,

These texts may need changing by a native speaker. I would opt for:
"Changing the size of the board starts a new game and the current progress will be lost.".
And "Cancel" and "Continue".

Because that was the issue, that the game restarts unexpectedly. Therefore we want to inform the user that this is the case.

@@ +452,3 @@
+                game_size = (int) size;
+                action.set_state (value);
+                                null);

I think this code doesn't need to be duplicated. We can just have that at the end of the method and return earlier, as we do in line 434.

So maybe something like if response != accept -> return and removing the else-part of the if-statement.

The thing is, we actually always want to do those four lines (changing settings and starting a new game) but there are cases where we just return early. The code shoud reflect that.

::: src/puzzle-view.vala
@@ +106,3 @@
     }
+
+    public bool game_in_progress ()

I think we can have that a read-only-property. This is pretty nice in vala.

@@ +110,3 @@
+        if (!puzzle.is_solved)
+        {
+            for (uint y = 0; y < puzzle.size; y++)

Can we not nest this too much? We can start this method off with if (!puzzle.is_solved) return false;

This doesn't change anything for the result but increases readability. We foremost write code for humans/developers and not for the compiler. So obviousness and readability are always key.
Comment 5 Michael Catanzaro 2014-09-08 19:37:14 UTC
(In reply to comment #4)
> Review of attachment 285667 [details] [review]:
> 
> I think we're getting there. :)
> 
> ::: src/gnome-tetravex.vala
> @@ +441,3 @@
> +                                                _("Are you sure you want to
> select new board size?"));
> +            dialog.add_buttons (_("_Keep Playing"), Gtk.ResponseType.REJECT,
> +                                                Gtk.DialogFlags.MODAL,
> 
> These texts may need changing by a native speaker. I would opt for:
> "Changing the size of the board starts a new game and the current progress will
> be lost.".
> And "Cancel" and "Continue".

How about:

_("Are you sure you want to start a new game with a different board size?")

_("_Keep Playing")
_("Start _New Game")
Comment 6 amisha 2014-09-08 20:26:44 UTC
Created attachment 285678 [details] [review]
Warning user when changing board size
Comment 7 Michael Catanzaro 2014-09-08 20:33:55 UTC
Review of attachment 285678 [details] [review]:

::: src/puzzle-view.vala
@@ +106,3 @@
     }
+
+    public bool game_in_progress

This should be a function, is_game_in_progress, not a property.

@@ +118,3 @@
+                {
+                    if (puzzle.get_tile (x, y) == null)
+                    {

No need for the extra braces on the if statement; they don't make the code easier to read.
Comment 8 Michael Catanzaro 2014-09-08 20:39:21 UTC
(In reply to comment #4)
> ::: src/puzzle-view.vala
> @@ +106,3 @@
>      }
> +
> +    public bool game_in_progress ()
> 
> I think we can have that a read-only-property. This is pretty nice in vala.

Eh, sorry, follow Mario's preference here, not mine.  I like to avoid complex properties but that's just a matter of style; either way is fine.
Comment 9 Mario Wenzel 2014-09-08 20:43:11 UTC
I suggested that because since we *do* have properties in our language. Methods, even without parameters, maybe imply side effects for the reader. :)

reading a property should not have side effects
Comment 10 amisha 2014-09-08 20:44:00 UTC
Created attachment 285680 [details] [review]
Warning user when changing board size
Comment 11 Michael Catanzaro 2014-09-10 16:43:45 UTC
Review of attachment 285680 [details] [review]:

Just one problem left:

::: src/gnome-tetravex.vala
@@ +433,3 @@
         if (size == settings.get_int (KEY_GRID_SIZE))
             return;
+        if (view.game_in_progress ())

Does this compile?  :)
Comment 12 amisha 2014-09-10 16:51:31 UTC
Created attachment 285838 [details] [review]
Warning user when changing board size
Comment 13 Michael Catanzaro 2014-09-10 16:55:55 UTC
Review of attachment 285838 [details] [review]:

Looks good.
Comment 14 amisha 2014-09-10 16:57:59 UTC
Thanks . :)