Implementing Recently Played Collection in GNOME Games
In my previous blog post, I talked about how I added a Favorites Collection to Games. Favorites Collection lists all the games that’s marked as favorite. In this post I’ll talk about what went into adding a Recently Played Collection, which helps you get to recently played games more quickly.
Since most of the ground work for supporting non-user collections are already done as part of introducing Favorites Collection, it required much less work to add another non-user collection. For Recently Played collection, the main differences from Favorites Collection in terms of implementation are:
- An option to add the game into Recently Played is not required, since the app knows which games were played at what time
- Games in Recently Played collection should be sorted by the last played date-time, instead of name
Implementing Recently Played Collection
Getting into the details, the first thing to do was to was introduce a
last_played prop to the
Game object. It stores a
DateTime of when a game was last played, and updates it every time a game is played. If the game was never played it’ll stay
The next thing was to modify the database to support this new prop. For that I added a new text column that stores the “stringified”
last_played to the
Games table using the simple migration system I talked about in the last post. I also added queries to fetch the games that were recently played so that it could be loaded, and queries to update the
last_played column, and that was it for database.
I then introduced a
RecentlyPlayedCollection which implements the
Collection interface. The load function fetches the list of recently played games (those games which has a non null
last_played column) and then add them to it’s
GameModel as and when the app discovers those games in the disk. The collection is also added to the
CollectionModel by the
CollectionManager so that its shown in the Collections Page along with Favorites Collection.
The Recently Played Collection is pretty much useless unless its sorted by the
last_played prop. And
Games in the
GameModel were sorted by name. So I implemented sort support to
GameModel, by having a new
sort_type prop for it. It stores a custom
SortType enum which currently contains
BY_LAST_PLAYED. On setting the
sort_type prop, all the compare functions used by the
Sequence of the
GameModel will be set depending on the new sort type, and the
Sequence is sorted again. This sort support can also be used for sorting games in any
FlowBox that are bound with a
So with that most of the collection part of Recently Played Collection was done. Next thing to do was simply update
last_played whenever a game is played. For better compatibility with future when multiple games can be played simultaneously, it was decided that
last_played should be updated when a user quits a game. And so, we now have a functional Recently Played Collection.
Apart from that it was decided that empty non-user collections should be hidden, especially because the collection thumbnails for empty collections gets boring quickly. So a filter was added and set to the
CollectionsMainPage to only show non-empty collections. Since right now only non-user collections exist, the Collections Page could look boring when both of the collections are empty, but that is intended to change when user collections arrive soon. This is where my work is at right now, you can see the relevant MR here. And here are some pictures of the changes:
Last week I got to experience my first GUADEC which is an awesome annual event conducted by GNOME where users, contributors and several developers meet and discuss all things GNOME, Linux, and pretty much anything. I, along with other interns from GSoC and outreach programs, had the opportunity to give an “Intern Lightning Talk” where we talked about our progress and experience at GNOME. It was a very fun experience, and I was also very excited to hear about the latest bleeding edge stuff that’s being worked on.
The work is going great, GUADEC was great. Thanks to my mentor, Alexander Mikhaylenko for all the help, and cheers to all the folks here at GNOME for GUADEC. See you next time!