Files
OldThink/Content.Client/_Amour/Animation/SharebleAnimationSystem.cs

105 lines
3.5 KiB
C#
Raw Normal View History

2024-02-24 16:37:40 +03:00
using System.Linq;
using Content.Client.Light.Components;
using Content.Shared._Amour.Animation;
using Content.Shared._Amour.Hole;
using Content.Shared.Verbs;
using Robust.Client.Animations;
using Robust.Client.GameObjects;
using Robust.Shared.Animations;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.Manager;
using Robust.Shared.Serialization.Markdown.Value;
using Robust.Shared.Utility;
namespace Content.Client._Amour.Animation;
public sealed class SharebleAnimationSystem : SharedAnimationSystem
{
[Dependency] private readonly AnimationPlayerSystem _animation = default!;
[Dependency] private readonly IComponentFactory _componentFactory = default!;
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly ISerializationManager _serializationManager = default!;
public override void Initialize()
{
SubscribeNetworkEvent<AnimationStartMessage>(OnStart);
SubscribeNetworkEvent<AnimationProtoStartMessage>(OnProtoStart);
}
private void OnProtoStart(AnimationProtoStartMessage ev)
{
if(ev.Owner.Valid)
Play(GetEntity(ev.Owner),ev.ProtoId);
2024-02-24 16:37:40 +03:00
}
private void OnStart(AnimationStartMessage ev)
{
if(ev.Owner.Valid)
Play(GetEntity(ev.Owner),ev.Data,ev.Id);
2024-02-24 16:37:40 +03:00
}
public override void Play(EntityUid uid,ProtoId<AnimationPrototype> protoId)
{
if(!_prototypeManager.TryIndex(protoId, out var prototype))
return;
Play(uid, prototype, protoId);
}
public override void Play(EntityUid uid,AnimationData data, string animationId = "funny")
{
2024-02-26 21:43:11 +03:00
if (_animation.HasRunningAnimation(uid, animationId))
{
Logger.Error($"Entity {ToPrettyString(uid)} has running animation {animationId}");
_animation.Stop(uid,animationId);
}
2024-02-24 16:37:40 +03:00
var animation = ParseAnimation(data);
_animation.Play(uid,animation,animationId);
}
public Robust.Client.Animations.Animation ParseAnimation(AnimationData data)
{
var animation = new Robust.Client.Animations.Animation
{
Length = data.Length
};
foreach (var track in data.AnimationTracks)
{
var component = _componentFactory.GetComponent(track.ComponentType);
var componentType = component.GetType();
var propertyType = AnimationHelper.GetAnimatableProperty(component, track.Property)?.GetType();
if (propertyType is null)
{
Logger.Error($"OH FUCK SEMPAI~~ PROPERTY FOR ANIMATION NOT FOUND: {track.Property} in component: {track.ComponentType}");
continue;
}
var property = new AnimationTrackComponentProperty()
{
ComponentType = componentType,
InterpolationMode = track.InterpolationMode,
Property = track.Property
};
foreach (var key in track.KeyFrames)
{
var value = _serializationManager.Read(propertyType, new ValueDataNode(key.Value));
if (value is null)
{
Logger.Error($"FUCK HARDER, SEMPAI~~ value not found: {key.Value}");
continue;
}
property.KeyFrames.Add(new AnimationTrackProperty.KeyFrame(value, key.KeyTime));
}
animation.AnimationTracks.Add(property);
}
return animation;
}
}