Files
tbd-station-14/Content.Client/Disposal/Systems/DisposalUnitSystem.cs
Vera Aguilera Puerto 680ad72939 And a bunch more.
2021-12-08 12:19:45 +01:00

60 lines
1.8 KiB
C#

using System.Collections.Generic;
using Content.Client.Disposal.Components;
using Content.Client.Disposal.UI;
using Content.Shared.Disposal;
using Robust.Client.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
namespace Content.Client.Disposal.Systems
{
public sealed class DisposalUnitSystem : SharedDisposalUnitSystem
{
public List<DisposalUnitComponent> PressuringDisposals = new();
public void UpdateActive(DisposalUnitComponent component, bool active)
{
if (active)
{
if (!PressuringDisposals.Contains(component))
PressuringDisposals.Add(component);
}
else
{
PressuringDisposals.Remove(component);
}
}
public override void FrameUpdate(float frameTime)
{
base.FrameUpdate(frameTime);
for (var i = PressuringDisposals.Count - 1; i >= 0; i--)
{
var comp = PressuringDisposals[i];
if (!UpdateInterface(comp)) continue;
PressuringDisposals.RemoveAt(i);
}
}
private bool UpdateInterface(DisposalUnitComponent component)
{
if (component.Deleted) return true;
if (!EntityManager.TryGetComponent(component.Owner, out ClientUserInterfaceComponent? userInterface)) return true;
var state = component.UiState;
if (state == null) return true;
foreach (var inter in userInterface.Interfaces)
{
if (inter is DisposalUnitBoundUserInterface disposals)
{
return disposals.Window?.UpdateState(state) != false;
}
}
return true;
}
}
}