Skip to content

Commit

Permalink
Make ConfigKeySessionShare more resilient
Browse files Browse the repository at this point in the history
  • Loading branch information
Banane9 committed Aug 2, 2024
1 parent 7a5e1ee commit 5dc542a
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ namespace MonkeyLoader.Resonite.Configuration
/// <typeparam name="T">The type of the config item's value.</typeparam>
public sealed class ConfigKeySessionShare<T> : IConfigKeySessionShare<T>
{
private readonly ConditionalWeakTable<World, object?> _didWorldSetup = new();
private readonly Lazy<string> _sharedId;
private readonly Lazy<string> _variableName;
private IDefiningConfigKey<T> _configKey = null!;
Expand Down Expand Up @@ -134,13 +133,10 @@ private ValueUserOverride<T> GetSharedOverride(World world)
=> GetSharedValue(world).Value.GetUserOverride();

private ValueField<T> GetSharedValue(World world)
=> world.GetSharedComponentOrCreate<ValueField<T>>(SharedId, SetupSharedField, 0, true, true, () => GetSharedConfigSlot(world));
=> world.GetSharedComponentOrCreate<ValueField<T>>(SharedId, SetupSharedField, 0, true, false, () => GetSharedConfigSlot(world));

private void SetupSharedField(ValueField<T> field)
{
if (_didWorldSetup.TryGetValue(field.World, out _))
return;

if (!field.IsDriven && EqualityComparer<T>.Default.Equals(field.Value, default!))
field.Value.Value = DefaultValue!;

Expand All @@ -150,8 +146,6 @@ private void SetupSharedField(ValueField<T> field)
vuo.CreateOverrideOnWrite.Value = true;

field.Value.OnValueChange += SharedValueChanged;

_didWorldSetup.TryAdd(field.World, null);
}

private void SharedValueChanged(SyncField<T> field)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<PackageId>MonkeyLoader.GamePacks.Resonite</PackageId>
<Title>Resonite Game Pack</Title>
<Authors>Banane9, Nytra</Authors>
<Version>0.18.0-beta</Version>
<Version>0.18.0-beta-pre1</Version>
<Description>
This Game Pack for MonkeyLoader provides basic hooks for modding the game Resonite,
which uses FrooxEngine. It provides hooks for the beginning of initialization,
Expand Down

0 comments on commit 5dc542a

Please sign in to comment.