[gnome-games/wip/exalm/uid] game: Make platform a property



commit 4536a50dda89a49ff3e0373ec42f0eeedd247a91
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Fri Feb 21 21:41:50 2020 +0500

    game: Make platform a property

 src/core/game-collection.vala |  2 +-
 src/core/game-model.vala      |  4 ++--
 src/core/game.vala            |  8 ++------
 src/core/platform-model.vala  |  6 +++---
 src/database/database.vala    |  2 +-
 src/retro/retro-runner.vala   | 12 ++++++------
 src/ui/platforms-view.vala    |  4 ++--
 7 files changed, 17 insertions(+), 21 deletions(-)
---
diff --git a/src/core/game-collection.vala b/src/core/game-collection.vala
index 932c6715..af8cb776 100644
--- a/src/core/game-collection.vala
+++ b/src/core/game-collection.vala
@@ -169,7 +169,7 @@ private class Games.GameCollection : Object {
        }
 
        public Runner? create_runner (Game game) {
-               var platform = game.get_platform ();
+               var platform = game.platform;
 
                if (!runner_factories_for_platforms.contains (platform))
                        return null;
diff --git a/src/core/game-model.vala b/src/core/game-model.vala
index d40044ba..280f46ea 100644
--- a/src/core/game-model.vala
+++ b/src/core/game-model.vala
@@ -62,8 +62,8 @@ private class Games.GameModel : Object, ListModel {
                if (ret != 0)
                        return ret;
 
-               ret = a.get_platform ().get_name ().collate (
-                     b.get_platform ().get_name ());
+               ret = a.platform.get_name ().collate (
+                     b.platform.get_name ());
                if (ret != 0)
                        return ret;
 
diff --git a/src/core/game.vala b/src/core/game.vala
index b3043b6d..81fe0c3a 100644
--- a/src/core/game.vala
+++ b/src/core/game.vala
@@ -22,18 +22,18 @@ public class Games.Game : Object {
 
        public string uid { get; private set; }
        public Uri uri { get; private set; }
+       public Platform platform { get; private set; }
 
        private Title game_title;
        private Icon game_icon;
        private Cover game_cover;
-       private Platform game_platform;
        private MediaSet? media_set;
 
        public Game (string uid, Uri uri, Title title, Platform platform) {
                this.uid = uid;
                this.uri = uri;
                game_title = title;
-               game_platform = platform;
+               this.platform = platform;
        }
 
        public Icon get_icon () {
@@ -66,10 +66,6 @@ public class Games.Game : Object {
                this.media_set = media_set;
        }
 
-       public Platform get_platform () {
-               return game_platform;
-       }
-
        public bool matches_search_terms (string[] search_terms) {
                if (search_terms.length != 0)
                        foreach (var term in search_terms)
diff --git a/src/core/platform-model.vala b/src/core/platform-model.vala
index 142077ea..504129ef 100644
--- a/src/core/platform-model.vala
+++ b/src/core/platform-model.vala
@@ -15,7 +15,7 @@ private class Games.PlatformModel : Object, ListModel {
                uint n = game_model.get_n_items ();
                for (uint i = 0; i < n; i++) {
                        var game = game_model.get_item (i) as Game;
-                       var platform = game.get_platform ();
+                       var platform = game.platform;
 
                        if (n_games[platform] == 0) {
                                sequence.append (platform);
@@ -48,7 +48,7 @@ private class Games.PlatformModel : Object, ListModel {
        }
 
        private void game_added (Game game) {
-               var platform = game.get_platform ();
+               var platform = game.platform;
 
                if (n_games[platform] == 0) {
                        var iter = sequence.insert_sorted (platform, compare_func);
@@ -59,7 +59,7 @@ private class Games.PlatformModel : Object, ListModel {
        }
 
        private void game_removed (Game game) {
-               var platform = game.get_platform ();
+               var platform = game.platform;
 
                n_games[platform] = n_games[platform] - 1;
 
diff --git a/src/database/database.vala b/src/database/database.vala
index 7f7f0890..5554fb2d 100644
--- a/src/database/database.vala
+++ b/src/database/database.vala
@@ -197,7 +197,7 @@ private class Games.Database : Object {
                var uid = game.uid;
                var uri = game.uri.to_string ();
                var title = game.name;
-               var platform = game.get_platform ().get_id ();
+               var platform = game.platform.get_id ();
                var media_set = serialize_media_set (game);
 
                // TODO transaction
diff --git a/src/retro/retro-runner.vala b/src/retro/retro-runner.vala
index 4e53fb0d..026bdc15 100644
--- a/src/retro/retro-runner.vala
+++ b/src/retro/retro-runner.vala
@@ -143,7 +143,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 (game.uid, game.get_platform (), get_core_id 
());
+               game_savestates = Savestate.get_game_savestates (game.uid, game.platform, get_core_id ());
                if (game_savestates.length != 0)
                        latest_savestate = game_savestates[0];
 
@@ -158,7 +158,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 (game.get_platform (), get_core_id 
());
+                       tmp_live_savestate = Savestate.create_empty_in_tmp (game.platform, get_core_id ());
                instantiate_core (tmp_live_savestate.get_save_directory_path ());
 
                // Step 4) Preview the latest savestate --------------------------------
@@ -234,7 +234,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 (game.get_platform (), 
get_core_id ());
+                               tmp_live_savestate = Savestate.create_empty_in_tmp (game.platform, 
get_core_id ());
 
                        instantiate_core (tmp_live_savestate.get_save_directory_path ());
                }
@@ -340,7 +340,7 @@ public class Games.RetroRunner : Object, Runner {
                        }
 
                var platforms_dir = Application.get_platforms_dir ();
-               var platform_id = game.get_platform ().get_id ();
+               var platform_id = game.platform.get_id ();
                core.system_directory = @"$platforms_dir/$platform_id/system";
 
                core.save_directory = save_directory_path;
@@ -575,7 +575,7 @@ public class Games.RetroRunner : Object, Runner {
                var now = new GLib.DateTime.now_local ();
                var creation_time = now.to_string ();
                var game_title = game.name;
-               var platform = game.get_platform ();
+               var platform = game.platform;
                var platform_name = platform.get_name ();
                var platform_id = platform.get_id ();
                if (platform_name == null) {
@@ -597,7 +597,7 @@ public class Games.RetroRunner : Object, Runner {
        }
 
        private string get_unsupported_system_message () {
-               var platform_name = game.get_platform ().get_name ();
+               var platform_name = game.platform.get_name ();
                if (platform_name != null)
                        return _("The system “%s” isn’t supported yet, but full support is planned.").printf 
(platform_name);
 
diff --git a/src/ui/platforms-view.vala b/src/ui/platforms-view.vala
index 30b85f2e..48a25667 100644
--- a/src/ui/platforms-view.vala
+++ b/src/ui/platforms-view.vala
@@ -73,7 +73,7 @@ private class Games.PlatformsView : Gtk.Bin {
                }
 
                foreach (var game in visible_games)
-                       if (game.get_platform () == item.platform)
+                       if (game.platform == item.platform)
                                return true;
 
                return false;
@@ -81,7 +81,7 @@ private class Games.PlatformsView : Gtk.Bin {
 
        private bool filter_game (Game game) {
                if (selected_platform != null &&
-                   selected_platform.get_name () != game.get_platform ().get_name ())
+                   selected_platform.get_name () != game.platform.get_name ())
                        return false;
 
                return true;


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