Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] Waddle / Походка Клоуна #107

Merged
merged 2 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
173 changes: 0 additions & 173 deletions Content.Client/Movement/Systems/WaddleAnimationSystem.cs

This file was deleted.

100 changes: 100 additions & 0 deletions Content.Client/_White/Animations/WaddleAnimationSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
using System.Numerics;
using Content.Client.Buckle;
using Content.Client.Gravity;
using Content.Shared._White.Animations;
using Content.Shared.Movement.Components;
using Content.Shared.Standing;
using Robust.Client.Animations;
using Robust.Client.GameObjects;
using Robust.Shared.Animations;

namespace Content.Client._White.Animations;

public sealed class WaddleAnimationSystem : SharedWaddleAnimationSystem
{
[Dependency] private readonly AnimationPlayerSystem _animation = default!;
[Dependency] private readonly StandingStateSystem _standingState = default!;
[Dependency] private readonly GravitySystem _gravity = default!;
[Dependency] private readonly BuckleSystem _buckle = default!;

public override void Initialize()
{
SubscribeLocalEvent<WaddleAnimationComponent, AnimationCompletedEvent>(OnAnimationCompleted);

SubscribeAllEvent<StartedWaddlingEvent>(ev => PlayAnimation(GetEntity(ev.User)));
SubscribeAllEvent<StoppedWaddlingEvent>(ev => StopAnimation(GetEntity(ev.User)));
Spatison marked this conversation as resolved.
Show resolved Hide resolved
}

protected override void PlayAnimation(EntityUid uid)
{
if (!Timing.IsFirstTimePredicted
Spatison marked this conversation as resolved.
Show resolved Hide resolved
|| !TryComp<WaddleAnimationComponent>(uid, out var component)
|| !TryComp<InputMoverComponent>(uid, out var mover)
|| _animation.HasRunningAnimation(uid, component.KeyName)
|| _standingState.IsDown(uid)
|| _gravity.IsWeightless(uid)
|| _buckle.IsBuckled(uid))
return;

var tumbleIntensity = component.LastStep ? 360 - component.TumbleIntensity : component.TumbleIntensity;
var len = mover.Sprinting ? component.AnimationLength * component.RunAnimationLengthMultiplier : component.AnimationLength;

component.LastStep = !component.LastStep;
component.IsCurrentlyWaddling = true;

var animation = new Animation()
{
Length = TimeSpan.FromSeconds(len),
AnimationTracks =
{
new AnimationTrackComponentProperty()
{
ComponentType = typeof(SpriteComponent),
Property = nameof(SpriteComponent.Rotation),
InterpolationMode = AnimationInterpolationMode.Linear,
KeyFrames =
{
new AnimationTrackProperty.KeyFrame(Angle.FromDegrees(0), 0),
new AnimationTrackProperty.KeyFrame(Angle.FromDegrees(tumbleIntensity), len/3),
new AnimationTrackProperty.KeyFrame(Angle.FromDegrees(0), len/3),
Spatison marked this conversation as resolved.
Show resolved Hide resolved
}
},
new AnimationTrackComponentProperty()
{
ComponentType = typeof(SpriteComponent),
Property = nameof(SpriteComponent.Offset),
InterpolationMode = AnimationInterpolationMode.Linear,
KeyFrames =
{
new AnimationTrackProperty.KeyFrame(new Vector2(), 0),
new AnimationTrackProperty.KeyFrame(component.HopIntensity, len/3),
new AnimationTrackProperty.KeyFrame(new Vector2(), len/3),
}
}
}
};

_animation.Play(uid, animation, component.KeyName);
}

protected override void StopAnimation(EntityUid uid)
{
if (!TryComp<WaddleAnimationComponent>(uid, out var component)
|| !TryComp<SpriteComponent>(uid, out var sprite))
return;

_animation.Stop(uid, component.KeyName);

sprite.Offset = new Vector2();
sprite.Rotation = Angle.FromDegrees(0);
component.IsCurrentlyWaddling = false;
}

private void OnAnimationCompleted(EntityUid uid, WaddleAnimationComponent component, AnimationCompletedEvent args)
{
if (args.Key != component.KeyName)
return;

PlayAnimation(uid);
}
}
17 changes: 17 additions & 0 deletions Content.Server/_White/Animations/WaddleAnimationSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Content.Shared._White.Animations;
using Content.Shared.Movement.Components;

namespace Content.Server._White.Animations;

public sealed class WaddleAnimationSystem : SharedWaddleAnimationSystem
{
protected override void PlayAnimation(EntityUid user)
{
RaiseNetworkEvent(new StartedWaddlingEvent(GetNetEntity(user)));
}

protected override void StopAnimation(EntityUid user)
{
RaiseNetworkEvent(new StoppedWaddlingEvent(GetNetEntity(user)));
}
}
19 changes: 11 additions & 8 deletions Content.Shared/Movement/Components/WaddleAnimationComponent.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
using System.Numerics;
using Robust.Shared.Serialization;

namespace Content.Shared.Movement.Components;

// WD EDIT START
/// <summary>
/// Declares that an entity has started to waddle like a duck/clown.
/// </summary>
/// <param name="Entity">The newly be-waddled.</param>
[ByRefEvent]
public record struct StartedWaddlingEvent(EntityUid Entity)
/// <param name="user">The newly be-waddled.</param>
[Serializable, NetSerializable]
public sealed class StartedWaddlingEvent(NetEntity user) : EntityEventArgs
{
public EntityUid Entity = Entity;
public NetEntity User = user;
}

/// <summary>
/// Declares that an entity has stopped waddling like a duck/clown.
/// </summary>
/// <param name="Entity">The former waddle-er.</param>
[ByRefEvent]
public record struct StoppedWaddlingEvent(EntityUid Entity)
/// <param name="user">The former waddle-er.</param>
[Serializable, NetSerializable]
public sealed class StoppedWaddlingEvent(NetEntity user) : EntityEventArgs
{
public EntityUid Entity = Entity;
public NetEntity User = user;
}
// WD EDIT END

/// <summary>
/// Defines something as having a waddle animation when it moves.
Expand Down
51 changes: 51 additions & 0 deletions Content.Shared/_White/Animations/SharedWaddleAnimationSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using Content.Shared.Buckle;
using Content.Shared.Gravity;
using Content.Shared.Movement.Components;
using Content.Shared.Movement.Events;
using Content.Shared.Standing;
using Robust.Shared.Timing;

namespace Content.Shared._White.Animations;

public abstract class SharedWaddleAnimationSystem : EntitySystem
{
[Dependency] protected readonly IGameTiming Timing = default!;
[Dependency] private readonly StandingStateSystem _standingState = default!;
[Dependency] private readonly SharedGravitySystem _gravity = default!;
[Dependency] private readonly SharedBuckleSystem _buckle = default!;

public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<WaddleAnimationComponent, MoveInputEvent>(OnMovementInput);
}

private void OnMovementInput(EntityUid uid, WaddleAnimationComponent component, MoveInputEvent args)
{
if (!Timing.IsFirstTimePredicted
|| _standingState.IsDown(uid)
|| _gravity.IsWeightless(uid)
|| _buckle.IsBuckled(uid))
return;

if (!args.HasDirectionalMovement && component.IsCurrentlyWaddling)
{
component.IsCurrentlyWaddling = false;
StopAnimation(uid);

return;
}

if (component.IsCurrentlyWaddling || !args.HasDirectionalMovement)
return;

component.IsCurrentlyWaddling = true;

PlayAnimation(uid);
}

protected abstract void PlayAnimation(EntityUid user);

protected abstract void StopAnimation(EntityUid user);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using Content.Shared.Movement.Components;
using Content.Shared.Inventory.Events;

namespace Content.Client.Clothing.Systems;
namespace Content.Shared._White.Clothing.EntitySystems;

public sealed class WaddleClothingSystem : EntitySystem
{
Expand Down
Loading