Migrate machine linking and resave all maps (#18243)

This commit is contained in:
Leon Friedrich
2023-07-24 12:35:09 +12:00
committed by GitHub
parent e1e717da04
commit 5172188a48
79 changed files with 20743 additions and 70160 deletions

View File

@@ -19,6 +19,7 @@ public abstract class SharedDeviceLinkSystem : EntitySystem
/// <inheritdoc/>
public override void Initialize()
{
SubscribeLocalEvent<DeviceLinkSourceComponent, ComponentInit>(OnInit);
SubscribeLocalEvent<DeviceLinkSourceComponent, ComponentStartup>(OnSourceStartup);
SubscribeLocalEvent<DeviceLinkSinkComponent, ComponentStartup>(OnSinkStartup);
SubscribeLocalEvent<DeviceLinkSourceComponent, ComponentRemove>(OnSourceRemoved);
@@ -27,6 +28,19 @@ public abstract class SharedDeviceLinkSystem : EntitySystem
}
#region Link Validation
private void OnInit(EntityUid uid, DeviceLinkSourceComponent component, ComponentInit args)
{
// Populate the output dictionary.
foreach (var (sinkUid, links) in component.LinkedPorts)
{
foreach (var link in links)
{
component.Outputs.GetOrNew(link.source).Add(sinkUid);
}
}
}
/// <summary>
/// Removes invalid links where the saved sink doesn't exist/have a sink component for example
/// </summary>
@@ -84,7 +98,7 @@ public abstract class SharedDeviceLinkSystem : EntitySystem
List<(string, string)> invalidLinks = new();
foreach (var link in linkedPorts)
{
if (!sinkComponent.Ports.Contains(link.sink) || !(sourceComponent.Outputs.GetValueOrDefault(link.source)?.Contains(sinkUid) ?? false))
if (!sinkComponent.Ports.Contains(link.sink))
invalidLinks.Add(link);
}