ECS standingstate (#8322)

This commit is contained in:
metalgearsloth 2022-05-21 17:30:38 +10:00 committed by GitHub
parent b5615b2564
commit 82693b4926
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 31 deletions

View File

@ -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
/// </summary>
[DataField("changedFixtures")]
public List<string> 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;
}
}
}
}

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