SharedConstructionSystem.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. using System.Linq;
  2. using Content.Shared.Construction.Components;
  3. using Robust.Shared.Map;
  4. using Robust.Shared.Prototypes;
  5. using static Content.Shared.Interaction.SharedInteractionSystem;
  6. namespace Content.Shared.Construction
  7. {
  8. public abstract class SharedConstructionSystem : EntitySystem
  9. {
  10. [Dependency] private readonly IMapManager _mapManager = default!;
  11. [Dependency] protected readonly IPrototypeManager PrototypeManager = default!;
  12. [Dependency] protected readonly SharedTransformSystem TransformSystem = default!;
  13. /// <summary>
  14. /// Get predicate for construction obstruction checks.
  15. /// </summary>
  16. public Ignored? GetPredicate(bool canBuildInImpassable, MapCoordinates coords)
  17. {
  18. if (!canBuildInImpassable)
  19. return null;
  20. if (!_mapManager.TryFindGridAt(coords, out _, out var grid))
  21. return null;
  22. var ignored = grid.GetAnchoredEntities(coords).ToHashSet();
  23. return e => ignored.Contains(e);
  24. }
  25. public string GetExamineName(GenericPartInfo info)
  26. {
  27. if (info.ExamineName is not null)
  28. return Loc.GetString(info.ExamineName.Value);
  29. return PrototypeManager.Index(info.DefaultPrototype).Name;
  30. }
  31. }
  32. }