[five-or-more/arnaudb/kill-preferences-dialog: 6/10] Clean BoardSize code.
- From: Arnaud B. <arnaudb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [five-or-more/arnaudb/kill-preferences-dialog: 6/10] Clean BoardSize code.
- Date: Fri, 8 May 2020 16:02:38 +0000 (UTC)
commit b3aba812dccd4b3ac227d0485995153e633055c9
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Fri May 8 14:15:59 2020 +0200
Clean BoardSize code.
data/five-or-more.ui | 6 +++---
data/org.gnome.five-or-more.gschema.xml | 1 +
src/game.vala | 9 ---------
src/window.vala | 27 ++++++++++++++++++---------
4 files changed, 22 insertions(+), 21 deletions(-)
---
diff --git a/data/five-or-more.ui b/data/five-or-more.ui
index ba74da7..c1c1831 100644
--- a/data/five-or-more.ui
+++ b/data/five-or-more.ui
@@ -16,19 +16,19 @@
<!-- Translators: entry of the hamburger menu (with a mnemonic that appears when pressing Alt);
starts a new game of small size -->
<attribute name="label" translatable="yes">_Small</attribute>
<attribute name="action">win.change-size</attribute>
- <attribute name="target">BOARD_SIZE_SMALL</attribute>
+ <attribute name="target">small</attribute>
</item>
<item>
<!-- Translators: entry of the hamburger menu (with a mnemonic that appears when pressing Alt);
starts a new game of medium size -->
<attribute name="label" translatable="yes">_Medium</attribute>
<attribute name="action">win.change-size</attribute>
- <attribute name="target">BOARD_SIZE_MEDIUM</attribute>
+ <attribute name="target">medium</attribute>
</item>
<item>
<!-- Translators: entry of the hamburger menu (with a mnemonic that appears when pressing Alt);
starts a new game of large size -->
<attribute name="label" translatable="yes">_Large</attribute>
<attribute name="action">win.change-size</attribute>
- <attribute name="target">BOARD_SIZE_LARGE</attribute>
+ <attribute name="target">large</attribute>
</item>
</section>
<section>
diff --git a/data/org.gnome.five-or-more.gschema.xml b/data/org.gnome.five-or-more.gschema.xml
index 4776b3f..7f2f3db 100644
--- a/data/org.gnome.five-or-more.gschema.xml
+++ b/data/org.gnome.five-or-more.gschema.xml
@@ -2,6 +2,7 @@
<schema id="org.gnome.five-or-more" path="/org/gnome/five-or-more/" gettext-domain="five-or-more">
<key name="size" type="i">
<default>2</default>
+ <range min="1" max="3"/>
<summary>Playing field size</summary>
<description>Playing field size. 1=Small, 2=Medium, 3=Large. Any other value is invalid.</description>
</key>
diff --git a/src/game.vala b/src/game.vala
index 9bbc812..1442365 100644
--- a/src/game.vala
+++ b/src/game.vala
@@ -272,15 +272,6 @@ private class Game : Object
}
}
-private enum BoardSize
-{
- UNSET,
- SMALL,
- MEDIUM,
- LARGE,
- MAX_SIZE,
-}
-
private struct GameDifficulty
{
public int n_cols;
diff --git a/src/window.vala b/src/window.vala
index 9b93c34..d965cf4 100644
--- a/src/window.vala
+++ b/src/window.vala
@@ -57,8 +57,8 @@ private class GameWindow : ApplicationWindow
{ "background", change_background },
{ "reset-bg", reset_background },
- { "change-size", null, "s", "'BOARD_SIZE_SMALL'", change_size },
- { "change-theme", null, "s", "'balls.svg'", change_theme },
+ { "change-size", null, "s", "'small'", change_size },
+ { "change-theme", null, "s", "'balls.svg'", change_theme },
{ "new-game", new_game },
{ "scores", show_scores }
@@ -76,10 +76,18 @@ private class GameWindow : ApplicationWindow
this.settings = settings;
var board_size_action = lookup_action ("change-size");
- BoardSize board_size = (BoardSize) settings.get_int (FiveOrMoreApp.KEY_SIZE);
- ((SimpleAction) board_size_action).set_state (new Variant.string (board_size.to_string ()));
+ string board_size_string;
+ int board_size = settings.get_int (FiveOrMoreApp.KEY_SIZE);
+ switch (board_size)
+ {
+ case 1: board_size_string = "small"; break;
+ case 2: board_size_string = "medium"; break;
+ case 3: board_size_string = "large"; break;
+ default: assert_not_reached ();
+ }
+ ((SimpleAction) board_size_action).set_state (board_size_string);
- game = new Game ((int) board_size);
+ game = new Game (board_size);
theme = new ThemeRenderer (settings);
set_default_size (settings.get_int ("window-width"), settings.get_int ("window-height"));
@@ -195,13 +203,14 @@ private class GameWindow : ApplicationWindow
}
private inline void change_size (SimpleAction action, Variant? parameter)
+ requires (parameter != null)
{
int size;
action.set_state (parameter);
- switch (parameter.get_string()) {
- case "BOARD_SIZE_SMALL": size = (int) BoardSize.SMALL; break;
- case "BOARD_SIZE_MEDIUM": size = (int) BoardSize.MEDIUM; break;
- case "BOARD_SIZE_LARGE": size = (int) BoardSize.LARGE; break;
+ switch (parameter.get_string ()) {
+ case "small": size = 1; break;
+ case "medium": size = 2; break;
+ case "large": size = 3; break;
default: assert_not_reached ();
}
settings.set_int (FiveOrMoreApp.KEY_SIZE, size);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]