Skip to content

Commit

Permalink
feat: module toggle menu
Browse files Browse the repository at this point in the history
  • Loading branch information
Clazex committed Oct 24, 2021
1 parent 1248607 commit ebf97fb
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
3 changes: 2 additions & 1 deletion GodSeekerPlus/GodSeekerPlus.csproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<AssemblyTitle>GodSeekerPlus</AssemblyTitle>
<Version>0.6.0</Version>
<Version>0.7.0</Version>
<Description>A Hollow Knight mod to enhance your Godhome experience</Description>
<Authors>Clazex</Authors>
<Copyright>Copyright © 2021 Clazex</Copyright>

<TargetFramework>net472</TargetFramework>
Expand Down
32 changes: 32 additions & 0 deletions GodSeekerPlus/Menu.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System.Collections.Generic;
using System.Linq;
using GodSeekerPlus.Util;
using Modding;
using static Modding.IMenuMod;

namespace GodSeekerPlus {
public sealed partial class GodSeekerPlus : IMenuMod {
bool IMenuMod.ToggleButtonInsideMenu => false;

List<MenuEntry> IMenuMod.GetMenuData(MenuEntry? _) {
string[] states = {
Language.Language.Get("MOH_OFF", "MainMenu"),
Language.Language.Get("MOH_ON", "MainMenu")
};

return ModuleHelper
.GetToggleableModuleNames()
.Map<string, MenuEntry>(name => new(
name,
states,
"",
(val) => {
Instance.GlobalSettings.modules[name] = val != 0;
moduleManager.Modules[name].Update();
},
() => Instance.GlobalSettings.modules[name] ? 1 : 0
))
.ToList();
}
}
}
3 changes: 2 additions & 1 deletion GodSeekerPlus/Util/ModuleHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ internal static IEnumerable<Type> FindModules() => Assembly
.Filter(HasModuleAttribute)
.Filter(HasDefaultConstructor);

internal static IEnumerable<string> GetModuleNames() => FindModules()
internal static IEnumerable<string> GetToggleableModuleNames() => FindModules()
.Filter(type => type.GetCustomAttribute<ModuleAttribute>().toggleable)
.Map(type => type.Name);

internal static Dictionary<string, bool> GetDefaultModuleStateDict() => FindModules()
Expand Down

0 comments on commit ebf97fb

Please sign in to comment.