1
0

BoardNodeEntity.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using Content.Server.Construction.Components;
  2. using Content.Shared.Construction;
  3. using Content.Shared.Construction.Components;
  4. using JetBrains.Annotations;
  5. using Robust.Server.Containers;
  6. namespace Content.Server.Construction.NodeEntities;
  7. /// <summary>
  8. /// Works for both <see cref="ComputerBoardComponent"/> and <see cref="MachineBoardComponent"/>
  9. /// because duplicating code just for this is really stinky.
  10. /// </summary>
  11. [UsedImplicitly]
  12. [DataDefinition]
  13. public sealed partial class BoardNodeEntity : IGraphNodeEntity
  14. {
  15. [DataField("container")] public string Container { get; private set; } = string.Empty;
  16. public string? GetId(EntityUid? uid, EntityUid? userUid, GraphNodeEntityArgs args)
  17. {
  18. if (uid == null)
  19. return null;
  20. var containerSystem = args.EntityManager.EntitySysManager.GetEntitySystem<ContainerSystem>();
  21. if (!containerSystem.TryGetContainer(uid.Value, Container, out var container)
  22. || container.ContainedEntities.Count == 0)
  23. return null;
  24. var board = container.ContainedEntities[0];
  25. // There should not be a case where both of these components exist on the same entity...
  26. if (args.EntityManager.TryGetComponent(board, out MachineBoardComponent? machine))
  27. return machine.Prototype;
  28. if(args.EntityManager.TryGetComponent(board, out ComputerBoardComponent? computer))
  29. return computer.Prototype;
  30. return null;
  31. }
  32. }