Reagent grinder jittering (#24190)

* Reagent grinder jittering

* Fix jittering for offset sprites
This commit is contained in:
Kara
2024-01-17 06:14:32 -07:00
committed by GitHub
parent cfc64fa8ca
commit 1f92376579
3 changed files with 25 additions and 2 deletions

View File

@@ -30,6 +30,7 @@ namespace Content.Client.Jittering
var animationPlayer = EnsureComp<AnimationPlayerComponent>(uid); var animationPlayer = EnsureComp<AnimationPlayerComponent>(uid);
jittering.StartOffset = sprite.Offset;
_animationPlayer.Play(uid, animationPlayer, GetAnimation(jittering, sprite), _jitterAnimationKey); _animationPlayer.Play(uid, animationPlayer, GetAnimation(jittering, sprite), _jitterAnimationKey);
} }
@@ -39,7 +40,7 @@ namespace Content.Client.Jittering
_animationPlayer.Stop(uid, animationPlayer, _jitterAnimationKey); _animationPlayer.Stop(uid, animationPlayer, _jitterAnimationKey);
if (TryComp(uid, out SpriteComponent? sprite)) if (TryComp(uid, out SpriteComponent? sprite))
sprite.Offset = Vector2.Zero; sprite.Offset = jittering.StartOffset;
} }
private void OnAnimationCompleted(EntityUid uid, JitteringComponent jittering, AnimationCompletedEvent args) private void OnAnimationCompleted(EntityUid uid, JitteringComponent jittering, AnimationCompletedEvent args)
@@ -91,7 +92,7 @@ namespace Content.Client.Jittering
KeyFrames = KeyFrames =
{ {
new AnimationTrackProperty.KeyFrame(sprite.Offset, 0f), new AnimationTrackProperty.KeyFrame(sprite.Offset, 0f),
new AnimationTrackProperty.KeyFrame(offset, length), new AnimationTrackProperty.KeyFrame(jittering.StartOffset + offset, length),
} }
} }
} }

View File

@@ -20,6 +20,8 @@ using Robust.Shared.Audio.Systems;
using Robust.Shared.Containers; using Robust.Shared.Containers;
using Robust.Shared.Timing; using Robust.Shared.Timing;
using System.Linq; using System.Linq;
using Content.Server.Jittering;
using Content.Shared.Jittering;
namespace Content.Server.Kitchen.EntitySystems namespace Content.Server.Kitchen.EntitySystems
{ {
@@ -36,11 +38,14 @@ namespace Content.Server.Kitchen.EntitySystems
[Dependency] private readonly SharedAppearanceSystem _appearanceSystem = default!; [Dependency] private readonly SharedAppearanceSystem _appearanceSystem = default!;
[Dependency] private readonly SharedContainerSystem _containerSystem = default!; [Dependency] private readonly SharedContainerSystem _containerSystem = default!;
[Dependency] private readonly RandomHelperSystem _randomHelper = default!; [Dependency] private readonly RandomHelperSystem _randomHelper = default!;
[Dependency] private readonly JitteringSystem _jitter = default!;
public override void Initialize() public override void Initialize()
{ {
base.Initialize(); base.Initialize();
SubscribeLocalEvent<ActiveReagentGrinderComponent, ComponentStartup>(OnActiveGrinderStart);
SubscribeLocalEvent<ActiveReagentGrinderComponent, ComponentRemove>(OnActiveGrinderRemove);
SubscribeLocalEvent<ReagentGrinderComponent, ComponentStartup>((uid, _, _) => UpdateUiState(uid)); SubscribeLocalEvent<ReagentGrinderComponent, ComponentStartup>((uid, _, _) => UpdateUiState(uid));
SubscribeLocalEvent((EntityUid uid, ReagentGrinderComponent _, ref PowerChangedEvent _) => UpdateUiState(uid)); SubscribeLocalEvent((EntityUid uid, ReagentGrinderComponent _, ref PowerChangedEvent _) => UpdateUiState(uid));
SubscribeLocalEvent<ReagentGrinderComponent, InteractUsingEvent>(OnInteractUsing); SubscribeLocalEvent<ReagentGrinderComponent, InteractUsingEvent>(OnInteractUsing);
@@ -119,6 +124,16 @@ namespace Content.Server.Kitchen.EntitySystems
} }
} }
private void OnActiveGrinderStart(Entity<ActiveReagentGrinderComponent> ent, ref ComponentStartup args)
{
_jitter.AddJitter(ent, -10, 100);
}
private void OnActiveGrinderRemove(Entity<ActiveReagentGrinderComponent> ent, ref ComponentRemove args)
{
RemComp<JitteringComponent>(ent);
}
private void OnEntRemoveAttempt(Entity<ReagentGrinderComponent> entity, ref ContainerIsRemovingAttemptEvent args) private void OnEntRemoveAttempt(Entity<ReagentGrinderComponent> entity, ref ContainerIsRemovingAttemptEvent args)
{ {
if (HasComp<ActiveReagentGrinderComponent>(entity)) if (HasComp<ActiveReagentGrinderComponent>(entity))

View File

@@ -17,4 +17,11 @@ public sealed partial class JitteringComponent : Component
[ViewVariables(VVAccess.ReadWrite)] [ViewVariables(VVAccess.ReadWrite)]
public Vector2 LastJitter { get; set; } public Vector2 LastJitter { get; set; }
/// <summary>
/// The offset that an entity had before jittering started,
/// so that we can reset it properly.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
public Vector2 StartOffset = Vector2.Zero;
} }