using System; using System.Collections.Generic; using Content.Shared.Doors; namespace Content.Client.Doors { /// /// Used by the client to "predict" when doors will change how collideable they are as part of their opening / closing. /// internal sealed class DoorSystem : SharedDoorSystem { /// /// List of doors that need to be periodically checked. /// private readonly List _activeDoors = new(); public override void Initialize() { base.Initialize(); SubscribeLocalEvent(HandleDoorState); } /// /// Registers doors to be periodically checked. /// /// A message corresponding to the component under consideration, raised when its state changes. private void HandleDoorState(DoorStateMessage message) { switch (message.State) { case SharedDoorComponent.DoorState.Closed: case SharedDoorComponent.DoorState.Open: _activeDoors.Remove(message.Component); break; case SharedDoorComponent.DoorState.Closing: case SharedDoorComponent.DoorState.Opening: _activeDoors.Add(message.Component); break; default: throw new ArgumentOutOfRangeException(); } } /// public override void Update(float frameTime) { for (var i = _activeDoors.Count - 1; i >= 0; i--) { var comp = _activeDoors[i]; if (comp.Deleted) { _activeDoors.RemoveAt(i); } comp.OnUpdate(); } } } }