Skip to content

Commit 21f6b7b

Browse files
committed
Tweak ModConfigurationKey Value implementation and comments
1 parent f10fbd8 commit 21f6b7b

2 files changed

Lines changed: 18 additions & 20 deletions

File tree

MonkeyLoader.GamePacks.ResoniteModLoader/ModConfigurationKey.cs

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,23 @@ public class ModConfigurationKey<T> : ModConfigurationKey
118118
/// </summary>
119119
public DefiningConfigKey<T> Key { get; }
120120

121+
/// <summary>
122+
/// Gets or sets the value of this configuration key.
123+
/// </summary>
124+
/// <remarks>
125+
/// When getting, attempts to retrieve the current value assigned to this key, or <c>default(T)</c> if none is set.<br/>
126+
/// When setting, assigns the provided value to this key and notifies any <see cref="ModConfigurationKey.OnChanged">OnChanged</see> subscribers.
127+
/// </remarks>
128+
public T? Value
129+
{
130+
get => Key.GetValue();
131+
132+
// In RML this bypasses the validation check, but ML doesn't let anything set an invalid value.
133+
// A debate could be had as to whether to use the version that throws or not,
134+
// but I'm using the one that throws to not let a mod continue with the old value if the new one is invalid.
135+
set => Key.SetValue(value!);
136+
}
137+
121138
internal override IDefiningConfigKey UntypedKey => Key;
122139

123140
/// <inheritdoc/>
@@ -195,24 +212,5 @@ private void OnKeyChanged(object sender, ConfigKeyChangedEventArgs<T> configKeyC
195212
FireOnChanged(configKeyChangedEventArgs.NewValue);
196213
ModConfiguration.FireConfigurationChangedEvent(this, configKeyChangedEventArgs.Label);
197214
}
198-
199-
/// <summary>
200-
/// Gets or sets the value of this configuration key.
201-
/// <para>
202-
/// When getting, attempts to retrieve the current value assigned to this key, or <c>default(T)</c> if none is set.
203-
/// When setting, assigns the provided value to this key and notifies any <see cref="OnChanged"/> subscribers.
204-
/// </para>
205-
/// </summary>
206-
public T? Value
207-
{
208-
get
209-
{
210-
return (T?)ModConfiguration.GetValue(this);
211-
}
212-
set
213-
{
214-
ModConfiguration.Set(this, value);
215-
}
216-
}
217215
}
218216
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<PackageId>MonkeyLoader.GamePacks.ResoniteModLoader</PackageId>
1212
<Title>ResoniteModLoader</Title>
1313
<Authors>Banane9, Nytra</Authors>
14-
<Version>4.0.0</Version>
14+
<Version>4.0.0.0</Version> <!-- We use the last digit for updates since RML uses the first three -->
1515
<Description>This MonkeyLoader Game Pack for Resonite enables loading ResoniteModLoader mods as MonkeyLoader mods.</Description>
1616
<PackageReadmeFile>README.md</PackageReadmeFile>
1717
<PackageLicenseExpression>LGPL-3.0-or-later</PackageLicenseExpression>

0 commit comments

Comments
 (0)