Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added src/RomManager/Assets/Icons/Games/favourite.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/RomManager/Assets/Icons/Games/unfavourite.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
63 changes: 63 additions & 0 deletions src/RomManager/Converters/FavouriteToImageConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Globalization;
using Avalonia.Data.Converters;
using Avalonia.Media;
using Avalonia.Media.Imaging;
using Avalonia.Platform;
using RomManager.Core.RegionDetection;

namespace RomManager.Converters;

public sealed class FavouriteToImageConverter : IValueConverter
{
private static readonly ConcurrentDictionary<bool, IImage?> IconCache = new();
private static readonly Dictionary<bool, string> FavouriteToIcon = new()
{
{ true, "favourite" },
{ false, "unfavourite" },

};

Check notice on line 21 in src/RomManager/Converters/FavouriteToImageConverter.cs

View check run for this annotation

codefactor.io / CodeFactor

src/RomManager/Converters/FavouriteToImageConverter.cs#L21

A closing brace should not be preceded by a blank line. (SA1508)
Comment thread
frenchfish marked this conversation as resolved.
Outdated
/* Uri uri;
if (IsFavourite == true)
{
uri = new Uri("avares://RomManager/Assets/Icons/Games/favourite.png");
}
else
{
uri = new Uri("avares://RomManager/Assets/Icons/Games/unfavourite.png");
}

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could use something like this:

var iconName = IsFavourite ? "favourite" : "unfavourite";
var uri = new Uri($"avares://RomManager/Assets/Icons/Games/{iconName}.png");

using var stream = AssetLoader.Open(uri);
FavouritePAth = new Bitmap(stream);*/

Check notice on line 33 in src/RomManager/Converters/FavouriteToImageConverter.cs

View check run for this annotation

codefactor.io / CodeFactor

src/RomManager/Converters/FavouriteToImageConverter.cs#L33

Code should not contain multiple blank lines in a row. (SA1507)



public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
if (value is not bool icon)
{
return null;
}

return IconCache.GetOrAdd(icon, static icon =>
{
var iconName = FavouriteToIcon[icon];
var uri = new Uri($"avares://RomManager/Assets/Icons/Games/{iconName}.png");

if (!AssetLoader.Exists(uri))
{
return null;
}

using var stream = AssetLoader.Open(uri);
return new Bitmap(stream);
});
}

public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
{
throw new NotSupportedException();
}
}
8 changes: 6 additions & 2 deletions src/RomManager/Models/Game.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using Avalonia.Media;
using Avalonia.Media.Imaging;
using Avalonia.Platform;
using CommunityToolkit.Mvvm.ComponentModel;
using RomManager.Core.RegionDetection;
using RomManager.Models.FileTypes;
Expand All @@ -19,12 +21,13 @@
private IEnumerable<IHasFilename> _files = [];

[ObservableProperty] private IImage? _coverArt;
[ObservableProperty] private GameInfo? _info;
[ObservableProperty] private GameInfo? _info ;

[ObservableProperty] private SystemInfo[] _systems;

[ObservableProperty] private Region[] _regions = [Region.Unknown];


public void Load()
{
var art = Files.OfType<CoverArtImage>().FirstOrDefault();
Expand All @@ -32,7 +35,8 @@
{
CoverArt = new Bitmap(art.Filename);
}

Check notice on line 38 in src/RomManager/Models/Game.cs

View check run for this annotation

codefactor.io / CodeFactor

src/RomManager/Models/Game.cs#L38

Code should not contain multiple blank lines in a row. (SA1507)

Systems = Files.OfType<RomFile>().Select(f => f.SystemInfo).ToArray();

// Detect regions from the ROM file
Expand Down
4 changes: 3 additions & 1 deletion src/RomManager/Models/SystemInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ private Game GetGame(PathsConfiguration pathsConfiguration, string file)
GameInfo gameInfo;
if (!GameList.GamesByFilename.TryGetValue(System.IO.Path.GetFileName(file), out gameInfo))
{
gameInfo = new GameInfo { Path = file, Name = System.IO.Path.GetFileNameWithoutExtension(file) };
//DELETE TEST
gameInfo = new GameInfo { Path = file, Name = System.IO.Path.GetFileNameWithoutExtension(file),IsFavorite = false};
// gameInfo = new GameInfo { Path = file, Name = System.IO.Path.GetFileNameWithoutExtension(file) };

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete the test code

}

return new Game
Expand Down
11 changes: 10 additions & 1 deletion src/RomManager/Pages/LibraryPage.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<converters:SystemIconNameToImageConverter x:Key="SystemIconNameToImageConverter" />
<converters:RegionToImageConverter x:Key="RegionToImageConverter" />
<converters:FilterComboBoxItemToTextConverter x:Key="FilterComboBoxItemToTextConverter" />
<converters:FavouriteToImageConverter x:Key="FavouriteToImageConverter" />
</UserControl.Resources>

<Grid RowDefinitions="Auto,Auto,*,Auto" RowSpacing="8">
Expand Down Expand Up @@ -149,11 +150,19 @@
Width="18" HorizontalAlignment="Center" VerticalAlignment="Center"
Height="18"
ToolTip.Tip="{Binding Name}" />

</Border>
</DataTemplate>

</ItemsControl.ItemTemplate>
</ItemsControl>

<!--
<Image Source="{Binding FavouritePAth}"
Width="18" HorizontalAlignment="Right" VerticalAlignment="Top"
Height="18" IsVisible="True" />-->
<Image Source="{Binding Info.IsFavorite ,Converter={StaticResource FavouriteToImageConverter }}"
Width="18" HorizontalAlignment="Right" VerticalAlignment="Top"
Height="18" IsVisible="True" />
<ItemsControl ItemsSource="{Binding Regions}"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Expand Down
2 changes: 2 additions & 0 deletions src/RomManager/ViewModels/LibraryPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
[ObservableProperty] private int _pageCount = 1;
[ObservableProperty] private int _pageSize = 30;
[ObservableProperty] private int _filteredGamesCount;

Check notice on line 30 in src/RomManager/ViewModels/LibraryPageViewModel.cs

View check run for this annotation

codefactor.io / CodeFactor

src/RomManager/ViewModels/LibraryPageViewModel.cs#L30

Code should not contain multiple blank lines in a row. (SA1507)


public LibraryPageViewModel(Core.RomManager romManager, FilenameFilterBuilder filenameFilterBuilder, IOptions<PathsConfiguration> pathsConfiguration)
{
_filenameFilterBuilder = filenameFilterBuilder;
Expand Down