[gnome-games/wip/exalm/savestates: 15/22] savestate: Make screenshot aspect ratio a property
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games/wip/exalm/savestates: 15/22] savestate: Make screenshot aspect ratio a property
- Date: Sat, 25 Jan 2020 20:09:33 +0000 (UTC)
commit 4a1a869f28ce3559380c159d94da352972337d48
Author: Alexander Mikhaylenko <alexm gnome org>
Date: Sun Jan 26 00:41:57 2020 +0500
savestate: Make screenshot aspect ratio a property
src/core/savestate.vala | 30 ++++++++++++------------------
src/retro/retro-runner.vala | 2 +-
src/ui/savestate-listbox-row.vala | 2 +-
3 files changed, 14 insertions(+), 20 deletions(-)
---
diff --git a/src/core/savestate.vala b/src/core/savestate.vala
index e0abbdad..5138fcb2 100644
--- a/src/core/savestate.vala
+++ b/src/core/savestate.vala
@@ -8,6 +8,7 @@ public class Games.Savestate : Object {
public string name { get; set; }
public DateTime? creation_date { get; private set; }
public string core { get; private set; }
+ public double screenshot_aspect_ratio { get; private set; }
private static Savestate load (Platform platform, string path) {
var type = platform.get_savestate_type ();
@@ -50,19 +51,6 @@ public class Games.Savestate : Object {
return metadata;
}
- public double get_screenshot_aspect_ratio () {
- var metadata = get_metadata ();
-
- try {
- return metadata.get_double ("Screenshot", "Aspect Ratio");
- }
- catch (Error e) {
- // Migrated savestates are not going to have the correct aspect ratio.
- // Fail gracefully and don't print
- return 0;
- }
- }
-
public void set_snapshot_data (Bytes snapshot_data) throws Error {
var buffer = snapshot_data.get_data ();
var snapshot_path = Path.build_filename (path, "snapshot");
@@ -161,8 +149,9 @@ public class Games.Savestate : Object {
is_automatic = true;
this.creation_date = creation_date;
this.core = core;
+ this.screenshot_aspect_ratio = aspect_ratio;
- set_metadata (aspect_ratio);
+ set_metadata ();
}
// Set the metadata for a manual savestate
@@ -171,8 +160,9 @@ public class Games.Savestate : Object {
this.name = name;
this.creation_date = creation_date;
this.core = core;
+ this.screenshot_aspect_ratio = aspect_ratio;
- set_metadata (aspect_ratio);
+ set_metadata ();
}
protected virtual void load_metadata (KeyFile keyfile) throws KeyFileError {
@@ -185,6 +175,10 @@ public class Games.Savestate : Object {
var creation_date_str = keyfile.get_string ("Metadata", "Creation Date");
creation_date = new DateTime.from_iso8601 (creation_date_str, new TimeZone.local ());
+
+ core = keyfile.get_string ("Metadata", "Core");
+
+ screenshot_aspect_ratio = keyfile.get_double ("Screenshot", "Aspect Ratio");
}
protected virtual void save_metadata (KeyFile keyfile) {
@@ -196,9 +190,11 @@ public class Games.Savestate : Object {
// FIXME: This is unused
keyfile.set_string ("Metadata", "Platform", platform.get_uid_prefix ());
keyfile.set_string ("Metadata", "Core", core);
+
+ keyfile.set_double ("Screenshot", "Aspect Ratio", screenshot_aspect_ratio);
}
- private void set_metadata (double aspect_ratio) throws Error {
+ private void set_metadata () throws Error {
var metadata_file_path = Path.build_filename (path, "metadata");
var metadata_file = File.new_for_path (metadata_file_path);
var metadata = new KeyFile ();
@@ -206,8 +202,6 @@ public class Games.Savestate : Object {
if (metadata_file.query_exists ())
metadata_file.@delete ();
- metadata.set_double ("Screenshot", "Aspect Ratio", aspect_ratio);
-
save_metadata (metadata);
metadata.save_to_file (metadata_file_path);
diff --git a/src/retro/retro-runner.vala b/src/retro/retro-runner.vala
index 2e27da0b..5d664233 100644
--- a/src/retro/retro-runner.vala
+++ b/src/retro/retro-runner.vala
@@ -185,7 +185,7 @@ public class Games.RetroRunner : Object, Runner {
try {
pixbuf = new Gdk.Pixbuf.from_file (screenshot_path);
- var aspect_ratio = savestate.get_screenshot_aspect_ratio ();
+ var aspect_ratio = savestate.screenshot_aspect_ratio;
if (aspect_ratio != 0)
Retro.pixbuf_set_aspect_ratio (pixbuf, (float) aspect_ratio);
diff --git a/src/ui/savestate-listbox-row.vala b/src/ui/savestate-listbox-row.vala
index fde08213..21cf3dff 100644
--- a/src/ui/savestate-listbox-row.vala
+++ b/src/ui/savestate-listbox-row.vala
@@ -48,7 +48,7 @@ private class Games.SavestateListBoxRow : Gtk.ListBoxRow {
Gdk.Pixbuf.get_file_info (screenshot_path, out screenshot_width, out screenshot_height);
- var aspect_ratio = (double) savestate.get_screenshot_aspect_ratio ();
+ var aspect_ratio = savestate.screenshot_aspect_ratio;
// A fallback for migrated savestates
if (aspect_ratio == 0)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]