Add platforms to metadata search results
This commit is contained in:
parent
819cb28d17
commit
113d8bd080
4 changed files with 53 additions and 8 deletions
|
|
@ -29,14 +29,20 @@
|
|||
SelectionMode="Single">
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<Grid ColumnDefinitions="*,Auto" Margin="4,6">
|
||||
<Grid ColumnDefinitions="*,Auto,Auto" Margin="4,6">
|
||||
<TextBlock Text="{Binding Title}" FontSize="14"
|
||||
Foreground="{DynamicResource TextPrimaryBrush}"
|
||||
VerticalAlignment="Center" />
|
||||
<TextBlock Grid.Column="1"
|
||||
Text="{Binding ReleasedOn, StringFormat='{}{0:yyyy-MM-dd}'}"
|
||||
Text="{Binding Platforms}"
|
||||
Opacity="0.4" FontSize="12"
|
||||
VerticalAlignment="Center" Margin="12,0"
|
||||
IsVisible="{Binding HasPlatforms}" />
|
||||
<TextBlock Grid.Column="2"
|
||||
Text="{Binding ReleasedOn}"
|
||||
Opacity="0.5" FontSize="12"
|
||||
VerticalAlignment="Center" />
|
||||
VerticalAlignment="Center"
|
||||
IsVisible="{Binding HasReleasedOn}" />
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Input;
|
||||
using Avalonia.Interactivity;
|
||||
|
|
@ -12,7 +13,7 @@ namespace LANCommander.Packager.Views;
|
|||
public partial class MetadataSearchDialog : Window
|
||||
{
|
||||
private readonly MetadataClient _metadataClient;
|
||||
private readonly ObservableCollection<Game> _results = new();
|
||||
private readonly ObservableCollection<SearchResultItem> _results = new();
|
||||
private readonly List<MetadataSearchResult> _rawResults = new();
|
||||
private string? _selectedProvider;
|
||||
private int _offset;
|
||||
|
|
@ -128,7 +129,7 @@ public partial class MetadataSearchDialog : Window
|
|||
foreach (var result in results.Results)
|
||||
{
|
||||
_rawResults.Add(result);
|
||||
_results.Add(result.Data);
|
||||
_results.Add(new SearchResultItem(result.Data));
|
||||
}
|
||||
|
||||
_hasMore = results.More;
|
||||
|
|
@ -177,7 +178,7 @@ public partial class MetadataSearchDialog : Window
|
|||
foreach (var result in results.Results)
|
||||
{
|
||||
_rawResults.Add(result);
|
||||
_results.Add(result.Data);
|
||||
_results.Add(new SearchResultItem(result.Data));
|
||||
}
|
||||
|
||||
_hasMore = results.More;
|
||||
|
|
@ -222,3 +223,28 @@ public partial class MetadataSearchDialog : Window
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal class SearchResultItem
|
||||
{
|
||||
public string Title { get; }
|
||||
public string? ReleasedOn { get; }
|
||||
public bool HasReleasedOn { get; }
|
||||
public string? Platforms { get; }
|
||||
public bool HasPlatforms { get; }
|
||||
|
||||
public SearchResultItem(Game game)
|
||||
{
|
||||
Title = game.Title ?? string.Empty;
|
||||
|
||||
HasReleasedOn = game.ReleasedOn != default;
|
||||
ReleasedOn = HasReleasedOn ? game.ReleasedOn.ToString("yyyy-MM-dd") : null;
|
||||
|
||||
var platformNames = game.Platforms?
|
||||
.Select(p => p.Name)
|
||||
.Where(n => !string.IsNullOrWhiteSpace(n))
|
||||
.ToList();
|
||||
|
||||
HasPlatforms = platformNames != null && platformNames.Count > 0;
|
||||
Platforms = HasPlatforms ? string.Join(", ", platformNames!) : null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ public class IgdbMetadataProvider(
|
|||
fields.Add("involved_companies.developer");
|
||||
fields.Add("involved_companies.publisher");
|
||||
fields.Add("involved_companies.company.name");
|
||||
fields.Add("platforms.*");
|
||||
|
||||
var sb = new StringBuilder();
|
||||
|
||||
|
|
@ -114,6 +115,13 @@ public class IgdbMetadataProvider(
|
|||
};
|
||||
}
|
||||
|
||||
if (igdbGame.Platforms?.Values?.Any() ?? false)
|
||||
{
|
||||
game.Platforms = igdbGame.Platforms.Values
|
||||
.Select(p => new Platform { Name = p.Name })
|
||||
.ToList();
|
||||
}
|
||||
|
||||
if (igdbGame.Genres?.Values?.Any() ?? false)
|
||||
{
|
||||
game.Genres = igdbGame.Genres.Values
|
||||
|
|
|
|||
|
|
@ -38,8 +38,13 @@
|
|||
|
||||
<Selection Key="@context.Id" Type="SelectionType.Radio"/>
|
||||
<PropertyColumn Property="g => g.Data.Title" Title="Title"/>
|
||||
<PropertyColumn Property="g => g.Data.ReleasedOn" Format="MM/dd/yyyy" Title="Released"/>
|
||||
<PropertyColumn Property="g => g.Data.Developers">
|
||||
<PropertyColumn Property="g => g.Data.ReleasedOn" Title="Released">
|
||||
@(context.Data.ReleasedOn != default ? context.Data.ReleasedOn.ToString("MM/dd/yyyy") : "—")
|
||||
</PropertyColumn>
|
||||
<PropertyColumn Property="g => g.Data.Platforms" Title="Platforms">
|
||||
@string.Join(", ", context.Data.Platforms?.Select(p => p.Name) ?? [])
|
||||
</PropertyColumn>
|
||||
<PropertyColumn Property="g => g.Data.Developers" Title="Developers">
|
||||
@string.Join(", ", context.Data.Developers?.Select(d => d.Name) ?? [])
|
||||
</PropertyColumn>
|
||||
</Table>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue