AppearanceChange.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using Content.Server.Construction.Components;
  2. using Content.Shared.Construction;
  3. using JetBrains.Annotations;
  4. using Robust.Server.GameObjects;
  5. namespace Content.Server.Construction.Completions;
  6. [UsedImplicitly]
  7. [DataDefinition]
  8. public sealed partial class AppearanceChange : IGraphAction
  9. {
  10. /// <summary>
  11. /// The appearance key to use.
  12. /// </summary>
  13. [DataField("key")]
  14. public Enum Key = ConstructionVisuals.Key;
  15. /// <summary>
  16. /// The enum data to set. If not specified, will set the data to the name of the current edges' target node
  17. /// (or the current node). This is because appearance changes are usually associated with reaching a new node.
  18. /// </summary>
  19. [DataField("data")]
  20. public Enum? Data;
  21. public void PerformAction(EntityUid uid, EntityUid? userUid, IEntityManager entityManager)
  22. {
  23. if (!entityManager.TryGetComponent(uid, out AppearanceComponent? appearance))
  24. return;
  25. if (Data != null)
  26. {
  27. entityManager.System<AppearanceSystem>().SetData(uid, Key, Data, appearance);
  28. return;
  29. }
  30. var (node, edge) = entityManager.System<ConstructionSystem>().GetCurrentNodeAndEdge(uid);
  31. var nodeName = edge?.Target ?? node?.Name;
  32. if (nodeName != null)
  33. entityManager.System<AppearanceSystem>().SetData(uid, Key, nodeName, appearance);
  34. }
  35. }