RoofSystem.cs 998 B

123456789101112131415161718192021222324252627282930313233
  1. using Content.Server.Light.Components;
  2. using Content.Shared.Light.EntitySystems;
  3. using Robust.Shared.Map.Components;
  4. namespace Content.Server.Light.EntitySystems;
  5. /// <inheritdoc/>
  6. public sealed class RoofSystem : SharedRoofSystem
  7. {
  8. [Dependency] private readonly SharedMapSystem _maps = default!;
  9. private EntityQuery<MapGridComponent> _gridQuery;
  10. public override void Initialize()
  11. {
  12. base.Initialize();
  13. _gridQuery = GetEntityQuery<MapGridComponent>();
  14. SubscribeLocalEvent<SetRoofComponent, ComponentStartup>(OnFlagStartup);
  15. }
  16. private void OnFlagStartup(Entity<SetRoofComponent> ent, ref ComponentStartup args)
  17. {
  18. var xform = Transform(ent.Owner);
  19. if (_gridQuery.TryComp(xform.GridUid, out var grid))
  20. {
  21. var index = _maps.LocalToTile(xform.GridUid.Value, grid, xform.Coordinates);
  22. SetRoof((xform.GridUid.Value, grid, null), index, ent.Comp.Value);
  23. }
  24. QueueDel(ent.Owner);
  25. }
  26. }