diff --git a/Content.Shared/Standing/StandingStateComponent.cs b/Content.Shared/Standing/StandingStateComponent.cs index d36313ea38..10512de14d 100644 --- a/Content.Shared/Standing/StandingStateComponent.cs +++ b/Content.Shared/Standing/StandingStateComponent.cs @@ -1,6 +1,5 @@ using Content.Shared.Sound; using Robust.Shared.GameStates; -using Robust.Shared.Serialization; namespace Content.Shared.Standing { @@ -9,8 +8,8 @@ namespace Content.Shared.Standing public sealed class StandingStateComponent : Component { [ViewVariables(VVAccess.ReadWrite)] - [DataField("downSoundCollection")] - public SoundSpecifier DownSoundCollection { get; } = new SoundCollectionSpecifier("BodyFall"); + [DataField("downSound")] + public SoundSpecifier DownSound { get; } = new SoundCollectionSpecifier("BodyFall"); [DataField("standing")] public bool Standing { get; set; } = true; @@ -21,30 +20,5 @@ namespace Content.Shared.Standing /// [DataField("changedFixtures")] public List ChangedFixtures = new(); - - public override ComponentState GetComponentState() - { - return new StandingComponentState(Standing); - } - - public override void HandleComponentState(ComponentState? curState, ComponentState? nextState) - { - base.HandleComponentState(curState, nextState); - if (curState is not StandingComponentState state) return; - - Standing = state.Standing; - } - - // I'm not calling it StandingStateComponentState - [Serializable, NetSerializable] - private sealed class StandingComponentState : ComponentState - { - public bool Standing { get; } - - public StandingComponentState(bool standing) - { - Standing = standing; - } - } } } diff --git a/Content.Shared/Standing/StandingStateSystem.cs b/Content.Shared/Standing/StandingStateSystem.cs index 057dfc6199..90306f6cc6 100644 --- a/Content.Shared/Standing/StandingStateSystem.cs +++ b/Content.Shared/Standing/StandingStateSystem.cs @@ -6,16 +6,36 @@ using Robust.Shared.Player; using Robust.Shared.Timing; using Robust.Shared.Physics; using Content.Shared.Physics; +using Robust.Shared.GameStates; +using Robust.Shared.Serialization; namespace Content.Shared.Standing { public sealed class StandingStateSystem : EntitySystem { [Dependency] private readonly IGameTiming _gameTiming = default!; - + // If StandingCollisionLayer value is ever changed to more than one layer, the logic needs to be edited. private const int StandingCollisionLayer = (int) CollisionGroup.MidImpassable; + public override void Initialize() + { + SubscribeLocalEvent(OnGetState); + SubscribeLocalEvent(OnHandleState); + } + + private void OnHandleState(EntityUid uid, StandingStateComponent component, ref ComponentHandleState args) + { + if (args.Current is not StandingComponentState state) return; + + component.Standing = state.Standing; + } + + private void OnGetState(EntityUid uid, StandingStateComponent component, ref ComponentGetState args) + { + args.State = new StandingComponentState(component.Standing); + } + public bool IsDown(EntityUid uid, StandingStateComponent? standingState = null) { if (!Resolve(uid, ref standingState, false)) @@ -81,7 +101,7 @@ namespace Content.Shared.Standing // > no longer true with door crushing. There just needs to be a better way to handle audio prediction. if (playSound) { - SoundSystem.Play(Filter.Pvs(uid), standingState.DownSoundCollection.GetSound(), uid, AudioHelpers.WithVariation(0.25f)); + SoundSystem.Play(Filter.Pvs(uid), standingState.DownSound.GetSound(), uid, AudioHelpers.WithVariation(0.25f)); } return true; @@ -108,7 +128,7 @@ namespace Content.Shared.Standing return false; standingState.Standing = true; - standingState.Dirty(); + Dirty(standingState); RaiseLocalEvent(uid, new StoodEvent(), false); appearance?.SetData(RotationVisuals.RotationState, RotationState.Vertical); @@ -125,6 +145,18 @@ namespace Content.Shared.Standing return true; } + + // I'm not calling it StandingStateComponentState + [Serializable, NetSerializable] + private sealed class StandingComponentState : ComponentState + { + public bool Standing { get; } + + public StandingComponentState(bool standing) + { + Standing = standing; + } + } } public sealed class DropHandItemsEvent : EventArgs