Skip to content

Commit 09500f0

Browse files
committed
Implement EnabledToggle for ResoniteModBase IMonkey
1 parent 72006c0 commit 09500f0

2 files changed

Lines changed: 18 additions & 4 deletions

File tree

MonkeyLoader.GamePacks.ResoniteModLoader/MonkeyLoader.GamePacks.ResoniteModLoader.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
</ItemGroup>
3535

3636
<ItemGroup>
37-
<PackageReference Include="MonkeyLoader.GamePacks.Resonite" Version="0.20.0-beta" GeneratePathProperty="true" />
37+
<PackageReference Include="MonkeyLoader.GamePacks.Resonite" Version="0.21.0-beta" GeneratePathProperty="true" />
3838
<PackageReference Include="PolySharp" Version="1.15.0">
3939
<PrivateAssets>all</PrivateAssets>
4040
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

MonkeyLoader.GamePacks.ResoniteModLoader/ResoniteModBase.cs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,32 @@ public abstract class ResoniteModBase : IMonkey
3030
public abstract string Author { get; }
3131

3232
/// <inheritdoc/>
33-
public bool CanBeDisabled => false;
33+
[MemberNotNullWhen(true, nameof(EnabledToggle))]
34+
public bool CanBeDisabled => EnabledToggle is not null;
3435

3536
/// <inheritdoc/>
3637
public Config Config => Mod.Config;
3738

3839
/// <inheritdoc/>
3940
public bool Enabled
4041
{
41-
get => true;
42-
set { }
42+
get => !CanBeDisabled || EnabledToggle.GetValue();
43+
set
44+
{
45+
if (CanBeDisabled)
46+
{
47+
EnabledToggle.SetValue(value, "SetMonkeyEnabled");
48+
return;
49+
}
50+
51+
if (!value)
52+
throw new NotSupportedException("This monkey can't be disabled!");
53+
}
4354
}
4455

56+
/// <inheritdoc/>
57+
public IDefiningConfigKey<bool>? EnabledToggle { get; }
58+
4559
/// <inheritdoc/>
4660
public bool Failed { get; private set; }
4761

0 commit comments

Comments
 (0)