[gnome-games/wip/abhinavsingh/gamepad-reassign: 4/9] core: Add ControllerSet



commit 0fcd826f0aace7691d9928daa175afcee1c496b0
Author: theawless <theawless gmail com>
Date:   Sat Aug 12 00:05:25 2017 +0530

    core: Add ControllerSet
    
    This will be used to move controller information from retro to ui
    similar to media set.

 src/Makefile.am              |    1 +
 src/core/controller-set.vala |   53 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 54 insertions(+), 0 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 645eb45..e9cd162 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -64,6 +64,7 @@ gnome_games_SOURCES = \
        core/game-collection.vala \
        core/game-uri-adapter.vala \
        core/icon.vala \
+       core/controller-set.vala \
        core/input-capabilities.vala \
        core/media.vala \
        core/media-info.vala \
diff --git a/src/core/controller-set.vala b/src/core/controller-set.vala
new file mode 100644
index 0000000..eee90ca
--- /dev/null
+++ b/src/core/controller-set.vala
@@ -0,0 +1,53 @@
+// This file is part of GNOME Games. License: GPL-3.0+.
+
+private class Games.ControllerSet : Object {
+       public signal void changed ();
+       public signal void reset ();
+
+       public bool has_multiple_inputs {
+               get {
+                       return has_keyboard && gamepads.length > 0
+                       || gamepads.length > 1;
+               }
+       }
+
+       public bool has_keyboard {
+               get { return keyboard_port != uint.MAX; }
+       }
+
+       public bool has_gamepads {
+               get { return gamepads.length > 0; }
+       }
+
+       public uint first_unplugged_port {
+               get {
+                       uint i = 0;
+                       while (gamepads.contains (i) || i == keyboard_port) {
+                               i++;
+                       }
+                       return i;
+               }
+       }
+
+       public uint keyboard_port {     set; get; }
+       public HashTable<uint, Gamepad?> gamepads { set; get; }
+
+       construct {
+               keyboard_port = uint.MAX;
+               gamepads = new HashTable<uint, Gamepad?> (GLib.direct_hash, GLib.direct_equal);
+               notify["gamepads"].connect (() => changed ());
+               notify["keyboard-port"].connect (() => changed ());
+       }
+
+       public void add_gamepad (uint port, Gamepad gamepad) {
+               gamepads.insert (port, gamepad);
+
+               changed ();
+       }
+
+       public void remove_gamepad (uint port) {
+               gamepads.remove (port);
+
+               changed ();
+       }
+}


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