[gnome-games/wip/exalm/ds: 9/11] nintendo-ds: Add NintendoDsRunner



commit d078c04546d362c07f1d0afe1d5f58494d1756fb
Author: Alexander Mikhaylenko <exalm7659 gmail com>
Date:   Sun Jan 6 20:49:33 2019 +0500

    nintendo-ds: Add NintendoDsRunner
    
    Add a proxy around RetroRunner that uses game_init() and game_deinit()
    signals to track game state and set desmume_screens_layout option
    according to gsettings.
    
    Also implement get_extra_widget() to return a NintendoDsLayoutSwitcher.

 plugins/nintendo-ds/src/meson.build             |   1 +
 plugins/nintendo-ds/src/nintendo-ds-runner.vala | 119 ++++++++++++++++++++++++
 2 files changed, 120 insertions(+)
---
diff --git a/plugins/nintendo-ds/src/meson.build b/plugins/nintendo-ds/src/meson.build
index 74730c77..29993a5d 100644
--- a/plugins/nintendo-ds/src/meson.build
+++ b/plugins/nintendo-ds/src/meson.build
@@ -2,6 +2,7 @@ vala_sources = [
   'nintendo-ds-icon.vala',
   'nintendo-ds-layout-switcher.vala',
   'nintendo-ds-plugin.vala',
+  'nintendo-ds-runner.vala',
 ]
 
 c_sources = [
diff --git a/plugins/nintendo-ds/src/nintendo-ds-runner.vala b/plugins/nintendo-ds/src/nintendo-ds-runner.vala
new file mode 100644
index 00000000..48dd4d39
--- /dev/null
+++ b/plugins/nintendo-ds/src/nintendo-ds-runner.vala
@@ -0,0 +1,119 @@
+// This file is part of GNOME Games. License: GPL-3.0+.
+
+private class Games.NintendoDsRunner : Object, Runner {
+       private RetroRunner runner;
+       private Settings settings;
+       private ulong settings_changed_id;
+
+       private const string SCREENS_LAYOUT_OPTION = "desmume_screens_layout";
+
+       public NintendoDsRunner (RetroRunner runner) {
+               this.runner = runner;
+
+               runner.game_init.connect (on_init);
+               runner.game_deinit.connect (on_deinit);
+       }
+
+       private bool core_supports_layouts () {
+               var core = runner.get_core ();
+
+               return core != null && core.has_option (SCREENS_LAYOUT_OPTION);
+       }
+
+       private void on_init () {
+               settings = new Settings ("org.gnome.Games.plugins.nintendo-ds");
+               settings_changed_id = settings.changed.connect (on_changed);
+
+               var core = runner.get_core ();
+
+               core.options_set.connect (update_screen_layout);
+       }
+
+       private void on_deinit () {
+               if (settings_changed_id > 0) {
+                       settings.disconnect (settings_changed_id);
+                       settings_changed_id = 0;
+
+                       settings = null;
+               }
+       }
+
+       private void on_changed (string key) {
+               if (key == "screen-layout")
+                       update_screen_layout ();
+       }
+
+       private void update_screen_layout () {
+               if (!core_supports_layouts ())
+                       return;
+
+               var core = runner.get_core ();
+
+               var option = core.get_option (SCREENS_LAYOUT_OPTION);
+
+               var value = settings.get_string ("screen-layout");
+
+               try {
+                       option.set_value (value);
+               }
+               catch (Error e) {
+                       critical (e.message);
+               }
+       }
+
+       public bool can_fullscreen {
+               get { return runner.can_fullscreen; }
+       }
+
+       public bool can_quit_safely {
+               get { return runner.can_quit_safely; }
+       }
+
+       public bool can_resume {
+               get { return runner.can_resume; }
+       }
+
+       public MediaSet? media_set {
+               get { return runner.media_set; }
+       }
+
+       public InputMode input_mode {
+               get { return runner.input_mode; }
+               set { runner.input_mode = value; }
+       }
+
+       public bool check_is_valid (out string error_message) throws Error {
+               return runner.check_is_valid (out error_message);
+       }
+
+       public Gtk.Widget get_display () {
+               return runner.get_display ();
+       }
+
+       public Gtk.Widget? get_extra_widget () {
+               if (!core_supports_layouts ())
+                       return null;
+
+               return new NintendoDsLayoutSwitcher ();
+       }
+
+       public void start () throws Error {
+               runner.start ();
+       }
+
+       public void resume () throws Error {
+               runner.resume ();
+       }
+
+       public void pause () {
+               runner.pause ();
+       }
+
+       public void stop () {
+               runner.stop ();
+       }
+
+       public InputMode[] get_available_input_modes () {
+               return runner.get_available_input_modes ();
+       }
+}


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