[gnome-nibbles/arnaudb/kill-preferences-dialog: 2/4] Allow to set a key used by absent worm.
- From: Arnaud B. <arnaudb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-nibbles/arnaudb/kill-preferences-dialog: 2/4] Allow to set a key used by absent worm.
- Date: Fri, 12 Jun 2020 14:30:04 +0000 (UTC)
commit 7bde70396c575030dc45d823e4371d2e0ffdf34d
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Fri Jun 12 09:57:46 2020 +0200
Allow to set a key used by absent worm.
src/nibbles-game.vala | 2 --
src/preferences-dialog.vala | 18 ++++++++++--------
2 files changed, 10 insertions(+), 10 deletions(-)
---
diff --git a/src/nibbles-game.vala b/src/nibbles-game.vala
index d83c949..51a3617 100644
--- a/src/nibbles-game.vala
+++ b/src/nibbles-game.vala
@@ -30,8 +30,6 @@ private class NibblesGame : Object
{
internal const int GAMEDELAY = 35;
- internal const int MAX_HUMANS = 4;
- internal const int MAX_AI = 5;
internal const int MAX_WORMS = 6;
internal const int MAX_SPEED = 4;
diff --git a/src/preferences-dialog.vala b/src/preferences-dialog.vala
index 2cbc772..d21354c 100644
--- a/src/preferences-dialog.vala
+++ b/src/preferences-dialog.vala
@@ -48,6 +48,8 @@ private class PreferencesDialog : Window
private EventControllerKey key_controller; // for keeping in memory
+ public int n_worms { private get; protected construct; }
+
construct
{
key_controller = new EventControllerKey (this);
@@ -74,7 +76,7 @@ private class PreferencesDialog : Window
internal PreferencesDialog (ApplicationWindow window, GLib.Settings settings,
Gee.ArrayList<GLib.Settings> worm_settings, int worm_id, int n_worms)
{
- Object (transient_for: window);
+ Object (transient_for: window, n_worms: n_worms);
this.settings = settings;
this.worm_settings = worm_settings;
@@ -173,17 +175,17 @@ private class PreferencesDialog : Window
if (key == null)
return;
- if (worm_settings[id].get_int (key) == keyval)
+ if (keyval == worm_settings [id].get_int (key))
return;
/* Duplicate key check */
bool valid = true;
- for (int i = 0; i < NibblesGame.MAX_HUMANS; i++)
+ for (int i = 0; i < n_worms; i++)
{
- if (worm_settings[i].get_int ("key-up") == keyval ||
- worm_settings[i].get_int ("key-down") == keyval ||
- worm_settings[i].get_int ("key-left") == keyval ||
- worm_settings[i].get_int ("key-right") == keyval)
+ if (keyval == worm_settings [i].get_int ("key-up")
+ || keyval == worm_settings [i].get_int ("key-down")
+ || keyval == worm_settings [i].get_int ("key-left")
+ || keyval == worm_settings [i].get_int ("key-right"))
{
valid = false;
@@ -246,7 +248,7 @@ private class PreferencesDialog : Window
worm_settings[i].set_enum ("color", color_old);
/* Update swapped colors in UI */
- if (i < NibblesGame.MAX_HUMANS)
+ if (i < n_worms)
{
foreach (var cbox in combo_boxes)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]