Skip to content

Commit

Permalink
Fix Session Share components being possible to initialize multiple ti…
Browse files Browse the repository at this point in the history
…mes and not write their value upon loading into a world where the share components exist
  • Loading branch information
Banane9 committed Dec 20, 2024
1 parent eb25262 commit 59de92f
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ public IEnumerable<User> GetSharingUsers(World world)

void IComponent<IDefiningConfigKey<TKey>>.Initialize(IDefiningConfigKey<TKey> entity)
{
if (ConfigKey is not null)
throw new InvalidOperationException($"This shared config item can't be initialized with key [{entity.Id}], as it has already been initialized with key [{ConfigKey.Id}]");

ConfigKey = entity;
entity.Changed += ValueChanged;

Expand All @@ -174,7 +177,7 @@ void IComponent<IDefiningConfigKey<TKey>>.Initialize(IDefiningConfigKey<TKey> en

/// <inheritdoc/>
public void SetupOverride(World world)
=> world.RunSynchronously(() => GetSharedValue(world));
=> world.RunSynchronously(() => GetSharedValue(world, true));

/// <inheritdoc/>
public void ShutdownOverride(World world)
Expand All @@ -183,8 +186,8 @@ public void ShutdownOverride(World world)
private ValueUserOverride<TShared> GetSharedOverride(World world)
=> GetSharedValue(world).Value.GetUserOverride();

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

private void SetupSharedField(ValueField<TShared> field)
{
Expand Down

0 comments on commit 59de92f

Please sign in to comment.