The owner asked for a game's cover and hero art on its page, its colour optionally carried into the page (2026-10-14), and chose: images already on the PC only, a banner with a portrait cover, the colour on by default. D60 - where the artwork comes from: - The image the user chooses in Edit... > Choose image..., copied only once the dialog closed with Save (Cancel leaves nothing) as a PNG no larger than 1200 px a side, to the data folder's covers\game-<id>-<unix ms>.png - a new name for each choice, so a shown file is never written over - and named in games.cover_path relative to the data folder. A cover_path is followed only when it is one of those names, in that folder and never through a junction or a symbolic link: a viewer's copy of a ledger may come from anywhere, and a rooted, share (\\host\...) or .. path is never opened. "Use the store's image" deletes the copy, as removing a game with its sessions does; at start the App deletes the copies no row names (its own folder only, never a viewer's). - Else what the store's app keeps: Steam's appcache\librarycache\<appid>\ (flat, or in hash-named folders - library_600x900[_2x], library_capsule, library_hero, header, library_header; the newest copy wins) and GOG GALAXY's webcache\<user>\gog\<id>\ (WebP). Which store installed the game is asked of the stores' own records as Play asks (StoreRecords.Owning over Steam's and GOG's, kept two minutes), never of the row's platform alone; store ids are digits only. Epic's and itch's apps keep no image files. - Found, decoded (no larger than the page needs, frozen, the twelve latest kept) and coloured on the thread pool: the page's text is there first. Nothing is downloaded; privacy.online_metadata stays reserved. D61 - the band's colour: the artwork's dominant colour (a hue histogram of a 48 px copy, greys and near-black or near-white skipped) over the card's fill, at the strongest opacity - at most 30 % on the dark theme, 22 % on the light - at which every text the header shows still reads: primary and secondary 4.5:1, tertiary 3:1, the pills' and the warning's text 4.5:1 on their fills. Controls/ArtTint follows a theme switch through a resource reference on the band (ApplicationThemeManager.Changed is raised by Apply alone); no tint in high contrast; no text is ever drawn on a picture. Settings > Games: "Show game artwork" (ui.game_art) and "Colour the game page from its artwork" (ui.game_art_tint), both on. Strings in en, vi and ja (ja marked for review). Caught in a render of the page before this commit: the cover's own Style was not based on WPF UI's DefaultImageStyle, so the ui:Image had no template and drew nothing beside a banner that drew. PagesLoadTests.TheGamePagesArtworkIsDrawn and AccessibilityTests.NoStyleOfAWpfUiControlLeavesOutItsTemplate both ran red first; 16_WPFUI_SYNTAX's Gotchas list has it. Docs: Privacy Policy 2.11 (section 1: the images you choose; section 4: the store apps' images, and their records read when a game's page opens) with legal-drift-history, TRADEMARKS, THIRD_PARTY_NOTICES, LIMITATIONS (Game artwork), 08_UI, 16_WPFUI_SYNTAX, 06_DATA_MODEL, 01_ARCHITECTURE, 02_SPEC FR-1.3, 05_DETECTION, 12_BUILD, 20_OPEN_QUESTIONS (Cover art closed), guide 05/07/08, wiki App-UI-development, CHANGELOG. Tests: StoreArtCachesTests (both Steam layouts, the better cover and the newest copy, ids of another shape, nothing there, several GOG users), ColorMathTests (agrees with the tests' own WCAG; the hardest colours keep every pair readable in both themes), GameArtTests (source order, a missing own image, the D59 owning rule, off in Settings reads nothing, a cover_path not ours, a damaged file, records read once), CoverStoreTests (a new name each choice, a non-image leaves nothing, tidying keeps a removed row's image, deleting follows our names only, a covers junction is never followed), EditGameViewModelTests, GameDetailViewModelTests, PagesLoadTests (the band readable in both themes and through a switch; the edit dialog's image row; the artwork drawn). Local gate: ALL GATES PASSED in 282 s; the artwork classes 20 times green. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
104 lines
4.0 KiB
C#
104 lines
4.0 KiB
C#
// SPDX-License-Identifier: GPL-3.0-only
|
|
// Copyright (C) 2026 poli0981 - additional terms under GPLv3 section 7: see NOTICE
|
|
|
|
using System.Windows.Media;
|
|
using System.Windows.Media.Imaging;
|
|
using FluentAssertions;
|
|
using FrameLedger.App.Services;
|
|
using FrameLedger.App.ViewModels;
|
|
using FrameLedger.Application.Persistence;
|
|
|
|
namespace FrameLedger.App.Tests;
|
|
|
|
/// <summary>
|
|
/// beta.23 (owner decision D60): the edit dialog's image row. A picked image is previewed and copied only on Save; going
|
|
/// back to the store's image drops the row's own; a file that is no image is said, and nothing is kept of it.
|
|
/// </summary>
|
|
public sealed class EditGameViewModelTests
|
|
{
|
|
private static readonly ImageSource _store = Frozen();
|
|
private static readonly ImageSource _own = Frozen();
|
|
private static readonly ImageSource _picked = Frozen();
|
|
|
|
private static BitmapSource Frozen()
|
|
{
|
|
BitmapSource image = BitmapSource.Create(2, 3, 96, 96, PixelFormats.Bgra32, null, new byte[24], 8);
|
|
image.Freeze();
|
|
return image;
|
|
}
|
|
|
|
private sealed class Picker(string? path) : IImagePicker
|
|
{
|
|
public int Asked { get; private set; }
|
|
|
|
public string? PickImage()
|
|
{
|
|
Asked++;
|
|
return path;
|
|
}
|
|
}
|
|
|
|
private static EditImage Image(Picker picker, bool own, bool readable = true) =>
|
|
new(own ? _own : _store, own, _store, picker, _ => Task.FromResult(readable ? _picked : null));
|
|
|
|
[Fact]
|
|
public void WithoutAnImageRowTheDialogIsAsItWas()
|
|
{
|
|
var vm = new EditGameViewModel(new GameMetadata { Name = "Alpha", CoverPath = "covers\\game-1-2.png" }, provenanceJson: null);
|
|
|
|
vm.ImageEditable.Should().BeFalse();
|
|
GameEdit edit = vm.Edit();
|
|
edit.PickedImage.Should().BeNull();
|
|
edit.Metadata.CoverPath.Should().Be("covers\\game-1-2.png", "an edit that did not touch the image keeps the row's");
|
|
}
|
|
|
|
[Fact]
|
|
public async Task APickedImageIsPreviewedAndHandedOnOnlyWithTheSave()
|
|
{
|
|
var picker = new Picker(@"C:\Pictures\alpha.png");
|
|
var vm = new EditGameViewModel(new GameMetadata { Name = "Alpha" }, null, Image(picker, own: false));
|
|
vm.ImagePreview.Should().BeSameAs(_store);
|
|
vm.CanUseStoreImage.Should().BeFalse("the store's image is the one shown");
|
|
|
|
await vm.ChooseImageCommand.ExecuteAsync(null);
|
|
|
|
vm.ImagePreview.Should().BeSameAs(_picked);
|
|
vm.PickedImage.Should().Be(@"C:\Pictures\alpha.png");
|
|
vm.CanUseStoreImage.Should().BeTrue();
|
|
vm.Edit().PickedImage.Should().Be(@"C:\Pictures\alpha.png", "Save hands the file on to be copied");
|
|
|
|
vm.UseStoreImageCommand.Execute(null);
|
|
vm.ImagePreview.Should().BeSameAs(_store);
|
|
vm.Edit().PickedImage.Should().BeNull("going back to the store's image drops the pick");
|
|
}
|
|
|
|
[Fact]
|
|
public async Task AFileThatIsNoImageIsSaidAndNotKept()
|
|
{
|
|
var vm = new EditGameViewModel(new GameMetadata { Name = "Alpha" }, null, Image(new Picker(@"C:\notes.txt"), own: false, readable: false));
|
|
|
|
await vm.ChooseImageCommand.ExecuteAsync(null);
|
|
|
|
vm.ImageError.Should().Be(Strings.Art_ImportFailed);
|
|
vm.PickedImage.Should().BeNull();
|
|
vm.ImagePreview.Should().BeSameAs(_store);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task UsingTheStoresImageDropsTheRowsOwnAndACancelledPickChangesNothing()
|
|
{
|
|
var picker = new Picker(null);
|
|
var vm = new EditGameViewModel(new GameMetadata { Name = "Alpha", CoverPath = "covers\\game-1-2.png" }, null, Image(picker, own: true));
|
|
vm.CanUseStoreImage.Should().BeTrue("the user's own image is the one shown");
|
|
|
|
await vm.ChooseImageCommand.ExecuteAsync(null);
|
|
picker.Asked.Should().Be(1);
|
|
vm.ImagePreview.Should().BeSameAs(_own, "a cancelled pick changes nothing");
|
|
|
|
vm.UseStoreImageCommand.Execute(null);
|
|
vm.Edit().Metadata.CoverPath.Should().BeNull("Save drops the row's own image");
|
|
vm.ImagePreview.Should().BeSameAs(_store);
|
|
vm.CanUseStoreImage.Should().BeFalse();
|
|
}
|
|
}
|