using Content.Shared.Light.EntitySystems; using Robust.Shared.Map.Components; namespace Content.Server._CP14.Roof; /// public sealed class CP14RoofSystem : EntitySystem { [Dependency] private readonly SharedMapSystem _maps = default!; [Dependency] private readonly SharedRoofSystem _roof = default!; public override void Initialize() { base.Initialize(); SubscribeLocalEvent(OnRoofStartup); SubscribeLocalEvent(OnRoofStartup); SubscribeLocalEvent(OnTileChanged); } private void OnTileChanged(Entity ent, ref TileChangedEvent args) { foreach (var changed in args.Changes) { if (changed.OldTile.IsEmpty) _roof.SetRoof(ent.Owner, changed.GridIndices, true); } } private void OnRoofStartup(Entity ent, ref ComponentStartup args) { if (!TryComp(ent.Owner, out var gridComp)) return; var enumerator = _maps.GetAllTilesEnumerator(ent, gridComp); while (enumerator.MoveNext(out var tileRef)) { _roof.SetRoof(ent.Owner, tileRef.Value.GridIndices, true); } } private void OnRoofStartup(Entity ent, ref ComponentStartup args) { if (!TryComp(ent.Owner, out var gridComp)) return; var enumerator = _maps.GetAllTilesEnumerator(ent, gridComp); while (enumerator.MoveNext(out var tileRef)) { _roof.SetRoof(ent.Owner, tileRef.Value.GridIndices, false); } } }