[swell-foop/arnaudb/add---version: 8/9] Store scores on uint.
- From: Robert Roth <robertroth src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [swell-foop/arnaudb/add---version: 8/9] Store scores on uint.
- Date: Thu, 14 May 2020 23:00:44 +0000 (UTC)
commit 5834063a4fdee73af7ccefcc176053167facc1d4
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Thu May 14 18:35:27 2020 +0200
Store scores on uint.
data/org.gnome.swell-foop.gschema.xml | 2 +-
src/game-view.vala | 6 +++---
src/game.vala | 26 +++++++++++++-------------
src/window.vala | 4 ++--
4 files changed, 19 insertions(+), 19 deletions(-)
---
diff --git a/data/org.gnome.swell-foop.gschema.xml b/data/org.gnome.swell-foop.gschema.xml
index e63b093..98c7515 100644
--- a/data/org.gnome.swell-foop.gschema.xml
+++ b/data/org.gnome.swell-foop.gschema.xml
@@ -41,7 +41,7 @@
<!-- Translators: description of a settings key, see 'dconf-editor /org/gnome/swell-foop/zealous' -->
<description>Use more flashy, but slower, animations.</description>
</key>
- <key name="saved-game" type="m(yqaay)">
+ <key name="saved-game" type="m(yuaay)">
<default>nothing</default>
<!-- Translators: summary of a settings key, see 'dconf-editor /org/gnome/swell-foop/saved-game' -->
<summary>Saved game</summary>
diff --git a/src/game-view.vala b/src/game-view.vala
index bc9a7bd..96c26da 100644
--- a/src/game-view.vala
+++ b/src/game-view.vala
@@ -380,7 +380,7 @@ private class GameGroup : Clutter.Group
}
/* Show flying score animation after each tile-removing click */
- private void update_score_cb (int points_awarded)
+ private void update_score_cb (uint points_awarded)
{
if (is_zealous)
{
@@ -543,9 +543,9 @@ private class ScoreActor : Clutter.Group
this.game_size = game_size;
}
- internal void animate_score (int points)
+ internal void animate_score (uint points)
{
- if (points <= 0)
+ if (points == 0)
return;
label.set_font_name ("Bitstrem Vera Sans Bold 30");
diff --git a/src/game.vala b/src/game.vala
index ea2efa8..7d995df 100644
--- a/src/game.vala
+++ b/src/game.vala
@@ -70,7 +70,7 @@ private class Game : Object
private bool is_started = false;
/* Game score */
- internal int score { internal get; private set; default = 0; }
+ internal uint score { internal get; private set; default = 0; }
private uint8 _color_num = 3;
public uint8 color_num
@@ -89,7 +89,7 @@ private class Game : Object
public uint8 rows { internal get; protected construct; }
public uint8 columns { internal get; protected construct; }
- internal signal void update_score (int points_awarded);
+ internal signal void update_score (uint points_awarded);
internal signal void complete ();
internal signal void started ();
@@ -247,7 +247,7 @@ private class Game : Object
for (uint8 y = 0; y < rows; y++)
tiles[y, new_x] = null;
- increment_score_from_tiles ((int) cl.length ());
+ increment_score_from_tiles ((uint16) cl.length ());
if (!is_started) {
is_started = true;
@@ -295,17 +295,17 @@ private class Game : Object
return true;
}
- internal void increment_score_from_tiles (int n_tiles)
+ private void increment_score_from_tiles (uint16 n_tiles)
{
- var points_awarded = 0;
+ uint points_awarded = 0;
if (n_tiles >= 3)
- points_awarded = (n_tiles - 2) * (n_tiles - 2);
+ points_awarded = (uint) (n_tiles - 2) * (uint) (n_tiles - 2);
increment_score (points_awarded);
}
- internal void increment_score (int increment)
+ private void increment_score (uint increment)
{
score += increment;
update_score (increment);
@@ -317,7 +317,7 @@ private class Game : Object
private inline bool load_saved_game (Variant variant)
{
- if (variant.get_type_string () != "m(yqaay)")
+ if (variant.get_type_string () != "m(yuaay)")
return false; // assert_not_reached() ?
Variant? child = variant.get_maybe ();
@@ -326,9 +326,9 @@ private class Game : Object
VariantIter iter = new VariantIter ((!) child);
uint8 color_num;
- uint16 score;
+ uint score;
iter.next ("y", out color_num);
- iter.next ("q", out score);
+ iter.next ("u", out score);
Variant? tmp_variant = iter.next_value ();
if (tmp_variant == null)
assert_not_reached ();
@@ -368,11 +368,11 @@ private class Game : Object
internal Variant get_saved_game ()
{
if (!is_started || has_completed ())
- return new Variant ("m(yqaay)", null);
+ return new Variant ("m(yuaay)", null);
- VariantBuilder builder = new VariantBuilder (new VariantType ("(yqaay)"));
+ VariantBuilder builder = new VariantBuilder (new VariantType ("(yuaay)"));
builder.add ("y", color_num);
- builder.add ("q", (uint16) score);
+ builder.add ("u", score);
builder.open (new VariantType ("aay"));
VariantType ay_type = new VariantType ("ay");
for (uint8 i = rows; i > 0; i--)
diff --git a/src/window.vala b/src/window.vala
index 1f2dd97..ed2846e 100644
--- a/src/window.vala
+++ b/src/window.vala
@@ -175,9 +175,9 @@ private class SwellFoopWindow : ApplicationWindow
* * various
\*/
- private void update_score_cb (int points_awarded)
+ private void update_score_cb (uint points_awarded)
{
- var score = 0;
+ uint score = 0;
if (game != null)
score = game.score;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]