Star favourite sceneries in the list

A right click stars or unstars the scenery under it; the starred ones are
gathered in a group on top and marked where they belong. They are kept in
favorites.txt beside the settings, not in eu07.ini.
This commit is contained in:
maj00r
2026-10-04 14:23:16 +02:00
parent be34d48033
commit e0901ae0ab
13 changed files with 223 additions and 6 deletions

View File

@@ -0,0 +1,38 @@
using StarterNG.Application;
using StarterNG.Domain.Sceneries;
using StarterNG.Tests.Fakes;
namespace StarterNG.Tests;
public class FavoriteSceneriesTests
{
private const string FavoritesPath = "/home/user/.config/MaSzyna/favorites.txt";
[Fact]
public void A_starred_scenery_stays_starred_after_a_restart()
{
var installation = new TestInstallation(new InMemoryFileSystem()
.WithLegacyFile(TestInstallation.At("scenery", "td.scn"), "//$n Testowa"));
var scenery = Assert.Single(installation.Sceneries.LoadAll());
new FavoriteSceneries(installation.Files, installation.Log, FavoritesPath).Toggle(scenery);
var restarted = new FavoriteSceneries(installation.Files, installation.Log, FavoritesPath);
Assert.True(restarted.Contains(scenery));
Assert.Equal("td.scn", installation.Files.ReadAllText(FavoritesPath));
}
[Fact]
public void Starring_again_unstars()
{
var installation = new TestInstallation(new InMemoryFileSystem()
.WithLegacyFile(TestInstallation.At("scenery", "td.scn"), "//$n Testowa"));
var scenery = Assert.Single(installation.Sceneries.LoadAll());
var favorites = new FavoriteSceneries(installation.Files, installation.Log, FavoritesPath);
favorites.Toggle(scenery);
favorites.Toggle(scenery);
Assert.False(favorites.Contains(scenery));
}
}

View File

@@ -80,6 +80,36 @@ public class SceneryTreeBuilderTests
return (new SceneryTreeBuilder(new SceneryTranslations(files, installation.Log)), sceneries);
}
[Fact]
public void Starred_sceneries_are_gathered_on_top_and_starred_where_they_belong()
{
var (builder, sceneries) = Build("//$l Śląsk", "//$l Śląsk", "//$n Aaa luzem");
string starred = SceneryTreeBuilder.Star + sceneries.Single(scenery => scenery.Path.EndsWith("s1.scn")).DisplayName;
string plain = sceneries.Single(scenery => scenery.Path.EndsWith("s0.scn")).DisplayName;
var nodes = builder.Build(sceneries, includeArchival: true, "en",
scenery => scenery.Path.EndsWith("s1.scn"), "Ulubione");
var top = nodes[0];
Assert.True(top.IsGroup);
Assert.Equal(SceneryTreeBuilder.Star + "Ulubione", top.Label);
Assert.Equal(starred, Assert.Single(top.Children).Label);
var group = Assert.Single(nodes, node => node.Label == "Śląsk");
Assert.Contains(group.Children, node => node.Label == starred);
Assert.Contains(group.Children, node => node.Label == plain);
}
[Fact]
public void Without_favourites_there_is_no_favourites_group()
{
var (builder, sceneries) = Build("//$n Bytom");
var nodes = builder.Build(sceneries, includeArchival: true, "en", _ => false, "Ulubione");
Assert.DoesNotContain(nodes, node => node.Label.StartsWith(SceneryTreeBuilder.Star));
}
[Fact]
public void Scenarios_declaring_a_group_are_gathered_under_it()
{