Commit 5f2f5ac3 authored by Alexander Mikhaylenko's avatar Alexander Mikhaylenko

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.
parent 9e405ba9
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
......
......@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment