0.2.0-dev Download ZIP
124 lines ·6.3 KB Raw
| 1 | using System.Reflection; |
| 2 | using System.Text; |
| 3 | using EvilEngine.Conversion; |
| 4 | using EvilEngine.Formats; |
| 5 | using EvilEngine.Formats.Records; |
| 6 | |
| 7 | namespace EvilEngine.Host.Tests; |
| 8 | |
| 9 | public sealed class MapTagListingTests(ITestOutputHelper output) |
| 10 | { |
| 11 | private static readonly string Installed = typeof(MapTagListingTests).Assembly |
| 12 | .GetCustomAttributes<AssemblyMetadataAttribute>() |
| 13 | .Single(attribute => attribute.Key == "AdapterOutputRoot").Value!; |
| 14 | |
| 15 | private static IReadOnlyList<RecordSet> Sets(string path) |
| 16 | { |
| 17 | var host = new EngineHost(); |
| 18 | host.Adapters.LoadAll([Installed]); |
| 19 | var sets = new List<RecordSet>(); |
| 20 | foreach (var probe in host.Mounts.Probe(path)) |
| 21 | { |
| 22 | var mount = host.Mounts.Open(probe); |
| 23 | host.Conversion.AddNamespace(ContentNamespace.For(mount)); |
| 24 | var result = host.Conversion.Get(ContentKind.Record, ContentId.Create(mount.Id.Game, "records/maps")); |
| 25 | Assert.True(result.Succeeded, string.Join('\n', result.Diagnostics)); |
| 26 | sets.Add(RecordText.Read(mount.Id.Game, Encoding.UTF8.GetString(result.Content!.Data.Span), "set")); |
| 27 | } |
| 28 | |
| 29 | return sets; |
| 30 | } |
| 31 | |
| 32 | private void Print(RecordSet set) |
| 33 | { |
| 34 | foreach (var group in set.Maps.GroupBy(map => $"{map.Category} | {string.Join(", ", map.Tags)}") |
| 35 | .OrderBy(group => group.Key, StringComparer.Ordinal)) |
| 36 | output.WriteLine($"{group.Count(),4} {group.Key} ({string.Join(" ", group.Take(4).Select(map => map.Id.Name))})"); |
| 37 | } |
| 38 | |
| 39 | [Fact] |
| 40 | public void SortsARealGarrysModInstallsMapsAsItsMenuDoes() |
| 41 | { |
| 42 | var path = Environment.GetEnvironmentVariable("EVIL_GMOD"); |
| 43 | Assert.SkipWhen(path is null, "Set EVIL_GMOD to a Garry's Mod install to list its maps."); |
| 44 | var set = Assert.Single(Sets(path!)); |
| 45 | Print(set); |
| 46 | |
| 47 | Assert.Equal(("Sandbox", "mode:sandbox setting:indoor setting:outdoor setting:urban origin:official"), |
| 48 | Sorted(set, "gm_construct")); |
| 49 | Assert.Equal(("Sandbox", "mode:sandbox setting:outdoor setting:abstract origin:official"), |
| 50 | Sorted(set, "gm_flatgrass")); |
| 51 | Assert.Equal(("Sandbox", "mode:sandbox origin:community"), Sorted(set, "gm_bigcity_dusk")); |
| 52 | Assert.Equal(("Half-Life 2", "mode:campaign setting:indoor setting:outdoor setting:urban origin:official"), |
| 53 | Sorted(set, "d1_trainstation_01")); |
| 54 | Assert.Equal(("Half-Life 2: Episode 2", |
| 55 | "mode:campaign setting:outdoor setting:nature setting:underground origin:official"), Sorted(set, "ep2_outland_01")); |
| 56 | Assert.Equal(("Other", "mode:menu setting:outdoor setting:urban setting:nature origin:official"), |
| 57 | Sorted(set, "background01")); |
| 58 | Assert.Equal(("Other", "origin:official"), Sorted(set, "credits")); |
| 59 | Assert.All(set.Maps, map => Assert.Contains(map.Tags, tag => tag.Group == MapTags.Origin)); |
| 60 | Assert.Empty(set.Maps.Where(map => map.Tags.All(tag => tag.Group != MapTags.Setting) && |
| 61 | map.Category is not ("Other" or null) && map.Id.Name != "gm_bigcity_dusk") |
| 62 | .Select(map => map.Id.Name)); |
| 63 | } |
| 64 | |
| 65 | [Fact] |
| 66 | public void SortsBothRealQuakesByTheRereleasesMapDatabaseAndTheMapsOwnEntities() |
| 67 | { |
| 68 | var path = Environment.GetEnvironmentVariable("EVIL_QUAKE"); |
| 69 | Assert.SkipWhen(path is null, "Set EVIL_QUAKE to a Quake install to list its maps."); |
| 70 | var sets = Sets(path!); |
| 71 | Assert.Equal(2, sets.Count); |
| 72 | foreach (var set in sets) |
| 73 | { |
| 74 | output.WriteLine(set.Maps[0].Id.Namespace); |
| 75 | Print(set); |
| 76 | } |
| 77 | |
| 78 | var original = sets.Single(set => set.Maps[0].Id.Namespace == "quake"); |
| 79 | var rerelease = sets.Single(set => set.Maps[0].Id.Namespace == "quake-rerelease"); |
| 80 | Assert.Equal(("id1", "mode:campaign mode:coop origin:official"), Sorted(original, "id1/e1m1")); |
| 81 | Assert.Equal(("id1", "mode:campaign mode:coop origin:official"), Sorted(original, "id1/start")); |
| 82 | Assert.Equal(("id1", "mode:deathmatch origin:official"), Sorted(original, "id1/dm4")); |
| 83 | Assert.Equal(("hipnotic", "mode:campaign mode:coop origin:expansion"), Sorted(original, "hipnotic/hip1m1")); |
| 84 | Assert.Equal(("id1", "mode:campaign mode:coop origin:official"), Sorted(rerelease, "id1/e1m1")); |
| 85 | Assert.Equal(("id1", "mode:deathmatch origin:official"), Sorted(rerelease, "id1/dm7")); |
| 86 | Assert.Equal(("ctf", "mode:team origin:expansion"), Sorted(rerelease, "ctf/ctf1")); |
| 87 | Assert.Equal(("mg1", "mode:coop origin:expansion"), Sorted(rerelease, "mg1/horde1")); |
| 88 | Assert.Equal(("mg3", "mode:deathmatch origin:expansion"), Sorted(rerelease, "mg3/dm1")); |
| 89 | Assert.Equal(("id1", "mode:test origin:official"), Sorted(rerelease, "id1/test/test_door")); |
| 90 | } |
| 91 | |
| 92 | [Fact] |
| 93 | public void TagsARealOvergrowthInstallsCoreLevelsByTheirMod() |
| 94 | { |
| 95 | var path = Environment.GetEnvironmentVariable("EVIL_OVERGROWTH"); |
| 96 | Assert.SkipWhen(path is null, "Set EVIL_OVERGROWTH to an Overgrowth install to list its levels."); |
| 97 | var set = Assert.Single(Sets(path!)); |
| 98 | Print(set); |
| 99 | |
| 100 | Assert.Equal(("Overgrowth Story", "mode:campaign origin:official"), |
| 101 | Sorted(set, "data/levels/og_story/01_slaver_camp_landing")); |
| 102 | Assert.Equal(("Sandbox Levels", "mode:sandbox origin:official"), Sorted(set, "data/levels/challenge/tree_canyon_summer")); |
| 103 | Assert.Equal(("Versus", "mode:deathmatch origin:official"), Sorted(set, "data/levels/project60/22_grass_beach")); |
| 104 | Assert.Equal(("Arena", "mode:arena origin:official"), Sorted(set, "data/levels/arenas/magma_arena")); |
| 105 | } |
| 106 | |
| 107 | [Fact] |
| 108 | public void TagsARealBunkerInstallsMenuMapByItsMainInitAndTheRestAsItsCampaign() |
| 109 | { |
| 110 | var path = Environment.GetEnvironmentVariable("EVIL_BUNKER"); |
| 111 | Assert.SkipWhen(path is null, "Set EVIL_BUNKER to an Amnesia: The Bunker install to list its maps."); |
| 112 | var set = Assert.Single(Sets(path!)); |
| 113 | Print(set); |
| 114 | Assert.Equal((null, "mode:menu origin:official"), Sorted(set, "main_menu")); |
| 115 | Assert.All(set.Maps.Where(map => map.Id.Name != "main_menu"), |
| 116 | map => Assert.Equal("mode:campaign origin:official", string.Join(' ', map.Tags))); |
| 117 | } |
| 118 | |
| 119 | private static (string?, string) Sorted(RecordSet set, string name) |
| 120 | { |
| 121 | var map = set.Maps.Single(map => map.Id.Name == name); |
| 122 | return (map.Category, string.Join(' ', map.Tags)); |
| 123 | } |
| 124 | } |