Skip to content

Commit

Permalink
Finish autodetection of enabled toggles
Browse files Browse the repository at this point in the history
  • Loading branch information
Banane9 committed Nov 26, 2024
1 parent 803f1b8 commit 59fd909
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,16 @@ internal void ProcessAttributes()
.Do(ProcessField);
}

internal bool TryGetEnabledToggle([NotNullWhen(true)] out DefiningConfigKey<bool>? enabledToggleKey, bool remove = true)
internal bool TryGetEnabledToggle([NotNullWhen(true)] out DefiningConfigKey<bool>? enabledToggleKey, bool makeInternal = true)
{
enabledToggleKey = null;
ModConfigurationKey? enabledToggle = null;
ModConfigurationKey<bool>? enabledToggle = null;

var potentialKeys = _keys.OfType<ModConfigurationKey<bool>>().ToArray();

foreach (var definitiveEnabledToggle in _definitiveEnabledToggles)
{
if (potentialKeys.FirstOrDefault(key => key.Name.Equals(definitiveEnabledToggle, StringComparison.OrdinalIgnoreCase)) is ModConfigurationKey enabledKey)
if (potentialKeys.FirstOrDefault(key => key.Name.Equals(definitiveEnabledToggle, StringComparison.OrdinalIgnoreCase)) is ModConfigurationKey<bool> enabledKey)
{
enabledToggle = enabledKey;
break;
Expand All @@ -122,11 +122,16 @@ internal bool TryGetEnabledToggle([NotNullWhen(true)] out DefiningConfigKey<bool
enabledToggle = potentialKeys[0];
}

enabledToggleKey = (DefiningConfigKey<bool>)enabledToggle.UntypedKey;

if (remove)
if (makeInternal && !enabledToggle.InternalAccessOnly)
{
_keys.Remove(enabledToggle);

enabledToggle = new ModConfigurationKey<bool>(enabledToggle.Name, enabledToggle.Description, () => true, true);
_keys.Add(enabledToggle);
}

enabledToggleKey = enabledToggle.Key;

return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="MonkeyLoader.GamePacks.Resonite" Version="0.21.0-beta" GeneratePathProperty="true" />
<PackageReference Include="MonkeyLoader.GamePacks.Resonite" Version="0.21.2-beta" GeneratePathProperty="true" />
<PackageReference Include="PolySharp" Version="1.15.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
5 changes: 0 additions & 5 deletions MonkeyLoader.GamePacks.ResoniteModLoader/ResoniteMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ public abstract class ResoniteMod : ResoniteModBase
{
private readonly Lazy<ModConfiguration?> _configuration;

/// <summary>
/// Gets the <see cref="MonkeyBase.Enabled">Enabled</see>-Toggle config item for this mod.
/// </summary>
internal DefiningConfigKey<bool>? EnabledToggle { get; private set; }

/// <inheritdoc/>
protected override ModConfiguration? Configuration => _configuration.Value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public bool Enabled
}

/// <inheritdoc/>
public IDefiningConfigKey<bool>? EnabledToggle { get; }
public IDefiningConfigKey<bool>? EnabledToggle { get; protected set; }

/// <inheritdoc/>
public bool Failed { get; private set; }
Expand Down
3 changes: 0 additions & 3 deletions MonkeyLoader.GamePacks.ResoniteModLoader/RmlMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,6 @@ public RmlMod(MonkeyLoader.MonkeyLoader loader, string? location, bool isGamePac

resoniteMod.GetConfiguration();

if (resoniteMod.EnabledToggle is not null)
MonkeyToggles.A

// Add dependencies after refactoring MKL
//foreach (var referencedAssembly in assembly.GetReferencedAssemblies())
// dependencies.Add(referencedAssembly.Name, new DependencyReference())
Expand Down

0 comments on commit 59fd909

Please sign in to comment.