Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions S1API.Tests/Deliveries/LoadingDockApiTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,20 @@ public void EventsExposeManagedPreviousAndCurrentValues()
GetEvent(nameof(LoadingDock.AcceptingItemsChanged)).EventHandlerType);
}

[Fact]
public void StaticOccupantSubscribersAreTracked()
{
var nativeDock = TestObjectFactory.CreateUninitialized<S1Delivery.LoadingDock>();
var dock = new LoadingDock(nativeDock);
Action<LandVehicle?, LandVehicle?> handler = (_, _) => { };

Assert.False(dock.HasStaticOccupantChangedSubscribers);
dock.StaticOccupantChanged += handler;
Assert.True(dock.HasStaticOccupantChangedSubscribers);
dock.StaticOccupantChanged -= handler;
Assert.False(dock.HasStaticOccupantChangedSubscribers);
}

[Fact]
public void ManagedNotificationsSuppressNoOpsAndIsolateSubscribers()
{
Expand Down
2 changes: 2 additions & 0 deletions S1API/Deliveries/LoadingDock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ public PropertyWrapper? Property
/// </summary>
public event Action<LandVehicle?, LandVehicle?>? StaticOccupantChanged;

internal bool HasStaticOccupantChangedSubscribers => StaticOccupantChanged != null;

/// <summary>
/// Raised after the accepting-items state changes.
/// </summary>
Expand Down
6 changes: 5 additions & 1 deletion S1API/Internal/Deliveries/LoadingDockEventBridge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ internal static void NotifyStaticOccupantChanged(
if (previous == current)
return;

LoadingDock.Wrap(native).NotifyStaticOccupantChanged(
var dock = LoadingDock.Wrap(native);
if (!dock.HasStaticOccupantChangedSubscribers)
return;

dock.NotifyStaticOccupantChanged(
VehicleRegistry.Wrap(previous),
VehicleRegistry.Wrap(current));
}
Expand Down
Loading