Implement ECS alternative for IDragDropOn and fully ECS disposal units (#6380)
Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
This commit is contained in:
@@ -2,20 +2,12 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using Content.Server.Atmos;
|
||||
using Content.Server.Disposal.Unit.EntitySystems;
|
||||
using Content.Server.Power.Components;
|
||||
using Content.Server.UserInterface;
|
||||
using Content.Shared.ActionBlocker;
|
||||
using Content.Shared.Acts;
|
||||
using Content.Shared.Atmos;
|
||||
using Content.Shared.Disposal.Components;
|
||||
using Content.Shared.DragDrop;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
@@ -23,7 +15,7 @@ namespace Content.Server.Disposal.Unit.Components
|
||||
{
|
||||
[RegisterComponent]
|
||||
[ComponentReference(typeof(SharedDisposalUnitComponent))]
|
||||
public class DisposalUnitComponent : SharedDisposalUnitComponent, IGasMixtureHolder, IDestroyAct
|
||||
public class DisposalUnitComponent : SharedDisposalUnitComponent, IGasMixtureHolder
|
||||
{
|
||||
/// <summary>
|
||||
/// Last time that an entity tried to exit this disposal unit.
|
||||
@@ -41,7 +33,7 @@ namespace Content.Server.Disposal.Unit.Components
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("autoEngageTime")]
|
||||
public readonly TimeSpan _automaticEngageTime = TimeSpan.FromSeconds(30);
|
||||
public readonly TimeSpan AutomaticEngageTime = TimeSpan.FromSeconds(30);
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("flushDelay")]
|
||||
@@ -71,86 +63,14 @@ namespace Content.Server.Disposal.Unit.Components
|
||||
/// </summary>
|
||||
[ViewVariables] public Container Container = default!;
|
||||
|
||||
[ViewVariables] public IReadOnlyList<EntityUid> ContainedEntities => Container.ContainedEntities;
|
||||
[ViewVariables] public bool Powered = false;
|
||||
|
||||
[ViewVariables]
|
||||
public bool Powered =>
|
||||
!IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner, out ApcPowerReceiverComponent? receiver) ||
|
||||
receiver.Powered;
|
||||
|
||||
[ViewVariables] public PressureState State => Pressure >= 1 ? PressureState.Ready : PressureState.Pressurizing;
|
||||
[ViewVariables] public PressureState State = PressureState.Ready;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public bool Engaged { get; set; }
|
||||
|
||||
[ViewVariables] public BoundUserInterface? UserInterface => Owner.GetUIOrNull(DisposalUnitUiKey.Key);
|
||||
|
||||
[DataField("air")]
|
||||
public GasMixture Air { get; set; } = new(Atmospherics.CellVolume);
|
||||
|
||||
private bool PlayerCanUse(EntityUid player)
|
||||
{
|
||||
var actionBlocker = EntitySystem.Get<ActionBlockerSystem>();
|
||||
|
||||
if (!actionBlocker.CanInteract(player) ||
|
||||
!actionBlocker.CanUse(player))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void OnUiReceiveMessage(ServerBoundUserInterfaceMessage obj)
|
||||
{
|
||||
if (obj.Session.AttachedEntity is not {Valid: true} player)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!PlayerCanUse(player))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (obj.Message is not UiButtonPressedMessage message)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
switch (message.Button)
|
||||
{
|
||||
case UiButton.Eject:
|
||||
EntitySystem.Get<DisposalUnitSystem>().TryEjectContents(this);
|
||||
break;
|
||||
case UiButton.Engage:
|
||||
EntitySystem.Get<DisposalUnitSystem>().ToggleEngage(this);
|
||||
break;
|
||||
case UiButton.Power:
|
||||
EntitySystem.Get<DisposalUnitSystem>().TogglePower(this);
|
||||
SoundSystem.Play(Filter.Pvs(Owner), "/Audio/Machines/machine_switch.ogg", Owner, AudioParams.Default.WithVolume(-2f));
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
}
|
||||
|
||||
public override bool CanDragDropOn(DragDropEvent eventArgs)
|
||||
{
|
||||
// Base is redundant given this already calls the base CanInsert
|
||||
// If that changes then update this
|
||||
return EntitySystem.Get<DisposalUnitSystem>().CanInsert(this, eventArgs.Dragged);
|
||||
}
|
||||
|
||||
public override bool DragDropOn(DragDropEvent eventArgs)
|
||||
{
|
||||
EntitySystem.Get<DisposalUnitSystem>().TryInsert(Owner, eventArgs.Dragged, eventArgs.User);
|
||||
return true;
|
||||
}
|
||||
|
||||
void IDestroyAct.OnDestroy(DestructionEventArgs eventArgs)
|
||||
{
|
||||
EntitySystem.Get<DisposalUnitSystem>().TryEjectContents(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user