ECS standingstate (#8322)
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
using Content.Shared.Sound;
|
using Content.Shared.Sound;
|
||||||
using Robust.Shared.GameStates;
|
using Robust.Shared.GameStates;
|
||||||
using Robust.Shared.Serialization;
|
|
||||||
|
|
||||||
namespace Content.Shared.Standing
|
namespace Content.Shared.Standing
|
||||||
{
|
{
|
||||||
@@ -9,8 +8,8 @@ namespace Content.Shared.Standing
|
|||||||
public sealed class StandingStateComponent : Component
|
public sealed class StandingStateComponent : Component
|
||||||
{
|
{
|
||||||
[ViewVariables(VVAccess.ReadWrite)]
|
[ViewVariables(VVAccess.ReadWrite)]
|
||||||
[DataField("downSoundCollection")]
|
[DataField("downSound")]
|
||||||
public SoundSpecifier DownSoundCollection { get; } = new SoundCollectionSpecifier("BodyFall");
|
public SoundSpecifier DownSound { get; } = new SoundCollectionSpecifier("BodyFall");
|
||||||
|
|
||||||
[DataField("standing")]
|
[DataField("standing")]
|
||||||
public bool Standing { get; set; } = true;
|
public bool Standing { get; set; } = true;
|
||||||
@@ -21,30 +20,5 @@ namespace Content.Shared.Standing
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
[DataField("changedFixtures")]
|
[DataField("changedFixtures")]
|
||||||
public List<string> ChangedFixtures = new();
|
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,16 +6,36 @@ using Robust.Shared.Player;
|
|||||||
using Robust.Shared.Timing;
|
using Robust.Shared.Timing;
|
||||||
using Robust.Shared.Physics;
|
using Robust.Shared.Physics;
|
||||||
using Content.Shared.Physics;
|
using Content.Shared.Physics;
|
||||||
|
using Robust.Shared.GameStates;
|
||||||
|
using Robust.Shared.Serialization;
|
||||||
|
|
||||||
namespace Content.Shared.Standing
|
namespace Content.Shared.Standing
|
||||||
{
|
{
|
||||||
public sealed class StandingStateSystem : EntitySystem
|
public sealed class StandingStateSystem : EntitySystem
|
||||||
{
|
{
|
||||||
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
||||||
|
|
||||||
// If StandingCollisionLayer value is ever changed to more than one layer, the logic needs to be edited.
|
// If StandingCollisionLayer value is ever changed to more than one layer, the logic needs to be edited.
|
||||||
private const int StandingCollisionLayer = (int) CollisionGroup.MidImpassable;
|
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)
|
public bool IsDown(EntityUid uid, StandingStateComponent? standingState = null)
|
||||||
{
|
{
|
||||||
if (!Resolve(uid, ref standingState, false))
|
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.
|
// > no longer true with door crushing. There just needs to be a better way to handle audio prediction.
|
||||||
if (playSound)
|
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;
|
return true;
|
||||||
@@ -108,7 +128,7 @@ namespace Content.Shared.Standing
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
standingState.Standing = true;
|
standingState.Standing = true;
|
||||||
standingState.Dirty();
|
Dirty(standingState);
|
||||||
RaiseLocalEvent(uid, new StoodEvent(), false);
|
RaiseLocalEvent(uid, new StoodEvent(), false);
|
||||||
|
|
||||||
appearance?.SetData(RotationVisuals.RotationState, RotationState.Vertical);
|
appearance?.SetData(RotationVisuals.RotationState, RotationState.Vertical);
|
||||||
@@ -125,6 +145,18 @@ namespace Content.Shared.Standing
|
|||||||
|
|
||||||
return true;
|
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
|
public sealed class DropHandItemsEvent : EventArgs
|
||||||
|
|||||||
Reference in New Issue
Block a user