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

Makes the Favorites and Recents monkeys togglable #6

Merged
merged 1 commit into from
Jul 7, 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
4 changes: 2 additions & 2 deletions ComponentSelectorAdditions/ComponentSelectorAdditions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="MonkeyLoader" Version="0.17.4-beta" />
<PackageReference Include="MonkeyLoader.GamePacks.Resonite" Version="0.16.4-beta" />
<PackageReference Include="MonkeyLoader" Version="0.18.0-beta" />
<PackageReference Include="MonkeyLoader.GamePacks.Resonite" Version="0.16.5-beta" />
<PackageReference Include="PolySharp" Version="1.14.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
47 changes: 37 additions & 10 deletions ComponentSelectorAdditions/FavoritesCategories.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,16 @@ internal sealed class FavoritesCategories : ConfiguredResoniteMonkey<FavoritesCa
private CategoryNode<Type> _protoFluxRootCategory = null!;
private CategoryNode<Type> _rootCategory = null!;

public override bool CanBeDisabled => true;
public int Priority => HarmonyLib.Priority.Normal;

public bool SkipCanceled => true;

public void Handle(EnumerateComponentsEvent eventData)
{
if (!Enabled)
return;

if (eventData.RootCategory != _favoritesCategory && eventData.RootCategory != _protoFluxFavoritesCategory)
{
if (ConfigSection.SortFavoriteComponentsToTop)
Expand All @@ -59,6 +63,9 @@ public void Handle(EnumerateComponentsEvent eventData)

public void Handle(EnumerateCategoriesEvent eventData)
{
if (!Enabled)
return;

if (eventData.RootCategory == _rootCategory || eventData.RootCategory == _protoFluxRootCategory)
{
if (eventData.RootCategory == _rootCategory)
Expand Down Expand Up @@ -96,6 +103,9 @@ public void Handle(EnumerateCategoriesEvent eventData)

public void Handle(PostProcessButtonsEvent eventData)
{
if (!Enabled)
return;

if (eventData.Path.IsSelectorRoot)
return;

Expand All @@ -118,6 +128,9 @@ public void Handle(PostProcessButtonsEvent eventData)

public void Handle(EnumerateConcreteGenericsEvent eventData)
{
if (!Enabled)
return;

var concreteGenerics = ConfigSection.Components
.Concat(ConfigSection.ProtoFluxNodes)
.Where(type => type is not null && type.IsGenericType && !type.ContainsGenericParameters && type.GetGenericTypeDefinition() == eventData.Component);
Expand All @@ -128,13 +141,13 @@ public void Handle(EnumerateConcreteGenericsEvent eventData)

protected override IEnumerable<IFeaturePatch> GetFeaturePatches() => Enumerable.Empty<IFeaturePatch>();

protected override void OnDisabled() => RemoveCategories();

protected override void OnEnabled() => AddCategories();

protected override bool OnEngineReady()
{
_favoritesCategory = WorkerInitializer.ComponentLibrary.GetSubcategory(FavoritesPath);
SearchConfig.Instance.AddExcludedCategory(FavoritesPath);

_protoFluxFavoritesCategory = WorkerInitializer.ComponentLibrary.GetSubcategory(ProtoFluxFavoritesPath);
SearchConfig.Instance.AddExcludedCategory(ProtoFluxFavoritesPath);
AddCategories();

_rootCategory = WorkerInitializer.ComponentLibrary;
_protoFluxRootCategory = WorkerInitializer.ComponentLibrary.GetSubcategory(ProtoFluxPath);
Expand All @@ -156,11 +169,7 @@ protected override bool OnShutdown(bool applicationExiting)
Mod.UnregisterEventHandler<EnumerateConcreteGenericsEvent>(this);
Mod.UnregisterEventHandler<PostProcessButtonsEvent>(this);

_rootCategory._subcategories.Remove("Favorites");
SearchConfig.Instance.RemoveExcludedCategory(FavoritesPath);

_protoFluxRootCategory._subcategories.Remove("Favorites");
SearchConfig.Instance.RemoveExcludedCategory(ProtoFluxFavoritesPath);
RemoveCategories();
}

return base.OnShutdown(applicationExiting);
Expand Down Expand Up @@ -213,6 +222,15 @@ private static bool ToggleHashSetContains<T>(ISet<T> set, T value)
return false;
}

private void AddCategories()
{
_favoritesCategory = WorkerInitializer.ComponentLibrary.GetSubcategory(FavoritesPath);
SearchConfig.Instance.AddExcludedCategory(FavoritesPath);

_protoFluxFavoritesCategory = WorkerInitializer.ComponentLibrary.GetSubcategory(ProtoFluxFavoritesPath);
SearchConfig.Instance.AddExcludedCategory(ProtoFluxFavoritesPath);
}

private bool IsFavoriteCategory(string name)
=> ConfigSection.Categories.Contains(name);

Expand All @@ -225,6 +243,15 @@ private bool IsFavoriteProtoFluxNode(string name)
private bool IsProtoFluxFavoriteCategory(string name)
=> ConfigSection.ProtoFluxCategories.Contains(name);

private void RemoveCategories()
{
_rootCategory._subcategories.Remove("Favorites");
SearchConfig.Instance.RemoveExcludedCategory(FavoritesPath);

_protoFluxRootCategory._subcategories.Remove("Favorites");
SearchConfig.Instance.RemoveExcludedCategory(ProtoFluxFavoritesPath);
}

private bool ToggleFavoriteCategory(string name)
=> ToggleHashSetContains(ConfigSection.Categories, name);

Expand Down
45 changes: 35 additions & 10 deletions ComponentSelectorAdditions/RecentsCategories.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,17 @@ internal sealed class RecentsCategories : ConfiguredResoniteMonkey<RecentsCatego
private CategoryNode<Type> _recentsCategory = null!;
private CategoryNode<Type> _rootCategory = null!;

public override bool CanBeDisabled => true;

public int Priority => HarmonyLib.Priority.Normal;

public bool SkipCanceled => true;

public void Handle(EnumerateComponentsEvent eventData)
{
if (!Enabled)
return;

if (eventData.RootCategory != _recentsCategory && eventData.RootCategory != _protoFluxRecentsCategory)
return;

Expand All @@ -51,6 +56,9 @@ public void Handle(EnumerateComponentsEvent eventData)

public void Handle(EnumerateCategoriesEvent eventData)
{
if (!Enabled)
return;

if (eventData.RootCategory == _rootCategory)
eventData.AddItem(_recentsCategory, -1000, true);
else if (eventData.RootCategory == _protoFluxRootCategory)
Expand All @@ -59,6 +67,9 @@ public void Handle(EnumerateCategoriesEvent eventData)

public void Handle(EnumerateConcreteGenericsEvent eventData)
{
if (!Enabled)
return;

var concreteGenerics = ConfigSection.Components
.Concat(ConfigSection.ProtoFluxNodes)
.Where(type => type is not null && type.IsGenericType && !type.ContainsGenericParameters && type.GetGenericTypeDefinition() == eventData.Component);
Expand All @@ -69,13 +80,13 @@ public void Handle(EnumerateConcreteGenericsEvent eventData)

protected override IEnumerable<IFeaturePatch> GetFeaturePatches() => Enumerable.Empty<IFeaturePatch>();

protected override void OnDisabled() => RemoveCategories();

protected override void OnEnabled() => AddCategories();

protected override bool OnEngineReady()
{
_recentsCategory = WorkerInitializer.ComponentLibrary.GetSubcategory(RecentsPath);
SearchConfig.Instance.AddExcludedCategory(RecentsPath);

_protoFluxRecentsCategory = WorkerInitializer.ComponentLibrary.GetSubcategory(ProtoFluxRecentsPath);
SearchConfig.Instance.AddExcludedCategory(ProtoFluxRecentsPath);
AddCategories();

_rootCategory = WorkerInitializer.ComponentLibrary;
_protoFluxRootCategory = WorkerInitializer.ComponentLibrary.GetSubcategory(ProtoFluxPath);
Expand All @@ -95,11 +106,7 @@ protected override bool OnShutdown(bool applicationExiting)
Mod.UnregisterEventHandler<EnumerateComponentsEvent>(this);
Mod.UnregisterEventHandler<EnumerateConcreteGenericsEvent>(this);

_rootCategory._subcategories.Remove("Recents");
SearchConfig.Instance.RemoveExcludedCategory(RecentsPath);

_protoFluxRootCategory._subcategories.Remove("Recents");
SearchConfig.Instance.RemoveExcludedCategory(ProtoFluxRecentsPath);
RemoveCategories();
}

return base.OnShutdown(applicationExiting);
Expand Down Expand Up @@ -156,5 +163,23 @@ private static void UpdateRecents(List<Type> recents, Type type)
if (recents.Count > ConfigSection.RecentCap)
recents.RemoveRange(0, recents.Count - ConfigSection.RecentCap);
}

private void AddCategories()
{
_recentsCategory = WorkerInitializer.ComponentLibrary.GetSubcategory(RecentsPath);
SearchConfig.Instance.AddExcludedCategory(RecentsPath);

_protoFluxRecentsCategory = WorkerInitializer.ComponentLibrary.GetSubcategory(ProtoFluxRecentsPath);
SearchConfig.Instance.AddExcludedCategory(ProtoFluxRecentsPath);
}

private void RemoveCategories()
{
_rootCategory._subcategories.Remove("Recents");
SearchConfig.Instance.RemoveExcludedCategory(RecentsPath);

_protoFluxRootCategory._subcategories.Remove("Recents");
SearchConfig.Instance.RemoveExcludedCategory(ProtoFluxRecentsPath);
}
}
}
Loading