[gnome-robots] locate scores-related code in one module
- From: Andrey Kutejko <akutejko src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-robots] locate scores-related code in one module
- Date: Tue, 6 Oct 2020 19:31:42 +0000 (UTC)
commit b1550ca6f6df6d0f984feefe5251fe285af0a9a6
Author: Andrey Kutejko <andy128k gmail com>
Date: Sun Sep 27 22:59:44 2020 +0200
locate scores-related code in one module
src/game-area.vala | 24 ++++++++----------------
src/game.vala | 7 -------
src/robots.vala | 15 ++++++++++++++-
3 files changed, 22 insertions(+), 24 deletions(-)
---
diff --git a/src/game-area.vala b/src/game-area.vala
index 679cf9d..ef5b049 100644
--- a/src/game-area.vala
+++ b/src/game-area.vala
@@ -20,7 +20,6 @@
using Gtk;
using Gdk;
using Cairo;
-using Games;
public class GameArea : DrawingArea {
@@ -82,6 +81,7 @@ public class GameArea : DrawingArea {
private Properties properties;
public signal void updated (Game game);
+ public signal void add_score (string game_type, int score);
public GameArea (Game game,
Theme theme,
@@ -352,29 +352,21 @@ public class GameArea : DrawingArea {
/**
* Enters a score in the high-score table
**/
- private void log_score (int sc) {
- if (sc <= 0) {
+ private void log_score (int score) {
+ if (score <= 0) {
return;
}
- string key;
+ string game_type;
if (properties.super_safe_moves) {
- key = game.config.description + "-super-safe";
+ game_type = game.config.description + "-super-safe";
} else if (properties.safe_moves) {
- key = game.config.description + "-safe";
+ game_type = game.config.description + "-safe";
} else {
- key = game.config.description;
+ game_type = game.config.description;
}
- string name = category_name_from_key (key);
- var category = new Scores.Category (key, name);
- highscores.add_score.begin (sc, category, null, (ctx, res) => {
- try {
- highscores.add_score.end (res);
- } catch (Error error) {
- warning ("Failed to add score: %s", error.message);
- }
- });
+ add_score (game_type, score);
}
private void play_sound (Sound sound) {
diff --git a/src/game.vala b/src/game.vala
index d3af8ee..e5df117 100644
--- a/src/game.vala
+++ b/src/game.vala
@@ -155,13 +155,6 @@ public class Game {
public signal void game_event (Event event, int param = 0);
- /**
- * Displays the high-score table
- **/
- public void show_scores () {
- highscores.run_dialog ();
- }
-
/**
* Ends the current game.
**/
diff --git a/src/robots.vala b/src/robots.vala
index 48efb69..501b45e 100644
--- a/src/robots.vala
+++ b/src/robots.vala
@@ -19,6 +19,7 @@
using Gtk;
using Cairo;
+using Games;
RobotsWindow window = null;
int window_width = 0;
@@ -328,6 +329,18 @@ class RobotsApplication : Gtk.Application {
quit ();
}
+ game_area.add_score.connect ((game_type, score) => {
+ string name = category_name_from_key (game_type);
+ var category = new Scores.Category (game_type, name);
+ highscores.add_score.begin (score, category, null, (ctx, res) => {
+ try {
+ highscores.add_score.end (res);
+ } catch (Error error) {
+ warning ("Failed to add score: %s", error.message);
+ }
+ });
+ });
+
game_area.background_color = properties.bgcolour;
keyboard_set (properties.keys);
@@ -390,7 +403,7 @@ class RobotsApplication : Gtk.Application {
}
private void scores_cb () {
- game.show_scores ();
+ highscores.run_dialog ();
}
private void help_cb () {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]