ShuttleSystem.Console.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using Content.Client.Resources;
  2. using Content.Client.Shuttles.UI;
  3. using Content.Shared.Shuttles.Components;
  4. using Content.Shared.Shuttles.UI.MapObjects;
  5. using Robust.Client.Graphics;
  6. using Robust.Client.ResourceManagement;
  7. using Robust.Shared.Map;
  8. using Robust.Shared.Map.Components;
  9. using Robust.Shared.Physics.Components;
  10. namespace Content.Client.Shuttles.Systems;
  11. public sealed partial class ShuttleSystem
  12. {
  13. [Dependency] private readonly IResourceCache _resource = default!;
  14. /// <summary>
  15. /// Gets the parallax to use for the specified map or uses the fallback if not available.
  16. /// </summary>
  17. public Texture GetTexture(Entity<ShuttleMapParallaxComponent?> entity)
  18. {
  19. if (!Resolve(entity, ref entity.Comp, false))
  20. {
  21. return _resource.GetTexture(ShuttleMapParallaxComponent.FallbackTexture);
  22. }
  23. return _resource.GetTexture(entity.Comp.TexturePath);
  24. }
  25. /// <summary>
  26. /// Gets the map coordinates of a map object.
  27. /// </summary>
  28. public MapCoordinates GetMapCoordinates(IMapObject mapObj)
  29. {
  30. switch (mapObj)
  31. {
  32. case ShuttleBeaconObject beacon:
  33. return XformSystem.ToMapCoordinates(GetCoordinates(beacon.Coordinates));
  34. case ShuttleExclusionObject exclusion:
  35. return XformSystem.ToMapCoordinates(GetCoordinates(exclusion.Coordinates));
  36. case GridMapObject grid:
  37. var gridXform = Transform(grid.Entity);
  38. if (HasComp<MapComponent>(grid.Entity))
  39. {
  40. return new MapCoordinates(gridXform.LocalPosition, gridXform.MapID);
  41. }
  42. Entity<PhysicsComponent?, TransformComponent?> gridEnt = (grid.Entity, null, gridXform);
  43. return new MapCoordinates(Maps.GetGridPosition(gridEnt), gridXform.MapID);
  44. default:
  45. throw new ArgumentOutOfRangeException();
  46. }
  47. }
  48. }