Update disposals code standards (#11076)
Co-authored-by: Kara <lunarautomaton6@gmail.com>
This commit is contained in:
@@ -32,10 +32,10 @@ public sealed class MailingUnitSystem : EntitySystem
|
|||||||
|
|
||||||
SubscribeLocalEvent<MailingUnitComponent, ComponentInit>(OnComponentInit);
|
SubscribeLocalEvent<MailingUnitComponent, ComponentInit>(OnComponentInit);
|
||||||
SubscribeLocalEvent<MailingUnitComponent, DeviceNetworkPacketEvent>(OnPacketReceived);
|
SubscribeLocalEvent<MailingUnitComponent, DeviceNetworkPacketEvent>(OnPacketReceived);
|
||||||
SubscribeLocalEvent<MailingUnitComponent, DisposalUnitSystem.BeforeDisposalFlushEvent>(OnBeforeFlush);
|
SubscribeLocalEvent<MailingUnitComponent, BeforeDisposalFlushEvent>(OnBeforeFlush);
|
||||||
SubscribeLocalEvent<MailingUnitComponent, ConfigurationSystem.ConfigurationUpdatedEvent>(OnConfigurationUpdated);
|
SubscribeLocalEvent<MailingUnitComponent, ConfigurationSystem.ConfigurationUpdatedEvent>(OnConfigurationUpdated);
|
||||||
SubscribeLocalEvent<MailingUnitComponent, ActivateInWorldEvent>(HandleActivate);
|
SubscribeLocalEvent<MailingUnitComponent, ActivateInWorldEvent>(HandleActivate);
|
||||||
SubscribeLocalEvent<MailingUnitComponent, DisposalUnitSystem.DisposalUnitUIStateUpdatedEvent>(OnDisposalUnitUIStateChange);
|
SubscribeLocalEvent<MailingUnitComponent, DisposalUnitUIStateUpdatedEvent>(OnDisposalUnitUIStateChange);
|
||||||
SubscribeLocalEvent<MailingUnitComponent, TargetSelectedMessage>(OnTargetSelected);
|
SubscribeLocalEvent<MailingUnitComponent, TargetSelectedMessage>(OnTargetSelected);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,7 +83,7 @@ public sealed class MailingUnitSystem : EntitySystem
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Prevents the unit from flushing if no target is selected
|
/// Prevents the unit from flushing if no target is selected
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void OnBeforeFlush(EntityUid uid, MailingUnitComponent component, DisposalUnitSystem.BeforeDisposalFlushEvent args)
|
private void OnBeforeFlush(EntityUid uid, MailingUnitComponent component, BeforeDisposalFlushEvent args)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(component.Target))
|
if (string.IsNullOrEmpty(component.Target))
|
||||||
{
|
{
|
||||||
@@ -164,7 +164,7 @@ public sealed class MailingUnitSystem : EntitySystem
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets called when the disposal unit components ui state changes. This is required because the mailing unit requires a disposal unit component and overrides its ui
|
/// Gets called when the disposal unit components ui state changes. This is required because the mailing unit requires a disposal unit component and overrides its ui
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void OnDisposalUnitUIStateChange(EntityUid uid, MailingUnitComponent component, DisposalUnitSystem.DisposalUnitUIStateUpdatedEvent args)
|
private void OnDisposalUnitUIStateChange(EntityUid uid, MailingUnitComponent component, DisposalUnitUIStateUpdatedEvent args)
|
||||||
{
|
{
|
||||||
component.DisposalUnitInterfaceState = args.State;
|
component.DisposalUnitInterfaceState = args.State;
|
||||||
UpdateUserInterface(component);
|
UpdateUserInterface(component);
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
namespace Content.Server.Disposal.Unit.Components;
|
||||||
|
|
||||||
|
[RegisterComponent]
|
||||||
|
public sealed class ActiveDisposalUnitComponent : Component
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
@@ -7,9 +7,6 @@ using Content.Server.DoAfter;
|
|||||||
using Content.Server.Hands.Components;
|
using Content.Server.Hands.Components;
|
||||||
using Content.Server.Popups;
|
using Content.Server.Popups;
|
||||||
using Content.Server.Power.Components;
|
using Content.Server.Power.Components;
|
||||||
using Content.Server.UserInterface;
|
|
||||||
using Content.Server.Storage.Components;
|
|
||||||
using Content.Server.Storage.EntitySystems;
|
|
||||||
using Content.Shared.ActionBlocker;
|
using Content.Shared.ActionBlocker;
|
||||||
using Content.Shared.Atmos;
|
using Content.Shared.Atmos;
|
||||||
using Content.Shared.Construction.Components;
|
using Content.Shared.Construction.Components;
|
||||||
@@ -21,16 +18,13 @@ using Content.Shared.Hands.Components;
|
|||||||
using Content.Shared.Hands.EntitySystems;
|
using Content.Shared.Hands.EntitySystems;
|
||||||
using Content.Shared.Interaction;
|
using Content.Shared.Interaction;
|
||||||
using Content.Shared.Item;
|
using Content.Shared.Item;
|
||||||
using Content.Shared.Movement;
|
|
||||||
using Content.Shared.Movement.Events;
|
using Content.Shared.Movement.Events;
|
||||||
using Content.Shared.Popups;
|
using Content.Shared.Popups;
|
||||||
using Content.Shared.Throwing;
|
using Content.Shared.Throwing;
|
||||||
using Content.Shared.Verbs;
|
using Content.Shared.Verbs;
|
||||||
using Content.Shared.Storage.Components;
|
|
||||||
using Robust.Server.GameObjects;
|
using Robust.Server.GameObjects;
|
||||||
using Robust.Shared.Audio;
|
using Robust.Shared.Audio;
|
||||||
using Robust.Shared.Containers;
|
using Robust.Shared.Containers;
|
||||||
using Robust.Shared.Map;
|
|
||||||
using Robust.Shared.Player;
|
using Robust.Shared.Player;
|
||||||
using Robust.Shared.Random;
|
using Robust.Shared.Random;
|
||||||
|
|
||||||
@@ -40,15 +34,16 @@ namespace Content.Server.Disposal.Unit.EntitySystems
|
|||||||
{
|
{
|
||||||
[Dependency] private readonly IRobustRandom _robustRandom = default!;
|
[Dependency] private readonly IRobustRandom _robustRandom = default!;
|
||||||
[Dependency] private readonly ActionBlockerSystem _actionBlockerSystem = default!;
|
[Dependency] private readonly ActionBlockerSystem _actionBlockerSystem = default!;
|
||||||
|
[Dependency] private readonly AppearanceSystem _appearance = default!;
|
||||||
[Dependency] private readonly AtmosphereSystem _atmosSystem = default!;
|
[Dependency] private readonly AtmosphereSystem _atmosSystem = default!;
|
||||||
|
[Dependency] private readonly AudioSystem _audio = default!;
|
||||||
[Dependency] private readonly DoAfterSystem _doAfterSystem = default!;
|
[Dependency] private readonly DoAfterSystem _doAfterSystem = default!;
|
||||||
|
[Dependency] private readonly EntityLookupSystem _lookup = default!;
|
||||||
[Dependency] private readonly PopupSystem _popupSystem = default!;
|
[Dependency] private readonly PopupSystem _popupSystem = default!;
|
||||||
[Dependency] private readonly SharedHandsSystem _handsSystem = default!;
|
|
||||||
[Dependency] private readonly DumpableSystem _dumpableSystem = default!;
|
|
||||||
[Dependency] private readonly TransformSystem _transformSystem = default!;
|
|
||||||
[Dependency] private readonly SharedContainerSystem _containerSystem = default!;
|
[Dependency] private readonly SharedContainerSystem _containerSystem = default!;
|
||||||
|
[Dependency] private readonly SharedHandsSystem _handsSystem = default!;
|
||||||
private readonly List<DisposalUnitComponent> _activeDisposals = new();
|
[Dependency] private readonly TransformSystem _transformSystem = default!;
|
||||||
|
[Dependency] private readonly UserInterfaceSystem _ui = default!;
|
||||||
|
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
@@ -187,11 +182,12 @@ namespace Content.Server.Disposal.Unit.EntitySystems
|
|||||||
public override void Update(float frameTime)
|
public override void Update(float frameTime)
|
||||||
{
|
{
|
||||||
base.Update(frameTime);
|
base.Update(frameTime);
|
||||||
for (var i = _activeDisposals.Count - 1; i >= 0; i--)
|
foreach (var (_, comp) in EntityQuery<ActiveDisposalUnitComponent, DisposalUnitComponent>())
|
||||||
{
|
{
|
||||||
var comp = _activeDisposals[i];
|
if (!Update(comp, frameTime))
|
||||||
if (!Update(comp, frameTime)) continue;
|
continue;
|
||||||
_activeDisposals.RemoveAt(i);
|
|
||||||
|
RemComp<ActiveDisposalUnitComponent>(comp.Owner);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -213,7 +209,8 @@ namespace Content.Server.Disposal.Unit.EntitySystems
|
|||||||
break;
|
break;
|
||||||
case SharedDisposalUnitComponent.UiButton.Power:
|
case SharedDisposalUnitComponent.UiButton.Power:
|
||||||
TogglePower(component);
|
TogglePower(component);
|
||||||
SoundSystem.Play("/Audio/Machines/machine_switch.ogg", Filter.Pvs(component.Owner), component.Owner, AudioParams.Default.WithVolume(-2f));
|
_audio.PlayPvs(new SoundPathSpecifier("/Audio/Machines/machine_switch.ogg"), component.Owner,
|
||||||
|
AudioParams.Default.WithVolume(-2f));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new ArgumentOutOfRangeException();
|
throw new ArgumentOutOfRangeException();
|
||||||
@@ -255,7 +252,7 @@ namespace Content.Server.Disposal.Unit.EntitySystems
|
|||||||
}
|
}
|
||||||
|
|
||||||
args.Handled = true;
|
args.Handled = true;
|
||||||
component.Owner.GetUIOrNull(SharedDisposalUnitComponent.DisposalUnitUiKey.Key)?.Open(actor.PlayerSession);
|
_ui.TryOpen(component.Owner, SharedDisposalUnitComponent.DisposalUnitUiKey.Key, actor.PlayerSession);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void HandleAfterInteractUsing(EntityUid uid, DisposalUnitComponent component, AfterInteractUsingEvent args)
|
private void HandleAfterInteractUsing(EntityUid uid, DisposalUnitComponent component, AfterInteractUsingEvent args)
|
||||||
@@ -263,7 +260,7 @@ namespace Content.Server.Disposal.Unit.EntitySystems
|
|||||||
if (args.Handled || !args.CanReach)
|
if (args.Handled || !args.CanReach)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!EntityManager.TryGetComponent(args.User, out HandsComponent? hands))
|
if (!EntityManager.HasComponent<HandsComponent>(args.User))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -311,13 +308,12 @@ namespace Content.Server.Disposal.Unit.EntitySystems
|
|||||||
component.Container.ForceRemove(entity);
|
component.Container.ForceRemove(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
component.Owner.GetUIOrNull(SharedDisposalUnitComponent.DisposalUnitUiKey.Key)?.CloseAll();
|
_ui.TryCloseAll(component.Owner, SharedDisposalUnitComponent.DisposalUnitUiKey.Key);
|
||||||
|
|
||||||
component.AutomaticEngageToken?.Cancel();
|
component.AutomaticEngageToken?.Cancel();
|
||||||
component.AutomaticEngageToken = null;
|
component.AutomaticEngageToken = null;
|
||||||
|
|
||||||
component.Container = null!;
|
component.Container = null!;
|
||||||
_activeDisposals.Remove(component);
|
RemComp<ActiveDisposalUnitComponent>(uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void HandlePowerChange(EntityUid uid, DisposalUnitComponent component, PowerChangedEvent args)
|
private void HandlePowerChange(EntityUid uid, DisposalUnitComponent component, PowerChangedEvent args)
|
||||||
@@ -351,12 +347,11 @@ namespace Content.Server.Disposal.Unit.EntitySystems
|
|||||||
{
|
{
|
||||||
if (active)
|
if (active)
|
||||||
{
|
{
|
||||||
if (!_activeDisposals.Contains(component))
|
EnsureComp<ActiveDisposalUnitComponent>(component.Owner);
|
||||||
_activeDisposals.Add(component);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_activeDisposals.Remove(component);
|
RemComp<ActiveDisposalUnitComponent>(component.Owner);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -428,7 +423,7 @@ namespace Content.Server.Disposal.Unit.EntitySystems
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
disposalsBounds = disposalsBody.GetWorldAABB();
|
disposalsBounds = _lookup.GetWorldAABB(disposalsBody.Owner);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -440,7 +435,7 @@ namespace Content.Server.Disposal.Unit.EntitySystems
|
|||||||
{
|
{
|
||||||
// TODO: We need to use a specific collision method (which sloth hasn't coded yet) for actual bounds overlaps.
|
// TODO: We need to use a specific collision method (which sloth hasn't coded yet) for actual bounds overlaps.
|
||||||
// Check for itemcomp as we won't just block the disposal unit "sleeping" for something it can't collide with anyway.
|
// Check for itemcomp as we won't just block the disposal unit "sleeping" for something it can't collide with anyway.
|
||||||
if (!EntityManager.HasComponent<ItemComponent>(uid) && body.GetWorldAABB().Intersects(disposalsBounds!.Value)) continue;
|
if (!EntityManager.HasComponent<ItemComponent>(uid) && _lookup.GetWorldAABB(body.Owner).Intersects(disposalsBounds!.Value)) continue;
|
||||||
component.RecentlyEjected.RemoveAt(i);
|
component.RecentlyEjected.RemoveAt(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -500,7 +495,7 @@ namespace Content.Server.Disposal.Unit.EntitySystems
|
|||||||
|
|
||||||
//Allows the MailingUnitSystem to add tags or prevent flushing
|
//Allows the MailingUnitSystem to add tags or prevent flushing
|
||||||
var beforeFlushArgs = new BeforeDisposalFlushEvent();
|
var beforeFlushArgs = new BeforeDisposalFlushEvent();
|
||||||
RaiseLocalEvent(component.Owner, beforeFlushArgs, false);
|
RaiseLocalEvent(component.Owner, beforeFlushArgs);
|
||||||
|
|
||||||
if (beforeFlushArgs.Cancelled)
|
if (beforeFlushArgs.Cancelled)
|
||||||
{
|
{
|
||||||
@@ -552,11 +547,11 @@ namespace Content.Server.Disposal.Unit.EntitySystems
|
|||||||
public void UpdateInterface(DisposalUnitComponent component, bool powered)
|
public void UpdateInterface(DisposalUnitComponent component, bool powered)
|
||||||
{
|
{
|
||||||
var stateString = Loc.GetString($"{component.State}");
|
var stateString = Loc.GetString($"{component.State}");
|
||||||
var state = new SharedDisposalUnitComponent.DisposalUnitBoundUserInterfaceState(EntityManager.GetComponent<MetaDataComponent>(component.Owner).EntityName, stateString, EstimatedFullPressure(component), powered, component.Engaged);
|
var state = new SharedDisposalUnitComponent.DisposalUnitBoundUserInterfaceState(Name(component.Owner), stateString, EstimatedFullPressure(component), powered, component.Engaged);
|
||||||
component.Owner.GetUIOrNull(SharedDisposalUnitComponent.DisposalUnitUiKey.Key)?.SetState(state);
|
_ui.TrySetUiState(component.Owner, SharedDisposalUnitComponent.DisposalUnitUiKey.Key, state);
|
||||||
|
|
||||||
var stateUpdatedEvent = new DisposalUnitUIStateUpdatedEvent(state);
|
var stateUpdatedEvent = new DisposalUnitUIStateUpdatedEvent(state);
|
||||||
RaiseLocalEvent(component.Owner, stateUpdatedEvent, false);
|
RaiseLocalEvent(component.Owner, stateUpdatedEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
private TimeSpan EstimatedFullPressure(DisposalUnitComponent component)
|
private TimeSpan EstimatedFullPressure(DisposalUnitComponent component)
|
||||||
@@ -583,40 +578,40 @@ namespace Content.Server.Disposal.Unit.EntitySystems
|
|||||||
|
|
||||||
if (!EntityManager.GetComponent<TransformComponent>(component.Owner).Anchored)
|
if (!EntityManager.GetComponent<TransformComponent>(component.Owner).Anchored)
|
||||||
{
|
{
|
||||||
appearance.SetData(SharedDisposalUnitComponent.Visuals.VisualState, SharedDisposalUnitComponent.VisualState.UnAnchored);
|
_appearance.SetData(component.Owner, SharedDisposalUnitComponent.Visuals.VisualState, SharedDisposalUnitComponent.VisualState.UnAnchored, appearance);
|
||||||
appearance.SetData(SharedDisposalUnitComponent.Visuals.Handle, SharedDisposalUnitComponent.HandleState.Normal);
|
_appearance.SetData(component.Owner, SharedDisposalUnitComponent.Visuals.Handle, SharedDisposalUnitComponent.HandleState.Normal, appearance);
|
||||||
appearance.SetData(SharedDisposalUnitComponent.Visuals.Light, SharedDisposalUnitComponent.LightState.Off);
|
_appearance.SetData(component.Owner, SharedDisposalUnitComponent.Visuals.Light, SharedDisposalUnitComponent.LightState.Off, appearance);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
appearance.SetData(SharedDisposalUnitComponent.Visuals.VisualState, component.Pressure < 1 ? SharedDisposalUnitComponent.VisualState.Charging : SharedDisposalUnitComponent.VisualState.Anchored);
|
_appearance.SetData(component.Owner, SharedDisposalUnitComponent.Visuals.VisualState, component.Pressure < 1 ? SharedDisposalUnitComponent.VisualState.Charging : SharedDisposalUnitComponent.VisualState.Anchored, appearance);
|
||||||
|
|
||||||
appearance.SetData(SharedDisposalUnitComponent.Visuals.Handle, component.Engaged
|
_appearance.SetData(component.Owner, SharedDisposalUnitComponent.Visuals.Handle, component.Engaged
|
||||||
? SharedDisposalUnitComponent.HandleState.Engaged
|
? SharedDisposalUnitComponent.HandleState.Engaged
|
||||||
: SharedDisposalUnitComponent.HandleState.Normal);
|
: SharedDisposalUnitComponent.HandleState.Normal, appearance);
|
||||||
|
|
||||||
if (!component.Powered)
|
if (!component.Powered)
|
||||||
{
|
{
|
||||||
appearance.SetData(SharedDisposalUnitComponent.Visuals.Light, SharedDisposalUnitComponent.LightState.Off);
|
_appearance.SetData(component.Owner, SharedDisposalUnitComponent.Visuals.Light, SharedDisposalUnitComponent.LightState.Off, appearance);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flush)
|
if (flush)
|
||||||
{
|
{
|
||||||
appearance.SetData(SharedDisposalUnitComponent.Visuals.VisualState, SharedDisposalUnitComponent.VisualState.Flushing);
|
_appearance.SetData(component.Owner, SharedDisposalUnitComponent.Visuals.VisualState, SharedDisposalUnitComponent.VisualState.Flushing, appearance);
|
||||||
appearance.SetData(SharedDisposalUnitComponent.Visuals.Light, SharedDisposalUnitComponent.LightState.Off);
|
_appearance.SetData(component.Owner, SharedDisposalUnitComponent.Visuals.Light, SharedDisposalUnitComponent.LightState.Off, appearance);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (component.Container.ContainedEntities.Count > 0)
|
if (component.Container.ContainedEntities.Count > 0)
|
||||||
{
|
{
|
||||||
appearance.SetData(SharedDisposalUnitComponent.Visuals.Light, SharedDisposalUnitComponent.LightState.Full);
|
_appearance.SetData(component.Owner, SharedDisposalUnitComponent.Visuals.Light, SharedDisposalUnitComponent.LightState.Full, appearance);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
appearance.SetData(SharedDisposalUnitComponent.Visuals.Light, component.Pressure < 1
|
_appearance.SetData(component.Owner, SharedDisposalUnitComponent.Visuals.Light, component.Pressure < 1
|
||||||
? SharedDisposalUnitComponent.LightState.Charging
|
? SharedDisposalUnitComponent.LightState.Charging
|
||||||
: SharedDisposalUnitComponent.LightState.Ready);
|
: SharedDisposalUnitComponent.LightState.Ready, appearance);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Remove(DisposalUnitComponent component, EntityUid entity)
|
public void Remove(DisposalUnitComponent component, EntityUid entity)
|
||||||
@@ -707,19 +702,11 @@ namespace Content.Server.Disposal.Unit.EntitySystems
|
|||||||
|
|
||||||
if (EntityManager.TryGetComponent(entity, out ActorComponent? actor))
|
if (EntityManager.TryGetComponent(entity, out ActorComponent? actor))
|
||||||
{
|
{
|
||||||
component.Owner.GetUIOrNull(SharedDisposalUnitComponent.DisposalUnitUiKey.Key)?.Close(actor.PlayerSession);
|
_ui.TryClose(component.Owner, SharedDisposalUnitComponent.DisposalUnitUiKey.Key, actor.PlayerSession);
|
||||||
}
|
}
|
||||||
|
|
||||||
UpdateVisualState(component);
|
UpdateVisualState(component);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Sent before the disposal unit flushes it's contents.
|
|
||||||
/// Allows adding tags for sorting and preventing the disposal unit from flushing.
|
|
||||||
/// </summary>
|
|
||||||
public sealed class BeforeDisposalFlushEvent : CancellableEntityEventArgs
|
|
||||||
{
|
|
||||||
public List<string> Tags = new();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -735,5 +722,13 @@ namespace Content.Server.Disposal.Unit.EntitySystems
|
|||||||
State = state;
|
State = state;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sent before the disposal unit flushes it's contents.
|
||||||
|
/// Allows adding tags for sorting and preventing the disposal unit from flushing.
|
||||||
|
/// </summary>
|
||||||
|
public sealed class BeforeDisposalFlushEvent : CancellableEntityEventArgs
|
||||||
|
{
|
||||||
|
public readonly List<string> Tags = new();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user