-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master' into blank1
- Loading branch information
Showing
77 changed files
with
651 additions
and
221 deletions.
There are no files selected for viewing
144 changes: 144 additions & 0 deletions
144
Content.Client/Movement/Systems/ClientWaddleAnimationSystem.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Numerics; | ||
using Content.Client.Buckle; | ||
using Content.Client.Gravity; | ||
using Content.Shared.ActionBlocker; | ||
using Content.Shared.Mobs.Systems; | ||
using Content.Shared.Movement.Components; | ||
using Content.Shared.Movement.Systems; | ||
using Robust.Client.Animations; | ||
using Robust.Client.GameObjects; | ||
using Robust.Shared.Animations; | ||
|
||
namespace Content.Client.Movement.Systems; | ||
|
||
public sealed class ClientWaddleAnimationSystem : SharedWaddleAnimationSystem | ||
{ | ||
[Dependency] private readonly AnimationPlayerSystem _animation = default!; | ||
[Dependency] private readonly GravitySystem _gravity = default!; | ||
[Dependency] private readonly ActionBlockerSystem _actionBlocker = default!; | ||
[Dependency] private readonly BuckleSystem _buckle = default!; | ||
[Dependency] private readonly MobStateSystem _mobState = default!; | ||
|
||
public override void Initialize() | ||
{ | ||
base.Initialize(); | ||
|
||
// Start waddling | ||
SubscribeAllEvent<StartedWaddlingEvent>((msg, args) => StartWaddling(args.SenderSession.AttachedEntity)); | ||
|
||
// Handle concluding animations | ||
SubscribeLocalEvent<WaddleAnimationComponent, AnimationCompletedEvent>(OnAnimationCompleted); | ||
|
||
// Stop waddling | ||
SubscribeAllEvent<StoppedWaddlingEvent>((msg, args) => StopWaddling(args.SenderSession.AttachedEntity)); | ||
} | ||
|
||
private void StartWaddling(EntityUid? uid) | ||
{ | ||
if ( | ||
!EntityIsValid(uid, out var entity, out var component) || | ||
_animation.HasRunningAnimation(entity.Value, component.KeyName) || | ||
_gravity.IsWeightless(entity.Value) || | ||
_buckle.IsBuckled(entity.Value) || | ||
_mobState.IsIncapacitated(entity.Value) || | ||
!TryComp<InputMoverComponent>(entity, out var mover) || | ||
!_actionBlocker.CanMove(entity.Value, mover) | ||
) | ||
return; | ||
|
||
PlayWaddleAnimationUsing(entity.Value, component, CalculateAnimationLength(component, mover), CalculateTumbleIntensity(component)); | ||
} | ||
|
||
private static float CalculateTumbleIntensity(WaddleAnimationComponent component) | ||
{ | ||
return component.LastStep ? 360 - component.TumbleIntensity : component.TumbleIntensity; | ||
} | ||
|
||
private static float CalculateAnimationLength(WaddleAnimationComponent component, InputMoverComponent mover) | ||
{ | ||
return mover.Sprinting ? component.AnimationLength * component.RunAnimationLengthMultiplier : component.AnimationLength; | ||
} | ||
|
||
private void OnAnimationCompleted(EntityUid uid, WaddleAnimationComponent component, AnimationCompletedEvent args) | ||
{ | ||
if (args.Key != component.KeyName) | ||
return; | ||
|
||
if (!TryComp<InputMoverComponent>(uid, out var mover)) | ||
return; | ||
|
||
PlayWaddleAnimationUsing(uid, component, CalculateAnimationLength(component, mover), CalculateTumbleIntensity(component)); | ||
} | ||
|
||
private void StopWaddling(EntityUid? uid) | ||
{ | ||
if ( | ||
!EntityIsValid(uid, out var entity, out var component) || | ||
!_animation.HasRunningAnimation(entity.Value, component.KeyName) | ||
) | ||
return; | ||
|
||
_animation.Stop(entity.Value, component.KeyName); | ||
|
||
if (!TryComp<SpriteComponent>(entity.Value, out var sprite)) | ||
return; | ||
|
||
// Note that this is a hard-write to this sprite, not some layer-based operation. If this is called whilst a sprite | ||
// is lying down, it will make the sprite stand up, which usually looks wrong. | ||
sprite.Offset = new Vector2(); | ||
sprite.Rotation = Angle.FromDegrees(0); | ||
} | ||
|
||
private bool EntityIsValid(EntityUid? uid, [NotNullWhen(true)] out EntityUid? entity, [NotNullWhen(true)] out WaddleAnimationComponent? component) | ||
{ | ||
entity = null; | ||
component = null; | ||
|
||
if (!uid.HasValue) | ||
return false; | ||
|
||
entity = uid.Value; | ||
|
||
return TryComp(entity, out component); | ||
} | ||
|
||
private void PlayWaddleAnimationUsing(EntityUid uid, WaddleAnimationComponent component, float len, float tumbleIntensity) | ||
{ | ||
component.LastStep = !component.LastStep; | ||
|
||
var anim = 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/2), | ||
new AnimationTrackProperty.KeyFrame(Angle.FromDegrees(0), len/2), | ||
} | ||
}, | ||
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/2), | ||
new AnimationTrackProperty.KeyFrame(new Vector2(), len/2), | ||
} | ||
} | ||
} | ||
}; | ||
|
||
_animation.Play(uid, anim, component.KeyName); | ||
} | ||
} |
135 changes: 0 additions & 135 deletions
135
Content.Client/Movement/Systems/WaddleAnimationSystem.cs
This file was deleted.
Oops, something went wrong.
5 changes: 5 additions & 0 deletions
5
Content.Server/Movement/Systems/ServerWaddleAnimationSystem.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
using Content.Shared.Movement.Systems; | ||
|
||
namespace Content.Server.Movement.Systems; | ||
|
||
public sealed class ServerWaddleAnimationSystem : SharedWaddleAnimationSystem; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
.../Clothing/Systems/WaddleClothingSystem.cs → ...ing/EntitySystems/WaddleClothingSystem.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.