-
Notifications
You must be signed in to change notification settings - Fork 372
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
274 additions
and
1 deletion.
There are no files selected for viewing
137 changes: 137 additions & 0 deletions
137
Content.Client/_Goobstation/Emoting/AnimatedEmotesSystem.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,137 @@ | ||
using Robust.Client.Animations; | ||
using Robust.Shared.Animations; | ||
using Robust.Shared.GameStates; | ||
using Robust.Client.GameObjects; | ||
using Content.Shared.Emoting; | ||
using System.Numerics; | ||
using Robust.Shared.Prototypes; | ||
using Content.Shared.Chat.Prototypes; | ||
using Content.Shared.Rotation; | ||
|
||
namespace Content.Client.Emoting; | ||
|
||
public sealed partial class AnimatedEmotesSystem : SharedAnimatedEmotesSystem | ||
{ | ||
[Dependency] private readonly AnimationPlayerSystem _anim = default!; | ||
[Dependency] private readonly AppearanceSystem _appearance = default!; | ||
[Dependency] private readonly IPrototypeManager _prot = default!; | ||
|
||
public override void Initialize() | ||
{ | ||
base.Initialize(); | ||
|
||
SubscribeLocalEvent<AnimatedEmotesComponent, ComponentHandleState>(OnHandleState); | ||
|
||
SubscribeLocalEvent<AnimatedEmotesComponent, AnimationFlipEmoteEvent>(OnFlip); | ||
SubscribeLocalEvent<AnimatedEmotesComponent, AnimationSpinEmoteEvent>(OnSpin); | ||
SubscribeLocalEvent<AnimatedEmotesComponent, AnimationJumpEmoteEvent>(OnJump); | ||
} | ||
|
||
public void PlayEmote(EntityUid uid, Animation anim, string animationKey = "emoteAnimKeyId") | ||
{ | ||
if (_anim.HasRunningAnimation(uid, animationKey)) | ||
return; | ||
|
||
_anim.Play(uid, anim, animationKey); | ||
} | ||
|
||
private void OnHandleState(EntityUid uid, AnimatedEmotesComponent component, ref ComponentHandleState args) | ||
{ | ||
if (args.Current is not AnimatedEmotesComponentState state | ||
|| !_prot.TryIndex<EmotePrototype>(state.Emote, out var emote)) | ||
return; | ||
|
||
if (emote.Event != null) | ||
RaiseLocalEvent(uid, emote.Event); | ||
} | ||
|
||
private void OnFlip(Entity<AnimatedEmotesComponent> ent, ref AnimationFlipEmoteEvent args) | ||
{ | ||
var angle = Angle.Zero; | ||
|
||
if (TryComp<RotationVisualsComponent>(ent, out var rotation)) | ||
{ | ||
_appearance.TryGetData<RotationState>(ent, RotationVisuals.RotationState, out var state); | ||
|
||
angle = state switch | ||
{ | ||
RotationState.Vertical => rotation.VerticalRotation, | ||
RotationState.Horizontal => rotation.HorizontalRotation, | ||
_ => Angle.Zero | ||
}; | ||
} | ||
|
||
var a = new Animation | ||
{ | ||
Length = TimeSpan.FromMilliseconds(500), | ||
AnimationTracks = | ||
{ | ||
new AnimationTrackComponentProperty | ||
{ | ||
ComponentType = typeof(SpriteComponent), | ||
Property = nameof(SpriteComponent.Rotation), | ||
InterpolationMode = AnimationInterpolationMode.Linear, | ||
KeyFrames = | ||
{ | ||
new AnimationTrackProperty.KeyFrame(angle, 0f), | ||
new AnimationTrackProperty.KeyFrame(angle + Angle.FromDegrees(180), 0.25f), | ||
new AnimationTrackProperty.KeyFrame(angle + Angle.FromDegrees(360), 0.25f), | ||
} | ||
} | ||
} | ||
}; | ||
PlayEmote(ent, a); | ||
} | ||
private void OnSpin(Entity<AnimatedEmotesComponent> ent, ref AnimationSpinEmoteEvent args) | ||
{ | ||
var a = new Animation | ||
{ | ||
Length = TimeSpan.FromMilliseconds(600), | ||
AnimationTracks = | ||
{ | ||
new AnimationTrackComponentProperty | ||
{ | ||
ComponentType = typeof(TransformComponent), | ||
Property = nameof(TransformComponent.LocalRotation), | ||
InterpolationMode = AnimationInterpolationMode.Linear, | ||
KeyFrames = | ||
{ | ||
new AnimationTrackProperty.KeyFrame(Angle.FromDegrees(0), 0f), | ||
new AnimationTrackProperty.KeyFrame(Angle.FromDegrees(90), 0.075f), | ||
new AnimationTrackProperty.KeyFrame(Angle.FromDegrees(180), 0.075f), | ||
new AnimationTrackProperty.KeyFrame(Angle.FromDegrees(270), 0.075f), | ||
new AnimationTrackProperty.KeyFrame(Angle.Zero, 0.075f), | ||
new AnimationTrackProperty.KeyFrame(Angle.FromDegrees(90), 0.075f), | ||
new AnimationTrackProperty.KeyFrame(Angle.FromDegrees(180), 0.075f), | ||
new AnimationTrackProperty.KeyFrame(Angle.FromDegrees(270), 0.075f), | ||
new AnimationTrackProperty.KeyFrame(Angle.Zero, 0.075f), | ||
} | ||
} | ||
} | ||
}; | ||
PlayEmote(ent, a, "emoteAnimSpin"); | ||
} | ||
private void OnJump(Entity<AnimatedEmotesComponent> ent, ref AnimationJumpEmoteEvent args) | ||
{ | ||
var a = new Animation | ||
{ | ||
Length = TimeSpan.FromMilliseconds(250), | ||
AnimationTracks = | ||
{ | ||
new AnimationTrackComponentProperty | ||
{ | ||
ComponentType = typeof(SpriteComponent), | ||
Property = nameof(SpriteComponent.Offset), | ||
InterpolationMode = AnimationInterpolationMode.Cubic, | ||
KeyFrames = | ||
{ | ||
new AnimationTrackProperty.KeyFrame(Vector2.Zero, 0f), | ||
new AnimationTrackProperty.KeyFrame(new Vector2(0, .35f), 0.125f), | ||
new AnimationTrackProperty.KeyFrame(Vector2.Zero, 0.125f), | ||
} | ||
} | ||
} | ||
}; | ||
PlayEmote(ent, a); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
Content.Server/_Goobstation/Emoting/AnimatedEmotesSystem.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,28 @@ | ||
using Robust.Shared.GameStates; | ||
using Content.Server.Chat.Systems; | ||
using Content.Shared.Chat.Prototypes; | ||
using Content.Shared.Emoting; | ||
using Robust.Shared.Prototypes; | ||
|
||
namespace Content.Server.Emoting; | ||
|
||
public sealed partial class AnimatedEmotesSystem : SharedAnimatedEmotesSystem | ||
{ | ||
public override void Initialize() | ||
{ | ||
base.Initialize(); | ||
|
||
SubscribeLocalEvent<AnimatedEmotesComponent, EmoteEvent>(OnEmote); | ||
} | ||
|
||
private void OnEmote(EntityUid uid, AnimatedEmotesComponent component, ref EmoteEvent args) | ||
{ | ||
PlayEmoteAnimation(uid, component, args.Emote.ID); | ||
} | ||
|
||
public void PlayEmoteAnimation(EntityUid uid, AnimatedEmotesComponent component, ProtoId<EmotePrototype> prot) | ||
{ | ||
component.Emote = prot; | ||
Dirty(uid, component); | ||
} | ||
} |
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
28 changes: 28 additions & 0 deletions
28
Content.Shared/_Goobstation/Emoting/AnimatedEmotesComponent.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,28 @@ | ||
using Content.Shared.Chat.Prototypes; | ||
using Robust.Shared.GameStates; | ||
using Robust.Shared.Prototypes; | ||
using Robust.Shared.Serialization; | ||
|
||
namespace Content.Shared.Emoting; | ||
|
||
// use as a template | ||
//[Serializable, NetSerializable, DataDefinition] public sealed partial class AnimationNameEmoteEvent : EntityEventArgs { } | ||
|
||
[Serializable, NetSerializable, DataDefinition] public sealed partial class AnimationFlipEmoteEvent : EntityEventArgs { } | ||
[Serializable, NetSerializable, DataDefinition] public sealed partial class AnimationSpinEmoteEvent : EntityEventArgs { } | ||
[Serializable, NetSerializable, DataDefinition] public sealed partial class AnimationJumpEmoteEvent : EntityEventArgs { } | ||
|
||
[RegisterComponent, NetworkedComponent] public sealed partial class AnimatedEmotesComponent : Component | ||
{ | ||
[DataField] public ProtoId<EmotePrototype>? Emote; | ||
} | ||
|
||
[Serializable, NetSerializable] public sealed partial class AnimatedEmotesComponentState : ComponentState | ||
{ | ||
public ProtoId<EmotePrototype>? Emote; | ||
|
||
public AnimatedEmotesComponentState(ProtoId<EmotePrototype>? emote) | ||
{ | ||
Emote = emote; | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
Content.Shared/_Goobstation/Emoting/SharedAnimatedEmotesSystem.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,18 @@ | ||
using Robust.Shared.GameStates; | ||
|
||
namespace Content.Shared.Emoting; | ||
|
||
public abstract class SharedAnimatedEmotesSystem : EntitySystem | ||
{ | ||
public override void Initialize() | ||
{ | ||
base.Initialize(); | ||
|
||
SubscribeLocalEvent<AnimatedEmotesComponent, ComponentGetState>(OnGetState); | ||
} | ||
|
||
private void OnGetState(Entity<AnimatedEmotesComponent> ent, ref ComponentGetState args) | ||
{ | ||
args.State = new AnimatedEmotesComponentState(ent.Comp.Emote); | ||
} | ||
} |
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,7 @@ | ||
|
||
chat-emote-name-flip = Do a flip | ||
chat-emote-name-spin = Spin | ||
chat-emote-name-jump = Jump | ||
chat-emote-msg-flip = does a flip! | ||
chat-emote-msg-spin = spins! | ||
chat-emote-msg-jump = jumps! |
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
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,42 @@ | ||
- type: emote | ||
id: Flip | ||
name: chat-emote-name-flip | ||
chatMessages: ["chat-emote-msg-flip"] | ||
icon: _Impstation/Interface/Emotes/backflip.png #imp | ||
chatTriggers: | ||
- flip | ||
- flips | ||
- flips. | ||
- flips! | ||
- does a flip | ||
- does a flip. | ||
- does a flip! | ||
event: !type:AnimationFlipEmoteEvent | ||
|
||
- type: emote | ||
id: Spin | ||
name: chat-emote-name-spin | ||
chatMessages: ["chat-emote-msg-spin"] | ||
icon: _Impstation/Interface/Emotes/spin.png #imp | ||
chatTriggers: | ||
- spin | ||
- spins | ||
- spins. | ||
- spins! | ||
event: !type:AnimationSpinEmoteEvent | ||
|
||
- type: emote | ||
id: Jump | ||
name: chat-emote-name-jump | ||
chatMessages: ["chat-emote-msg-jump"] | ||
icon: _Impstation/Interface/Emotes/jump.png #imp | ||
chatTriggers: | ||
- jump | ||
- jumps | ||
- jumps. | ||
- jumps! | ||
- bounce | ||
- bounces | ||
- bounces. | ||
- bounces! | ||
event: !type:AnimationJumpEmoteEvent |
7 changes: 7 additions & 0 deletions
7
Resources/Textures/_Impstation/Interface/Emotes/attributions.yml
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,7 @@ | ||
- files: | ||
- backflip.png | ||
- jump.png | ||
- spin.png | ||
license: "CC-BY-SA-4.0" | ||
copyright: "Created by Carousel for Impstation" | ||
source: "https://github.com/impstation/imp-station-14" |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.