Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Top Level Groups Enumeration #563

Merged
merged 6 commits into from
Oct 19, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions Mutagen.Bethesda.Core/Extensions/EnumerableExt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ namespace Mutagen.Bethesda;

internal static class EnumerableExt
{
public static IEnumerable<T> WhereNotNull<T>(this IEnumerable<T?> enumer)
Copy link
Member

Choose a reason for hiding this comment

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

Already got an extension like this over in https://github.com/Noggog/CSharpExt/blob/89a5e0918ae8a212b592b890a5b62ca1209f2120/Noggog.CSharpExt/Extensions/EnumerableExt.cs#L257

But I do like the Where__ naming better. Feel free to open a PR over there, and mark the old ones obsolete

{
return enumer.Where(x => x != null).Cast<T>();
}

public static ExtendedList<T> CastExtendedList<T>(this ExtendedList<T> enumer)
{
return enumer;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Collections.Concurrent;
using System.Collections.Immutable;
using System.Reflection;
using Loqui;
using Noggog;

Expand All @@ -8,14 +10,15 @@ public record RecordTypes(Type ClassType, Type GetterType, Type SetterType);

public static class MajorRecordTypeEnumerator
{
private static readonly ConcurrentDictionary<GameCategory, List<RecordTypes>> Registrations = new();
private static readonly ConcurrentDictionary<GameCategory, ImmutableArray<RecordTypes>> MajorRecordRegistrations = new();
private static readonly ConcurrentDictionary<GameCategory, ImmutableArray<RecordTypes>> TopLevelMajorRecordRegistrations = new();

static MajorRecordTypeEnumerator()
{
Warmup.Init();
}

private static List<RecordTypes> GetRegistrations(GameCategory cat)
private static ImmutableArray<RecordTypes> GetMajorRecordRegistrations(GameCategory cat)
{
var categoryString = Enums<GameCategory>.ToStringFast((int) cat);

Expand All @@ -25,11 +28,29 @@ private static List<RecordTypes> GetRegistrations(GameCategory cat)
&& x.ClassType.Namespace.Contains(categoryString, StringComparison.Ordinal)
&& x.GetterType.IsAssignableTo(typeof(IMajorRecordGetter)))
.Select(x => new RecordTypes(x.ClassType, x.GetterType, x.SetterType))
.ToList();
.ToImmutableArray();
}

public static IEnumerable<RecordTypes> GetMajorRecordTypesFor(GameCategory cat)
{
return Registrations.GetOrAdd(cat, () => GetRegistrations(cat));
return MajorRecordRegistrations.GetOrAdd(cat, () => GetMajorRecordRegistrations(cat));
}

private static ImmutableArray<RecordTypes> GetTopLevelMajorRecordRegistrations(GameCategory cat)
{
return cat.ToModRegistration().GetterType
.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly)
.Where(p => p.PropertyType.IsGenericType && p.PropertyType.IsAssignableTo(typeof(IGroupGetter)))
.Select(p =>
LoquiRegistration.StaticRegister.Registrations
.FirstOrDefault(r => r.GetterType == p.PropertyType.GetGenericArguments()[0]))
.WhereNotNull()
.Select(r => new RecordTypes(r.ClassType, r.GetterType, r.SetterType))
.ToImmutableArray();
}

public static IEnumerable<RecordTypes> GetTopLevelMajorRecordTypesFor(GameCategory cat)
{
return TopLevelMajorRecordRegistrations.GetOrAdd(cat, () => GetTopLevelMajorRecordRegistrations(cat));
}
}
10 changes: 10 additions & 0 deletions docs/Big-Cheat-Sheet.md
Original file line number Diff line number Diff line change
Expand Up @@ -312,4 +312,14 @@ foreach (var recTypes in MajorRecordTypeEnumerator.GetMajorRecordTypesFor(GameCa
Console.WriteLine($"Setter: {recTypes.SetterType}");
Console.WriteLine($"Class: {recTypes.ClassType}");
}
```

## Find all Major Record Types for Top Level Groups
```cs
foreach (var recTypes in MajorRecordTypeEnumerator.GetTopLevelMajorRecordTypesFor(GameCategory.Skyrim))
{
Console.WriteLine($"Getter: {recTypes.GetterType}");
Console.WriteLine($"Setter: {recTypes.SetterType}");
Console.WriteLine($"Class: {recTypes.ClassType}");
}
```
5 changes: 3 additions & 2 deletions docs/Contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,12 @@ This step downloads (clones) the fork you just made to your local computer.
![Cloning](images/cloning.png){ width="350" }

#### Installing MkDocs
This is the documentation system Mutagen uses, so you have to install it so it can display the docs as you edit them.
This is the documentation system Mutagen uses, so you have to install it, along with the GLightbox plugin, so it can display the docs as you edit them.

[Installing Material for MkDocs](https://squidfunk.github.io/mkdocs-material/getting-started/)
[Installing MkDocs GLightbox](https://blueswen.github.io/mkdocs-glightbox/)

TLDR: `pip install mkdocs-material` in a command line
TLDR: `pip install mkdocs-material mkdocs-glightbox` in a command line

#### Running MkDocs
Running `mkdocs serve` on your cloned Mutagen repository
Expand Down
39 changes: 36 additions & 3 deletions docs/stylesheets/extra.css
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,39 @@
}

.md-grid {
width: 100%;
max-width: 1900px;
}
width: 100%;
max-width: 1900px;
}

.tabbed-labels > label {
background-color: var(--md-typeset-mark-color);
}

/* the source theme uses this for selected tabs and goes out to 19 as well */
.tabbed-alternate input:nth-child(1):checked ~ .tabbed-labels > :nth-child(1),
.tabbed-alternate input:nth-child(2):checked ~ .tabbed-labels > :nth-child(2),
.tabbed-alternate input:nth-child(3):checked ~ .tabbed-labels > :nth-child(3),
.tabbed-alternate input:nth-child(4):checked ~ .tabbed-labels > :nth-child(4),
.tabbed-alternate input:nth-child(5):checked ~ .tabbed-labels > :nth-child(5),
.tabbed-alternate input:nth-child(6):checked ~ .tabbed-labels > :nth-child(6),
.tabbed-alternate input:nth-child(7):checked ~ .tabbed-labels > :nth-child(7),
.tabbed-alternate input:nth-child(8):checked ~ .tabbed-labels > :nth-child(8),
.tabbed-alternate input:nth-child(9):checked ~ .tabbed-labels > :nth-child(9)
{
background-color: var(--md-primary-fg-color);
box-shadow: var(--md-shadow-z3);
}

.md-typeset .tabbed-alternate input:nth-child(1):checked ~ .tabbed-labels > :nth-child(1),
.md-typeset .tabbed-alternate input:nth-child(2):checked ~ .tabbed-labels > :nth-child(2),
.md-typeset .tabbed-alternate input:nth-child(3):checked ~ .tabbed-labels > :nth-child(3),
.md-typeset .tabbed-alternate input:nth-child(4):checked ~ .tabbed-labels > :nth-child(4),
.md-typeset .tabbed-alternate input:nth-child(5):checked ~ .tabbed-labels > :nth-child(5),
.md-typeset .tabbed-alternate input:nth-child(6):checked ~ .tabbed-labels > :nth-child(6),
.md-typeset .tabbed-alternate input:nth-child(7):checked ~ .tabbed-labels > :nth-child(7),
.md-typeset .tabbed-alternate input:nth-child(8):checked ~ .tabbed-labels > :nth-child(8),
.md-typeset .tabbed-alternate input:nth-child(9):checked ~ .tabbed-labels > :nth-child(9)
{
color: var(--md-accent-fg-color);
}

Loading