[gnome-games/wip/aplazas/options: 1/5] input-capabilities: Turn it into a class



commit 851d519ac4cf2c3132588066656768dea49e6b8e
Author: Adrien Plazas <kekun plazas laposte net>
Date:   Fri Nov 24 09:26:30 2017 +0100

    input-capabilities: Turn it into a class
    
    This will help having a default set of capabilities that classes can
    simply expand upon by subclassing it and overriding methods, and will
    help avoiding having null input capabilities or a dummy one to represent
    the default state.

 src/core/input-capabilities.vala                   |   11 ++++++++---
 .../gameinfo-disc-id-input-capabilities.vala       |    9 +++------
 2 files changed, 11 insertions(+), 9 deletions(-)
---
diff --git a/src/core/input-capabilities.vala b/src/core/input-capabilities.vala
index 2e1e43a..3d61f25 100644
--- a/src/core/input-capabilities.vala
+++ b/src/core/input-capabilities.vala
@@ -1,6 +1,11 @@
 // This file is part of GNOME Games. License: GPL-3.0+.
 
-public interface Games.InputCapabilities : Object {
-       public abstract bool get_allow_classic_gamepads () throws Error;
-       public abstract bool get_allow_analog_gamepads () throws Error;
+public class Games.InputCapabilities : Object {
+       public virtual bool get_allow_classic_gamepads () throws Error {
+               return true;
+       }
+
+       public virtual bool get_allow_analog_gamepads () throws Error {
+               return true;
+       }
 }
diff --git a/src/gameinfo/gameinfo-disc-id-input-capabilities.vala 
b/src/gameinfo/gameinfo-disc-id-input-capabilities.vala
index f5c40d3..a19cb1b 100644
--- a/src/gameinfo/gameinfo-disc-id-input-capabilities.vala
+++ b/src/gameinfo/gameinfo-disc-id-input-capabilities.vala
@@ -1,9 +1,6 @@
 // This file is part of GNOME Games. License: GPL-3.0+.
 
-public class Games.GameinfoDiscIdInputCapabilities : Object, InputCapabilities {
-       public bool default_allow_classic_gamepads { set; get; }
-       public bool default_allow_analog_gamepads { set; get; }
-
+public class Games.GameinfoDiscIdInputCapabilities : InputCapabilities {
        private GameinfoDoc gameinfo;
        private string disc_id;
        private string[] controllers;
@@ -18,7 +15,7 @@ public class Games.GameinfoDiscIdInputCapabilities : Object, InputCapabilities {
                        controllers = gameinfo.get_game_controllers_for_disc_id (disc_id);
 
                if (controllers.length == 0)
-                       return default_allow_classic_gamepads;
+                       return base.get_allow_classic_gamepads ();
 
                return "classic-gamepad" in controllers;
        }
@@ -28,7 +25,7 @@ public class Games.GameinfoDiscIdInputCapabilities : Object, InputCapabilities {
                        controllers = gameinfo.get_game_controllers_for_disc_id (disc_id);
 
                if (controllers.length == 0)
-                       return default_allow_analog_gamepads;
+                       return base.get_allow_analog_gamepads ();
 
                return "analog-gamepad" in controllers;
        }


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