Disposals refactor (#17803)
This commit is contained in:
@@ -1,145 +1,215 @@
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
|
||||
|
||||
namespace Content.Shared.Disposal.Components
|
||||
namespace Content.Shared.Disposal.Components;
|
||||
|
||||
[NetworkedComponent]
|
||||
public abstract class SharedDisposalUnitComponent : Component
|
||||
{
|
||||
[NetworkedComponent]
|
||||
public abstract class SharedDisposalUnitComponent : Component
|
||||
public const string ContainerId = "disposals";
|
||||
|
||||
/// <summary>
|
||||
/// Sounds played upon the unit flushing.
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite), DataField("soundFlush")]
|
||||
public SoundSpecifier? FlushSound = new SoundPathSpecifier("/Audio/Machines/disposalflush.ogg");
|
||||
|
||||
/// <summary>
|
||||
/// State for this disposals unit.
|
||||
/// </summary>
|
||||
[DataField("state")]
|
||||
public DisposalsPressureState State;
|
||||
|
||||
// TODO: Just make this use vaulting.
|
||||
/// <summary>
|
||||
/// We'll track whatever just left disposals so we know what collision we need to ignore until they stop intersecting our BB.
|
||||
/// </summary>
|
||||
[ViewVariables, DataField("recentlyEjected")]
|
||||
public readonly List<EntityUid> RecentlyEjected = new();
|
||||
|
||||
/// <summary>
|
||||
/// Next time the disposal unit will be pressurized.
|
||||
/// </summary>
|
||||
[DataField("nextPressurized", customTypeSerializer:typeof(TimeOffsetSerializer))]
|
||||
public TimeSpan NextPressurized = TimeSpan.Zero;
|
||||
|
||||
/// <summary>
|
||||
/// How long it takes to flush a disposals unit manually.
|
||||
/// </summary>
|
||||
[DataField("flushTime")]
|
||||
public TimeSpan ManualFlushTime = TimeSpan.FromSeconds(2);
|
||||
|
||||
/// <summary>
|
||||
/// How long it takes from the start of a flush animation to return the sprite to normal.
|
||||
/// </summary>
|
||||
[DataField("flushDelay")]
|
||||
public TimeSpan FlushDelay = TimeSpan.FromSeconds(3);
|
||||
|
||||
[DataField("mobsCanEnter")]
|
||||
public bool MobsCanEnter = true;
|
||||
|
||||
/// <summary>
|
||||
/// Removes the pressure requirement for flushing.
|
||||
/// </summary>
|
||||
[DataField("disablePressure"), ViewVariables(VVAccess.ReadWrite)]
|
||||
public bool DisablePressure = false;
|
||||
|
||||
/// <summary>
|
||||
/// Last time that an entity tried to exit this disposal unit.
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
public TimeSpan LastExitAttempt;
|
||||
|
||||
[DataField("autoEngageEnabled")]
|
||||
public bool AutomaticEngage = true;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("autoEngageTime")]
|
||||
public TimeSpan AutomaticEngageTime = TimeSpan.FromSeconds(30);
|
||||
|
||||
/// <summary>
|
||||
/// Delay from trying to enter disposals ourselves.
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("entryDelay")]
|
||||
public float EntryDelay = 0.5f;
|
||||
|
||||
/// <summary>
|
||||
/// Delay from trying to shove someone else into disposals.
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public float DraggedEntryDelay = 0.5f;
|
||||
|
||||
/// <summary>
|
||||
/// Container of entities inside this disposal unit.
|
||||
/// </summary>
|
||||
[ViewVariables] public Container Container = default!;
|
||||
|
||||
// TODO: Network power shit instead fam.
|
||||
[ViewVariables, DataField("powered")]
|
||||
public bool Powered;
|
||||
|
||||
/// <summary>
|
||||
/// Was the disposals unit engaged for a manual flush.
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite), DataField("engaged")]
|
||||
public bool Engaged;
|
||||
|
||||
/// <summary>
|
||||
/// Next time this unit will flush. Is the lesser of <see cref="FlushDelay"/> and <see cref="AutomaticEngageTime"/>
|
||||
/// </summary>
|
||||
[ViewVariables, DataField("nextFlush", customTypeSerializer:typeof(TimeOffsetSerializer))]
|
||||
public TimeSpan? NextFlush;
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public enum Visuals : byte
|
||||
{
|
||||
public const string ContainerId = "DisposalUnit";
|
||||
VisualState,
|
||||
Handle,
|
||||
Light
|
||||
}
|
||||
|
||||
// TODO: Could maybe turn the contact off instead far more cheaply as farseer (though not box2d) had support for it?
|
||||
// Need to suss it out.
|
||||
/// <summary>
|
||||
/// We'll track whatever just left disposals so we know what collision we need to ignore until they stop intersecting our BB.
|
||||
/// </summary>
|
||||
public List<EntityUid> RecentlyEjected = new();
|
||||
[Serializable, NetSerializable]
|
||||
public enum VisualState : byte
|
||||
{
|
||||
UnAnchored,
|
||||
Anchored,
|
||||
Flushing,
|
||||
Charging
|
||||
}
|
||||
|
||||
[DataField("flushTime", required: true)]
|
||||
public readonly float FlushTime;
|
||||
[Serializable, NetSerializable]
|
||||
public enum HandleState : byte
|
||||
{
|
||||
Normal,
|
||||
Engaged
|
||||
}
|
||||
|
||||
[DataField("mobsCanEnter")]
|
||||
public bool MobsCanEnter = true;
|
||||
[Serializable, NetSerializable]
|
||||
[Flags]
|
||||
public enum LightStates : byte
|
||||
{
|
||||
Off = 0,
|
||||
Charging = 1 << 0,
|
||||
Full = 1 << 1,
|
||||
Ready = 1 << 2
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes the pressure requirement for flushing.
|
||||
/// </summary>
|
||||
[DataField("disablePressure"), ViewVariables(VVAccess.ReadWrite)]
|
||||
public bool DisablePressure = false;
|
||||
[Serializable, NetSerializable]
|
||||
public enum UiButton : byte
|
||||
{
|
||||
Eject,
|
||||
Engage,
|
||||
Power
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public enum Visuals : byte
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class DisposalUnitBoundUserInterfaceState : BoundUserInterfaceState, IEquatable<DisposalUnitBoundUserInterfaceState>
|
||||
{
|
||||
public readonly string UnitName;
|
||||
public readonly string UnitState;
|
||||
public readonly TimeSpan FullPressureTime;
|
||||
public readonly bool Powered;
|
||||
public readonly bool Engaged;
|
||||
|
||||
public DisposalUnitBoundUserInterfaceState(string unitName, string unitState, TimeSpan fullPressureTime, bool powered,
|
||||
bool engaged)
|
||||
{
|
||||
VisualState,
|
||||
Handle,
|
||||
Light
|
||||
UnitName = unitName;
|
||||
UnitState = unitState;
|
||||
FullPressureTime = fullPressureTime;
|
||||
Powered = powered;
|
||||
Engaged = engaged;
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public enum VisualState : byte
|
||||
public bool Equals(DisposalUnitBoundUserInterfaceState? other)
|
||||
{
|
||||
UnAnchored,
|
||||
Anchored,
|
||||
Flushing,
|
||||
Charging
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public enum HandleState : byte
|
||||
{
|
||||
Normal,
|
||||
Engaged
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public enum LightStates : byte
|
||||
{
|
||||
Off = 0,
|
||||
Charging = 1 << 0,
|
||||
Full = 1 << 1,
|
||||
Ready = 1 << 2
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public enum UiButton : byte
|
||||
{
|
||||
Eject,
|
||||
Engage,
|
||||
Power
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public enum PressureState : byte
|
||||
{
|
||||
Ready,
|
||||
Pressurizing
|
||||
}
|
||||
|
||||
public override ComponentState GetComponentState()
|
||||
{
|
||||
return new DisposalUnitComponentState(RecentlyEjected);
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
protected sealed class DisposalUnitComponentState : ComponentState
|
||||
{
|
||||
public List<EntityUid> RecentlyEjected;
|
||||
|
||||
public DisposalUnitComponentState(List<EntityUid> uids)
|
||||
{
|
||||
RecentlyEjected = uids;
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class DisposalUnitBoundUserInterfaceState : BoundUserInterfaceState, IEquatable<DisposalUnitBoundUserInterfaceState>
|
||||
{
|
||||
public readonly string UnitName;
|
||||
public readonly string UnitState;
|
||||
public readonly TimeSpan FullPressureTime;
|
||||
public readonly bool Powered;
|
||||
public readonly bool Engaged;
|
||||
|
||||
public DisposalUnitBoundUserInterfaceState(string unitName, string unitState, TimeSpan fullPressureTime, bool powered,
|
||||
bool engaged)
|
||||
{
|
||||
UnitName = unitName;
|
||||
UnitState = unitState;
|
||||
FullPressureTime = fullPressureTime;
|
||||
Powered = powered;
|
||||
Engaged = engaged;
|
||||
}
|
||||
|
||||
public bool Equals(DisposalUnitBoundUserInterfaceState? other)
|
||||
{
|
||||
if (ReferenceEquals(null, other)) return false;
|
||||
if (ReferenceEquals(this, other)) return true;
|
||||
return UnitName == other.UnitName &&
|
||||
UnitState == other.UnitState &&
|
||||
Powered == other.Powered &&
|
||||
Engaged == other.Engaged &&
|
||||
FullPressureTime.Equals(other.FullPressureTime);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Message data sent from client to server when a disposal unit ui button is pressed.
|
||||
/// </summary>
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class UiButtonPressedMessage : BoundUserInterfaceMessage
|
||||
{
|
||||
public readonly UiButton Button;
|
||||
|
||||
public UiButtonPressedMessage(UiButton button)
|
||||
{
|
||||
Button = button;
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public enum DisposalUnitUiKey : byte
|
||||
{
|
||||
Key
|
||||
if (ReferenceEquals(null, other)) return false;
|
||||
if (ReferenceEquals(this, other)) return true;
|
||||
return UnitName == other.UnitName &&
|
||||
UnitState == other.UnitState &&
|
||||
Powered == other.Powered &&
|
||||
Engaged == other.Engaged &&
|
||||
FullPressureTime.Equals(other.FullPressureTime);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Message data sent from client to server when a disposal unit ui button is pressed.
|
||||
/// </summary>
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class UiButtonPressedMessage : BoundUserInterfaceMessage
|
||||
{
|
||||
public readonly UiButton Button;
|
||||
|
||||
public UiButtonPressedMessage(UiButton button)
|
||||
{
|
||||
Button = button;
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public enum DisposalUnitUiKey : byte
|
||||
{
|
||||
Key
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public enum DisposalsPressureState : byte
|
||||
{
|
||||
Ready,
|
||||
|
||||
/// <summary>
|
||||
/// Has been flushed recently within FlushDelay.
|
||||
/// </summary>
|
||||
Flushed,
|
||||
|
||||
/// <summary>
|
||||
/// FlushDelay has elapsed and now we're transitioning back to Ready.
|
||||
/// </summary>
|
||||
Pressurizing
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user