ECS standingstate (#8322)

This commit is contained in:
metalgearsloth
2022-05-21 17:30:38 +10:00
committed by GitHub
parent b5615b2564
commit 82693b4926
2 changed files with 37 additions and 31 deletions

View File

@@ -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<StandingStateComponent, ComponentGetState>(OnGetState);
SubscribeLocalEvent<StandingStateComponent, ComponentHandleState>(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