[gnome-games/wip/exalm/ds: 6/15] savestate: Allow platforms to use custom savestate types



commit 5f2f5ac37e055ca1aadd39d548de4cd33913703d
Author: Alexander Mikhaylenko <exalm7659 gmail com>
Date:   Mon Aug 12 23:00:54 2019 +0500

    savestate: Allow platforms to use custom savestate types
    
    Replace savestate constructor with Savestate.load() which takes platform
    and creates an instance of type returned by Platform.get_savestate_type().
    
    This will be used to subclass savestates for Nintendo DS.

 src/core/savestate.vala     | 19 +++++++++++--------
 src/retro/retro-runner.vala |  8 ++++----
 2 files changed, 15 insertions(+), 12 deletions(-)
---
diff --git a/src/core/savestate.vala b/src/core/savestate.vala
index 977a9e04..4d40da97 100644
--- a/src/core/savestate.vala
+++ b/src/core/savestate.vala
@@ -1,8 +1,11 @@
 public class Games.Savestate : Object {
-       private string path; // Path to the savestate directory
+       public string path { get; construct; }
+       public Platform platform { get; construct; }
 
-       public Savestate (string path) {
-               this.path = path;
+       public static Savestate load (Platform platform, string path) {
+               var type = platform.get_savestate_type ();
+
+               return Object.new (type, "path", path, "platform", platform, null) as Savestate;
        }
 
        protected KeyFile get_metadata () {
@@ -134,7 +137,7 @@ public class Games.Savestate : Object {
 
                FileOperations.copy_contents (cloned_savestate_dir, tmp_savestate_dir);
 
-               return new Savestate (tmp_savestate_path);
+               return Savestate.load (platform, tmp_savestate_path);
        }
 
        // This method is used to save the savestate in /tmp as a regular savestate
@@ -210,7 +213,7 @@ public class Games.Savestate : Object {
                }
        }
 
-       public static Savestate[] get_game_savestates (Uid game_uid, string core_id) throws Error {
+       public static Savestate[] get_game_savestates (Uid game_uid, Platform platform, string core_id) 
throws Error {
                var data_dir_path = Application.get_data_dir ();
                var savestates_dir_path = Path.build_filename (data_dir_path, "savestates");
                var uid_str = game_uid.get_uid ();
@@ -231,7 +234,7 @@ public class Games.Savestate : Object {
 
                while ((savestate_name = game_savestates_dir.read_name ()) != null) {
                        var savestate_path = Path.build_filename (game_savestates_dir_path, savestate_name);
-                       game_savestates += new Savestate (savestate_path);
+                       game_savestates += Savestate.load (platform, savestate_path);
                }
 
                // Sort the savestates array by creation dates
@@ -255,8 +258,8 @@ public class Games.Savestate : Object {
                return 1;
        }
 
-       public static Savestate create_empty_in_tmp () throws Error {
-               return new Savestate (prepare_empty_savestate_in_tmp ());
+       public static Savestate create_empty_in_tmp (Platform platform) throws Error {
+               return Savestate.load (platform, prepare_empty_savestate_in_tmp ());
        }
 
        // Returns the path of the newly created dir in tmp
diff --git a/src/retro/retro-runner.vala b/src/retro/retro-runner.vala
index 5e2ab607..e57b8092 100644
--- a/src/retro/retro-runner.vala
+++ b/src/retro/retro-runner.vala
@@ -135,7 +135,7 @@ public class Games.RetroRunner : Object, Runner {
 
        private void init_phase_one () throws Error {
                // Step 1) Load the game's savestates ----------------------------------
-               game_savestates = Savestate.get_game_savestates (uid, get_core_id ());
+               game_savestates = Savestate.get_game_savestates (uid, platform, get_core_id ());
                if (game_savestates.length != 0)
                        latest_savestate = game_savestates[0];
 
@@ -147,7 +147,7 @@ public class Games.RetroRunner : Object, Runner {
 
                // Step 3) Instantiate the core
                // This is needed to check if the core supports savestates
-               tmp_live_savestate = Savestate.create_empty_in_tmp ();
+               tmp_live_savestate = Savestate.create_empty_in_tmp (platform);
                instantiate_core (tmp_live_savestate.get_save_directory_path ());
 
                // Step 4) Preview the latest savestate --------------------------------
@@ -225,7 +225,7 @@ public class Games.RetroRunner : Object, Runner {
                        if (latest_savestate != null)
                                tmp_live_savestate = latest_savestate.clone_in_tmp ();
                        else
-                               tmp_live_savestate = Savestate.create_empty_in_tmp ();
+                               tmp_live_savestate = Savestate.create_empty_in_tmp (platform);
 
                        instantiate_core (tmp_live_savestate.get_save_directory_path ());
                }
@@ -491,7 +491,7 @@ public class Games.RetroRunner : Object, Runner {
 
                // Instantiate the Savestate object
                var savestate_path = Path.build_filename (game_savestates_dir_path, now_time.to_string ());
-               var savestate = new Savestate (savestate_path);
+               var savestate = Savestate.load (platform, savestate_path);
 
                // Update the game_savestates array
                // Insert the new savestate at the beginning of the array since it's the latest savestate


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