Files
tbd-station-14/Content.Client/Disposal/Systems/DisposalUnitSystem.cs
metalgearsloth 4da74d0ee4 Refactor disposals to ECS (#4418)
* ECS up disposals

Also significantly reduced its CPU usage.

* Make update significantly less S L O W

* Start units pressurised

* Client-side flush lerping

* Fix powered not toggling UI

* Fix flush button

* InteractUsing

* Minor optimisations

* Fix collisions

* Make visual state ECS

* Almost done with shared

* Most stuff moved

* Optimise item sleeping
2021-08-12 13:40:38 +10:00

58 lines
1.7 KiB
C#

using System.Collections.Generic;
using Content.Client.Disposal.Components;
using Content.Client.Disposal.UI;
using Content.Shared.Disposal;
using Robust.Client.GameObjects;
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 (!component.Owner.TryGetComponent(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;
}
}
}