- add: shared animation
This commit is contained in:
99
Content.Client/_Amour/Animation/SharebleAnimationSystem.cs
Normal file
99
Content.Client/_Amour/Animation/SharebleAnimationSystem.cs
Normal file
@@ -0,0 +1,99 @@
|
||||
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)
|
||||
{
|
||||
Play(GetEntity(ev.Owner),ev.ProtoId);
|
||||
}
|
||||
|
||||
private void OnStart(AnimationStartMessage ev)
|
||||
{
|
||||
Play(GetEntity(ev.Owner),ev.Data,ev.Id);
|
||||
}
|
||||
|
||||
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")
|
||||
{
|
||||
if(_animation.HasRunningAnimation(uid,animationId))
|
||||
return;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -33,9 +33,9 @@ public sealed class VibratorSystem : SharedVibratorSystem
|
||||
|
||||
}
|
||||
|
||||
private Animation GetAnimation()
|
||||
private Robust.Client.Animations.Animation GetAnimation()
|
||||
{
|
||||
return new Animation
|
||||
return new Robust.Client.Animations.Animation
|
||||
{
|
||||
Length = TimeSpan.FromMilliseconds(100),
|
||||
AnimationTracks =
|
||||
|
||||
38
Content.Server/_Amour/Animation/SharebleAnimationSystem.cs
Normal file
38
Content.Server/_Amour/Animation/SharebleAnimationSystem.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using Content.Shared._Amour.Animation;
|
||||
using Content.Shared._Amour.Hole;
|
||||
using Content.Shared.Verbs;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Server._Amour.Animation;
|
||||
|
||||
public sealed class SharebleAnimationSystem : SharedAnimationSystem
|
||||
{
|
||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
SubscribeLocalEvent<HoleContainerComponent,GetVerbsEvent<Verb>>(OnVerb);
|
||||
}
|
||||
|
||||
private void OnVerb(EntityUid uid, HoleContainerComponent component, GetVerbsEvent<Verb> args)
|
||||
{
|
||||
if(!_prototypeManager.TryIndex<AnimationPrototype>("meow",out var prototype))
|
||||
return;
|
||||
|
||||
args.Verbs.Add(new Verb()
|
||||
{
|
||||
Text = "MEOW ABOUT IT",
|
||||
Act = () => Play(uid, prototype)
|
||||
});
|
||||
}
|
||||
|
||||
public override void Play(EntityUid uid, ProtoId<AnimationPrototype> protoId)
|
||||
{
|
||||
RaiseNetworkEvent(new AnimationProtoStartMessage(GetNetEntity(uid),protoId));
|
||||
}
|
||||
|
||||
public override void Play(EntityUid uid, AnimationData data, string animationId = "funny")
|
||||
{
|
||||
RaiseNetworkEvent(new AnimationStartMessage(GetNetEntity(uid),data,animationId));
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,15 @@
|
||||
using System.Numerics;
|
||||
using Content.Server._Amour.Animation;
|
||||
using Content.Shared._Amour.Animation;
|
||||
using Content.Shared._Amour.InteractionPanel;
|
||||
using Content.Shared.Movement.Components;
|
||||
using Robust.Shared.Animations;
|
||||
|
||||
namespace Content.Server._Amour.InteractionPanel;
|
||||
|
||||
public sealed class Interactions : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly SharebleAnimationSystem _animationSystem = default!;
|
||||
public override void Initialize()
|
||||
{
|
||||
SubscribeLocalEvent<InteractionPanelComponent,InteractionBeginningEvent>(OnBegin);
|
||||
@@ -15,8 +21,6 @@ public sealed class Interactions : EntitySystem
|
||||
if(args.Handled)
|
||||
return;
|
||||
|
||||
Logger.Debug(args.Id + " END");
|
||||
|
||||
switch (args.Id)
|
||||
{
|
||||
|
||||
@@ -28,11 +32,41 @@ public sealed class Interactions : EntitySystem
|
||||
if(args.Handled)
|
||||
return;
|
||||
|
||||
Logger.Debug(args.Id + " START");
|
||||
|
||||
switch (args.Id)
|
||||
{
|
||||
|
||||
case "SlapButt":
|
||||
OnSlapButt(uid,component,args);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnSlapButt(EntityUid uid, InteractionPanelComponent component, InteractionBeginningEvent args)
|
||||
{
|
||||
if(!TryComp<InputMoverComponent>(uid,out var moverComponent))
|
||||
return;
|
||||
|
||||
var viewerRot = moverComponent.TargetRelativeRotation;
|
||||
var rotation = (Transform(args.Performer).LocalRotation - viewerRot).ToWorldVec()*0.25f;
|
||||
|
||||
|
||||
_animationSystem.Play(uid,new AnimationData()
|
||||
{
|
||||
Length = TimeSpan.FromSeconds(0.5),
|
||||
AnimationTracks =
|
||||
{
|
||||
new AnimationTrackData()
|
||||
{
|
||||
ComponentType = "SpriteComponent",
|
||||
Property = "Offset",
|
||||
InterpolationMode = AnimationInterpolationMode.Cubic,
|
||||
KeyFrames =
|
||||
{
|
||||
_animationSystem.KeyFrame(Vector2.Zero,0),
|
||||
_animationSystem.KeyFrame(rotation,0.150f),
|
||||
_animationSystem.KeyFrame(Vector2.Zero,0.250f)
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
28
Content.Shared/_Amour/Animation/AnimationData.cs
Normal file
28
Content.Shared/_Amour/Animation/AnimationData.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using Robust.Shared.Animations;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared._Amour.Animation;
|
||||
|
||||
[DataDefinition,Serializable,NetSerializable,Virtual]
|
||||
public partial class AnimationData
|
||||
{
|
||||
[DataField] public TimeSpan Length;
|
||||
[DataField] public List<AnimationTrackData> AnimationTracks;
|
||||
}
|
||||
|
||||
[DataDefinition, Serializable, NetSerializable]
|
||||
public sealed partial class AnimationTrackData
|
||||
{
|
||||
[DataField] public string ComponentType;
|
||||
[DataField] public string Property;
|
||||
[DataField] public AnimationInterpolationMode InterpolationMode;
|
||||
[DataField] public List<AnimationKeyData> KeyFrames;
|
||||
}
|
||||
|
||||
[DataDefinition, Serializable, NetSerializable]
|
||||
public sealed partial class AnimationKeyData
|
||||
{
|
||||
[DataField] public string Value;
|
||||
[DataField] public float KeyTime;
|
||||
}
|
||||
|
||||
32
Content.Shared/_Amour/Animation/AnimationMessages.cs
Normal file
32
Content.Shared/_Amour/Animation/AnimationMessages.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared._Amour.Animation;
|
||||
|
||||
[Serializable,NetSerializable]
|
||||
public sealed class AnimationProtoStartMessage : EntityEventArgs
|
||||
{
|
||||
public NetEntity Owner;
|
||||
public string ProtoId;
|
||||
|
||||
public AnimationProtoStartMessage(NetEntity owner, string protoId)
|
||||
{
|
||||
Owner = owner;
|
||||
ProtoId = protoId;
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable,NetSerializable]
|
||||
public sealed class AnimationStartMessage : EntityEventArgs
|
||||
{
|
||||
public NetEntity Owner;
|
||||
public AnimationData Data;
|
||||
public string Id;
|
||||
|
||||
public AnimationStartMessage(NetEntity owner, AnimationData data, string id)
|
||||
{
|
||||
Owner = owner;
|
||||
Data = data;
|
||||
Id = id;
|
||||
}
|
||||
}
|
||||
10
Content.Shared/_Amour/Animation/AnimationPrototype.cs
Normal file
10
Content.Shared/_Amour/Animation/AnimationPrototype.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared._Amour.Animation;
|
||||
|
||||
[Prototype("animation"),Serializable,NetSerializable]
|
||||
public sealed partial class AnimationPrototype : AnimationData, IPrototype
|
||||
{
|
||||
[IdDataField] public string ID { get; private set; } = default!;
|
||||
}
|
||||
27
Content.Shared/_Amour/Animation/SharedAnimationSystem.cs
Normal file
27
Content.Shared/_Amour/Animation/SharedAnimationSystem.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization.Manager;
|
||||
using Robust.Shared.Serialization.Markdown.Value;
|
||||
|
||||
namespace Content.Shared._Amour.Animation;
|
||||
|
||||
public abstract class SharedAnimationSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly ISerializationManager _serializationManager = default!;
|
||||
|
||||
public virtual void Play(EntityUid uid,ProtoId<AnimationPrototype> protoId)
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void Play(EntityUid uid,AnimationData data, string animationId = "funny")
|
||||
{
|
||||
}
|
||||
|
||||
public AnimationKeyData KeyFrame(object value, float keyTime)
|
||||
{
|
||||
return new AnimationKeyData()
|
||||
{
|
||||
KeyTime = keyTime,
|
||||
Value = _serializationManager.WriteValueAs<ValueDataNode>(value).Value
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -267,7 +267,7 @@
|
||||
- type: Arousal
|
||||
- type: InteractionPanel
|
||||
actionPrototypes:
|
||||
- basic
|
||||
- SlapButt
|
||||
|
||||
- type: entity
|
||||
save: false
|
||||
|
||||
28
Resources/Prototypes/_Amour/AnimationTracks/meow.yml
Normal file
28
Resources/Prototypes/_Amour/AnimationTracks/meow.yml
Normal file
@@ -0,0 +1,28 @@
|
||||
- type: animation
|
||||
id: meow
|
||||
length: 1
|
||||
animationTracks:
|
||||
- componentType: Sprite
|
||||
property: Scale
|
||||
interpolationMode: Linear
|
||||
keyFrames:
|
||||
- keyTime: 0
|
||||
value: 1,1
|
||||
- keyTime: 0.2
|
||||
value: 1.5,1.5
|
||||
- keyTime: 0.3
|
||||
value: 0.25,0.25
|
||||
- keyTime: 0.3
|
||||
value: 1,1
|
||||
- componentType: Sprite
|
||||
property: Rotation
|
||||
interpolationMode: Linear
|
||||
keyFrames:
|
||||
- keyTime: 0
|
||||
value: 15
|
||||
- keyTime: 0.2
|
||||
value: 45
|
||||
- keyTime: 0.3
|
||||
value: 90
|
||||
- keyTime: 0.3
|
||||
value: 0
|
||||
@@ -1,6 +1,6 @@
|
||||
- type: interaction
|
||||
id: basic
|
||||
id: SlapButt
|
||||
checks:
|
||||
- !type:HasSmallDistance
|
||||
beginningMessages:
|
||||
- шлёпает по попе
|
||||
- interaction-butt-slap
|
||||
|
||||
Reference in New Issue
Block a user