[gnome-games/wip/exalm/ds: 7/9] nintendo-ds: Add NintendoDsSavestate



commit 9bc52f3153c80c9bfe7177a6397c8d4bfc4127ba
Author: Alexander Mikhaylenko <exalm7659 gmail com>
Date:   Wed Aug 14 04:17:38 2019 +0500

    nintendo-ds: Add NintendoDsSavestate
    
    This special savestate stores screen layout and which screen is visible
    if quick switch is used.
    
    NintendoDsRunner is supposed to override load_extra_savestate_metadata(),
    call load_extra_metadata() from it and use the property values.
    
    Similarly, it overrides save_extra_savestate_metadata() and change the
    properties, so that later they are written into the keyfile.

 plugins/nintendo-ds/src/meson.build                |  1 +
 plugins/nintendo-ds/src/nintendo-ds-savestate.vala | 26 ++++++++++++++++++++++
 2 files changed, 27 insertions(+)
---
diff --git a/plugins/nintendo-ds/src/meson.build b/plugins/nintendo-ds/src/meson.build
index 49c03b88..3f3d6186 100644
--- a/plugins/nintendo-ds/src/meson.build
+++ b/plugins/nintendo-ds/src/meson.build
@@ -6,6 +6,7 @@ vala_sources = [
   'nintendo-ds-platform.vala',
   'nintendo-ds-plugin.vala',
   'nintendo-ds-runner.vala',
+  'nintendo-ds-savestate.vala',
 ]
 
 c_sources = [
diff --git a/plugins/nintendo-ds/src/nintendo-ds-savestate.vala 
b/plugins/nintendo-ds/src/nintendo-ds-savestate.vala
new file mode 100644
index 00000000..9c82888d
--- /dev/null
+++ b/plugins/nintendo-ds/src/nintendo-ds-savestate.vala
@@ -0,0 +1,26 @@
+// This file is part of GNOME Games. License: GPL-3.0+.
+
+public class Games.NintendoDsSavestate : Savestate {
+       public NintendoDsLayout screen_layout { get; set; }
+       public bool view_bottom_screen { get; set; }
+
+       public void load_extra_metadata () {
+               var keyfile = get_metadata ();
+
+               try {
+                       var layout_value = keyfile.get_string ("Nintendo DS", "Screen Layout");
+                       view_bottom_screen = keyfile.get_boolean ("Nintendo DS", "View Bottom Screen");
+
+                       screen_layout = NintendoDsLayout.from_value (layout_value);
+               }
+               catch (KeyFileError e) {
+                       critical ("Failed to get Nintendo DS metadata from metadata file for savestate at %s: 
%s", path, e.message);
+                       return;
+               }
+       }
+
+       protected override void save_extra_metadata (KeyFile keyfile) {
+               keyfile.set_string ("Nintendo DS", "Screen Layout", screen_layout.get_value ());
+               keyfile.set_boolean ("Nintendo DS", "View Bottom Screen", view_bottom_screen);
+       }
+}


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