[libgames-support] score: Provide default value for time



commit 1e20510b043b6657d65aca8616585d4b7d1f3d25
Author: Michael Catanzaro <mcatanzaro igalia com>
Date:   Sun Feb 14 14:32:28 2016 -0600

    score: Provide default value for time

 games/scores/context.vala |    3 +--
 games/scores/score.vala   |    8 ++++++--
 2 files changed, 7 insertions(+), 4 deletions(-)
---
diff --git a/games/scores/context.vala b/games/scores/context.vala
index 88f36b7..4679f5d 100644
--- a/games/scores/context.vala
+++ b/games/scores/context.vala
@@ -218,8 +218,7 @@ public class Context : Object
     /* Return true if a dialog was launched on attaining high score */
     public async bool add_score (long score_value, Category category, Cancellable? cancellable) throws Error
     {
-        var current_time = new DateTime.now_local ().to_unix ();
-        var score = new Score (score_value, current_time);
+        var score = new Score (score_value);
 
         /* Don't allow the dialog if it wouldn't have a parent, or in tests. */
         return yield add_score_internal (score, category, game_window != null, cancellable);
diff --git a/games/scores/score.vala b/games/scores/score.vala
index bbbbc81..ff5d5e3 100644
--- a/games/scores/score.vala
+++ b/games/scores/score.vala
@@ -25,12 +25,16 @@ public class Score : Object
 {
     public long score { get; set; }
     public string user { get; set; }
+
+    /* Although the scores dialog does not currently display the time a
+     * score was achieved, it did in the past and it might again in the future.
+     */
     public int64 time { get; set; }
 
-    public Score (long score, int64 time, string? user = null)
+    public Score (long score, int64 time = 0, string? user = null)
     {
         this.score = score;
-        this.time = time;
+        this.time = (time == 0 ? new DateTime.now_local ().to_unix () : time);
         this.user = (user == null ? Environment.get_real_name () : user);
     }
 


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