Skip to content

Commit

Permalink
resolve #33, Game Sort Title
Browse files Browse the repository at this point in the history
  • Loading branch information
retropassdev committed Apr 19, 2023
1 parent 04f064b commit da6dedc
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 6 deletions.
41 changes: 35 additions & 6 deletions RetroPass/DataSourceLaunchBox.cs
Expand Up @@ -21,6 +21,7 @@ public class GameLaunchBox : Game
[XmlElement(ElementName = "Developer")] public override string Developer { get; set; }
[XmlElement(ElementName = "Publisher")] public override string Publisher { get; set; }
[XmlElement(ElementName = "Genre")] public override string Genre { get; set; }
[XmlElement(ElementName = "SortTitle")] public override string SortTitle { get; set; }

[XmlIgnore] public override string ApplicationPathFull { get { return Path.GetFullPath(Path.Combine(DataRootFolder, ApplicationPath)); } }

Expand Down Expand Up @@ -284,6 +285,18 @@ public async Task<List<PlaylistLaunchBox>> LoadPlaylistsXmls(StorageFolder dataF
return playlistLaunchBoxList;
}

private void AddGameToSortedDictionary(SortedDictionary<string, Game> sortedGames, Game game)
{
string key = string.IsNullOrEmpty(game.SortTitle) ? game.Title : game.SortTitle;

if (sortedGames.ContainsKey(key))
{
//if the key exists, still show the game, but just append a unique guid so it can be added to a dictionary
key += Guid.NewGuid().ToString();
}
sortedGames.Add(key, game);
}

private void AddToDictionaryList<TKey, TValue>(IDictionary<TKey, List<TValue>> dictionary, TKey key, TValue value)
{
if (!dictionary.ContainsKey(key))
Expand Down Expand Up @@ -391,12 +404,20 @@ public async Task<Playlist> LoadLaunchBoxPlatform(string platformName, Platforms
using (TextReader reader = new StringReader(xmlPlatform))
{
XmlSerializer serializer = new XmlSerializer(typeof(PlaylistPlatformLaunchBox));
PlaylistPlatformLaunchBox platformGames = serializer.Deserialize(reader) as PlaylistPlatformLaunchBox;
playlistTmp.Name = platformName;
PlaylistPlatformLaunchBox platformGames = serializer.Deserialize(reader) as PlaylistPlatformLaunchBox;

SortedDictionary<string, Game> sortedGames = new SortedDictionary<string, Game>();

foreach (var game in platformGames.games)
{
AddGameToSortedDictionary(sortedGames, game);
}

playlistTmp.Name = platformName;

foreach (var gameEntry in sortedGames)
{
var game = gameEntry.Value as GameLaunchBox;
game.DataRootFolder = rootFolder;
game.GamePlatform = platform;

Expand All @@ -416,7 +437,6 @@ public async Task<Playlist> LoadLaunchBoxPlatform(string platformName, Platforms
}
}

playlistTmp.Sort();
playlistTmp.UpdateGamesLandingPage();
Playlists.Add(playlistTmp);
return playlistTmp;
Expand Down Expand Up @@ -497,6 +517,8 @@ public override async Task Load()
playlistTmp = new Playlist();
playlistTmp.Name = playlistLaunchBox._Playlist.Name;

SortedDictionary<string, Game> sortedGames = new SortedDictionary<string, Game>();

foreach (var playlistGameLaunchBox in playlistLaunchBox.PlaylistGames)
{
var gamePlatform = playlistGameLaunchBox.GamePlatform;
Expand All @@ -514,10 +536,17 @@ public override async Task Load()

if (playlistItemPlatform != null)
{
playlistTmp.AddPlaylistItem(playlistItemPlatform.game);
var game = playlistItemPlatform.game;

AddGameToSortedDictionary(sortedGames, game);
}
}

foreach (var gameEntry in sortedGames)
{
playlistTmp.AddPlaylistItem(gameEntry.Value);
}

//show playlist only if there is at least one game
if (string.IsNullOrEmpty(playlistTmp.Name) == false && playlistTmp.PlaylistItems.Count > 0)
{
Expand All @@ -531,6 +560,6 @@ public override async Task Load()
PlaylistImported?.Invoke(playlistTmp);
}
}
}
}
}
}
1 change: 1 addition & 0 deletions RetroPass/Game.cs
Expand Up @@ -33,6 +33,7 @@ public abstract class Game
[XmlIgnore] public virtual string Publisher { get; set; }
[XmlIgnore] public virtual string ReleaseDate { get; set; }
[XmlIgnore] public virtual string Genre { get; set; }
[XmlIgnore] public virtual string SortTitle { get; set; }

BitmapImage bitmapImage = null;

Expand Down

0 comments on commit da6dedc

Please sign in to comment.