Files
tbd-station-14/Content.Server/GameObjects/EntitySystems/ConveyorSystem.cs
metalgearsloth 619386a04a Server EntitySystem cleanup (#1617)
* Server EntitySystem cleanup

I went after low-hanging fruit systems.

* Add / change to internal access modifiers to systems
* Use EntityQuery to get components instead
* Add sealed modifier to systems
* Remove unused imports
* Add jetbrains annotation for unused classes
* Removed some pragmas for dependencies

This should also fix a decent chunk of the server build warnings, at least the ones that matter.

* Also disposals

* Update Content.Server/GameObjects/EntitySystems/GravitySystem.cs

* Fix build

Co-authored-by: Metal Gear Sloth <metalgearsloth@gmail.com>
Co-authored-by: Víctor Aguilera Puerto <6766154+Zumorica@users.noreply.github.com>
2020-08-13 14:17:12 +02:00

95 lines
2.5 KiB
C#

using System.Collections.Generic;
using Content.Server.GameObjects.Components.Conveyor;
using Content.Shared.GameObjects.Components.Conveyor;
using JetBrains.Annotations;
using Robust.Shared.GameObjects.Systems;
namespace Content.Server.GameObjects.EntitySystems
{
[UsedImplicitly]
internal sealed class ConveyorSystem : EntitySystem
{
public override void Update(float frameTime)
{
foreach (var comp in ComponentManager.EntityQuery<ConveyorComponent>())
{
comp.Update(frameTime);
}
}
}
public class ConveyorGroup
{
private readonly HashSet<ConveyorComponent> _conveyors;
private readonly HashSet<ConveyorSwitchComponent> _switches;
public ConveyorGroup()
{
_conveyors = new HashSet<ConveyorComponent>(0);
_switches = new HashSet<ConveyorSwitchComponent>(0);
State = ConveyorState.Off;
}
public IReadOnlyCollection<ConveyorComponent> Conveyors => _conveyors;
public IReadOnlyCollection<ConveyorSwitchComponent> Switches => _switches;
public ConveyorState State { get; private set; }
public void AddConveyor(ConveyorComponent conveyor)
{
_conveyors.Add(conveyor);
conveyor.Sync(this);
}
public void RemoveConveyor(ConveyorComponent conveyor)
{
_conveyors.Remove(conveyor);
}
public void AddSwitch(ConveyorSwitchComponent conveyorSwitch)
{
_switches.Add(conveyorSwitch);
if (_switches.Count == 1)
{
SetState(conveyorSwitch);
}
conveyorSwitch.Sync(this);
}
public void RemoveSwitch(ConveyorSwitchComponent conveyorSwitch)
{
_switches.Remove(conveyorSwitch);
}
public void SetState(ConveyorSwitchComponent conveyorSwitch)
{
var state = conveyorSwitch.State;
if (state == ConveyorState.Loose)
{
if (_switches.Count > 0)
{
return;
}
state = ConveyorState.Off;
}
State = state;
foreach (var conveyor in Conveyors)
{
conveyor.Sync(this);
}
foreach (var connectedSwitch in _switches)
{
connectedSwitch.Sync(this);
}
}
}
}