Reagent grinder jittering (#24190)
* Reagent grinder jittering * Fix jittering for offset sprites
This commit is contained in:
@@ -30,6 +30,7 @@ namespace Content.Client.Jittering
|
||||
|
||||
var animationPlayer = EnsureComp<AnimationPlayerComponent>(uid);
|
||||
|
||||
jittering.StartOffset = sprite.Offset;
|
||||
_animationPlayer.Play(uid, animationPlayer, GetAnimation(jittering, sprite), _jitterAnimationKey);
|
||||
}
|
||||
|
||||
@@ -39,7 +40,7 @@ namespace Content.Client.Jittering
|
||||
_animationPlayer.Stop(uid, animationPlayer, _jitterAnimationKey);
|
||||
|
||||
if (TryComp(uid, out SpriteComponent? sprite))
|
||||
sprite.Offset = Vector2.Zero;
|
||||
sprite.Offset = jittering.StartOffset;
|
||||
}
|
||||
|
||||
private void OnAnimationCompleted(EntityUid uid, JitteringComponent jittering, AnimationCompletedEvent args)
|
||||
@@ -91,7 +92,7 @@ namespace Content.Client.Jittering
|
||||
KeyFrames =
|
||||
{
|
||||
new AnimationTrackProperty.KeyFrame(sprite.Offset, 0f),
|
||||
new AnimationTrackProperty.KeyFrame(offset, length),
|
||||
new AnimationTrackProperty.KeyFrame(jittering.StartOffset + offset, length),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,8 @@ using Robust.Shared.Audio.Systems;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.Timing;
|
||||
using System.Linq;
|
||||
using Content.Server.Jittering;
|
||||
using Content.Shared.Jittering;
|
||||
|
||||
namespace Content.Server.Kitchen.EntitySystems
|
||||
{
|
||||
@@ -36,11 +38,14 @@ namespace Content.Server.Kitchen.EntitySystems
|
||||
[Dependency] private readonly SharedAppearanceSystem _appearanceSystem = default!;
|
||||
[Dependency] private readonly SharedContainerSystem _containerSystem = default!;
|
||||
[Dependency] private readonly RandomHelperSystem _randomHelper = default!;
|
||||
[Dependency] private readonly JitteringSystem _jitter = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<ActiveReagentGrinderComponent, ComponentStartup>(OnActiveGrinderStart);
|
||||
SubscribeLocalEvent<ActiveReagentGrinderComponent, ComponentRemove>(OnActiveGrinderRemove);
|
||||
SubscribeLocalEvent<ReagentGrinderComponent, ComponentStartup>((uid, _, _) => UpdateUiState(uid));
|
||||
SubscribeLocalEvent((EntityUid uid, ReagentGrinderComponent _, ref PowerChangedEvent _) => UpdateUiState(uid));
|
||||
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)
|
||||
{
|
||||
if (HasComp<ActiveReagentGrinderComponent>(entity))
|
||||
|
||||
@@ -17,4 +17,11 @@ public sealed partial class JitteringComponent : Component
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user