From a009a8fae3b7d5f084781d3695d7ee45bf724227 Mon Sep 17 00:00:00 2001 From: Remuchi Date: Fri, 26 Jan 2024 16:35:45 +0700 Subject: [PATCH] =?UTF-8?q?fix:=20=D1=87=D0=B0=D1=81=D1=82=D0=B8=D1=87?= =?UTF-8?q?=D0=BD=D1=8B=D0=B9=20=D1=84=D0=B8=D0=BA=D1=81=20=D1=8D=D0=BC?= =?UTF-8?q?=D0=BE=D1=83=D1=82=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../White/Animations/EmoteAnimationSystem.cs | 55 ++++++++++--------- .../White/Animations/DancingComponent.cs | 2 +- .../White/Animations/DancingSystem.cs | 7 +-- .../White/Animations/EmoteAnimationSystem.cs | 46 +--------------- .../AspectsSystem/Aspects/DancingAspect.cs | 10 +++- .../Animations/EmoteAnimationComponent.cs | 12 ++-- .../Locale/ru-RU/white/actions/emotes.ftl | 6 -- Resources/Prototypes/White/Actions/emotes.yml | 37 ------------- 8 files changed, 45 insertions(+), 130 deletions(-) delete mode 100644 Resources/Locale/ru-RU/white/actions/emotes.ftl diff --git a/Content.Client/White/Animations/EmoteAnimationSystem.cs b/Content.Client/White/Animations/EmoteAnimationSystem.cs index 6828789c07..1083c2ef29 100644 --- a/Content.Client/White/Animations/EmoteAnimationSystem.cs +++ b/Content.Client/White/Animations/EmoteAnimationSystem.cs @@ -1,16 +1,22 @@ +using Content.Shared.White.Animations; using System.Numerics; -using Content.Shared.Animations; using Robust.Client.Animations; +using Robust.Client.GameObjects; using Robust.Shared.Animations; using Robust.Shared.GameStates; -using Robust.Client.GameObjects; -using static Content.Shared.Animations.EmoteAnimationComponent; -namespace Content.Client.Animations; +using static Content.Shared.White.Animations.EmoteAnimationComponent; -public class EmoteAnimationSystem : EntitySystem +namespace Content.Client.White.Animations; + +public sealed class EmoteAnimationSystem : EntitySystem { [Dependency] private readonly AnimationPlayerSystem _animationSystem = default!; + private readonly Dictionary> _emoteList = new(); + + private const string AnimationKey = "emoteAnimationKeyId"; + private const string AnimationKeyTurn = "emoteAnimationKeyId_rotate"; + //OnVerbsResponse?.Invoke(msg); public override void Initialize() { @@ -19,16 +25,13 @@ public class EmoteAnimationSystem : EntitySystem // EmoteFlip animation _emoteList.Add("EmoteFlip", uid => { - var animationKey = "emoteAnimationKeyId"; - - if (_animationSystem.HasRunningAnimation(uid, animationKey)) + if (_animationSystem.HasRunningAnimation(uid, AnimationKey)) return; var baseAngle = Angle.Zero; if (EntityManager.TryGetComponent(uid, out SpriteComponent? sprite)) { - if (sprite != null) - baseAngle = sprite.Rotation; + baseAngle = sprite.Rotation; } var animation = new Animation @@ -43,7 +46,7 @@ public class EmoteAnimationSystem : EntitySystem InterpolationMode = AnimationInterpolationMode.Linear, KeyFrames = { - new AnimationTrackProperty.KeyFrame(Angle.FromDegrees(baseAngle.Degrees), 0f), + new AnimationTrackProperty.KeyFrame(Angle.FromDegrees(baseAngle.Degrees - 10), 0f), new AnimationTrackProperty.KeyFrame(Angle.FromDegrees(baseAngle.Degrees + 180), 0.25f), new AnimationTrackProperty.KeyFrame(Angle.FromDegrees(baseAngle.Degrees + 360), 0.25f), new AnimationTrackProperty.KeyFrame(Angle.FromDegrees(baseAngle.Degrees), 0f), @@ -52,14 +55,13 @@ public class EmoteAnimationSystem : EntitySystem } }; - _animationSystem.Play(uid, animation, animationKey); + _animationSystem.Play(uid, animation, AnimationKey); }); - // EmoteJump animation - _emoteList.Add("EmoteJump", (EntityUid uid) => - { - var animationKey = "emoteAnimationKeyId"; - if (_animationSystem.HasRunningAnimation(uid, animationKey)) + // EmoteJump animation + _emoteList.Add("EmoteJump", uid => + { + if (_animationSystem.HasRunningAnimation(uid, AnimationKey)) return; var animation = new Animation @@ -82,19 +84,18 @@ public class EmoteAnimationSystem : EntitySystem } }; - _animationSystem.Play(uid, animation, animationKey); + _animationSystem.Play(uid, animation, AnimationKey); }); - // EmoteTurn animation - _emoteList.Add("EmoteTurn", (EntityUid uid) => - { - var animationKey = "emoteAnimationKeyId_rotate"; // it needs for only rotate anim - if (_animationSystem.HasRunningAnimation(uid, animationKey)) + // EmoteTurn animation + _emoteList.Add("EmoteTurn", uid => + { + if (_animationSystem.HasRunningAnimation(uid, AnimationKeyTurn)) return; var animation = new Animation { - Length = TimeSpan.FromMilliseconds(600), // Пока пусть на 0.6 секунд. В идеале бы до 0.9 на 3 поворота + Length = TimeSpan.FromMilliseconds(900), AnimationTracks = { new AnimationTrackComponentProperty @@ -118,7 +119,7 @@ public class EmoteAnimationSystem : EntitySystem } }; - _animationSystem.Play(uid, animation, animationKey); + _animationSystem.Play(uid, animation, AnimationKeyTurn); }); } @@ -128,9 +129,9 @@ public class EmoteAnimationSystem : EntitySystem return; component.AnimationId = state.AnimationId; - if (_emoteList.ContainsKey(component.AnimationId)) + if (_emoteList.TryGetValue(component.AnimationId, out var value)) { - _emoteList[component.AnimationId].Invoke(uid); + value.Invoke(uid); } } } diff --git a/Content.Server/White/Animations/DancingComponent.cs b/Content.Server/White/Animations/DancingComponent.cs index 7e278319f0..8183500bc3 100644 --- a/Content.Server/White/Animations/DancingComponent.cs +++ b/Content.Server/White/Animations/DancingComponent.cs @@ -1,4 +1,4 @@ -namespace Content.Server.Animations; +namespace Content.Server.White.Animations; [RegisterComponent] public sealed partial class DancingComponent : Component diff --git a/Content.Server/White/Animations/DancingSystem.cs b/Content.Server/White/Animations/DancingSystem.cs index 0d9a4e0c5f..8f0e82a03a 100644 --- a/Content.Server/White/Animations/DancingSystem.cs +++ b/Content.Server/White/Animations/DancingSystem.cs @@ -1,11 +1,10 @@ -using Content.Server.White.Animations; -using Content.Shared.Animations; using Content.Shared.Bed.Sleep; using Content.Shared.Mobs.Components; using Content.Shared.Mobs.Systems; +using Content.Shared.White.Animations; using Robust.Shared.Random; -namespace Content.Server.Animations; +namespace Content.Server.White.Animations; public sealed class DancingSystem : EntitySystem { @@ -13,7 +12,7 @@ public sealed class DancingSystem : EntitySystem [Dependency] private readonly EmoteAnimationSystem _emoteAnimation = default!; [Dependency] private readonly MobStateSystem _mobState = default!; - private readonly string[] _emoteList = {"EmoteFlip", "EmoteTurn"}; + private readonly string[] _emoteList = { "EmoteFlip", "EmoteTurn" }; public override void Initialize() { diff --git a/Content.Server/White/Animations/EmoteAnimationSystem.cs b/Content.Server/White/Animations/EmoteAnimationSystem.cs index 0eadeb1e44..1ccd2b12d5 100644 --- a/Content.Server/White/Animations/EmoteAnimationSystem.cs +++ b/Content.Server/White/Animations/EmoteAnimationSystem.cs @@ -1,31 +1,17 @@ -using Content.Server.Actions; using Content.Server.Chat.Systems; -using Content.Shared.Animations; using Content.Shared.Chat.Prototypes; +using Content.Shared.White.Animations; using Robust.Shared.GameStates; -using Robust.Shared.Prototypes; -using static Content.Shared.Animations.EmoteAnimationComponent; +using static Content.Shared.White.Animations.EmoteAnimationComponent; namespace Content.Server.White.Animations; public sealed class EmoteAnimationSystem : EntitySystem { - [Dependency] private readonly ActionsSystem _action = default!; - [Dependency] private readonly IPrototypeManager _proto = default!; - - /// - /// We write 'EmoteAction' word before id name for instant action. - /// Example: EmoteActionJump, EmoteActionFlip and etc. - /// - private const string InstantIdentifier = "EmoteAction"; - public override void Initialize() { SubscribeLocalEvent(OnGetState); - SubscribeLocalEvent(OnMapInint); - SubscribeLocalEvent(OnShutdown); SubscribeLocalEvent(OnEmote); - SubscribeLocalEvent(OnEmoteAction); } private void OnGetState(EntityUid uid, EmoteAnimationComponent component, ref ComponentGetState args) @@ -33,28 +19,6 @@ public sealed class EmoteAnimationSystem : EntitySystem args.State = new EmoteAnimationComponentState(component.AnimationId); } - private void OnMapInint(EntityUid uid, EmoteAnimationComponent component, MapInitEvent args) - { - foreach (var item in _proto.EnumeratePrototypes()) - { - if (item.ID.Length <= InstantIdentifier.Length || - item.ID[..InstantIdentifier.Length] != InstantIdentifier) - continue; - - EntityUid? action = null; - component.Actions.Add(action); - _action.AddAction(uid, ref action, item.ID); - } - } - - private void OnShutdown(EntityUid uid, EmoteAnimationComponent component, ComponentShutdown args) - { - foreach (var item in component.Actions) - { - _action.RemoveAction(uid, item); - } - } - private void OnEmote(EntityUid uid, EmoteAnimationComponent component, ref EmoteEvent args) { if (args.Handled || !args.Emote.Category.HasFlag(EmoteCategory.Gesture)) @@ -63,12 +27,6 @@ public sealed class EmoteAnimationSystem : EntitySystem PlayEmoteAnimation(uid, component, args.Emote.ID); } - private void OnEmoteAction(EntityUid uid, EmoteAnimationComponent component, EmoteActionEvent args) - { - PlayEmoteAnimation(uid, component, args.Emote); - args.Handled = true; - } - public void PlayEmoteAnimation(EntityUid uid, EmoteAnimationComponent component, string emoteId) { component.AnimationId = emoteId; diff --git a/Content.Server/White/AspectsSystem/Aspects/DancingAspect.cs b/Content.Server/White/AspectsSystem/Aspects/DancingAspect.cs index 0e6c890462..5822520fe4 100644 --- a/Content.Server/White/AspectsSystem/Aspects/DancingAspect.cs +++ b/Content.Server/White/AspectsSystem/Aspects/DancingAspect.cs @@ -1,10 +1,10 @@ -using Content.Server.Animations; using Content.Server.GameTicking; using Content.Server.GameTicking.Rules.Components; +using Content.Server.White.Animations; using Content.Server.White.AspectsSystem.Aspects.Components; using Content.Server.White.AspectsSystem.Base; -using Content.Shared.Animations; using Content.Shared.Mobs.Components; +using Content.Shared.White.Animations; namespace Content.Server.White.AspectsSystem.Aspects; @@ -16,7 +16,11 @@ public sealed class DancingAspect : AspectSystem SubscribeLocalEvent(HandleLateJoin); } - protected override void Started(EntityUid uid, DancingAspectComponent component, GameRuleComponent gameRule, GameRuleStartedEvent args) + protected override void Started( + EntityUid uid, + DancingAspectComponent component, + GameRuleComponent gameRule, + GameRuleStartedEvent args) { base.Started(uid, component, gameRule, args); var query = EntityQueryEnumerator(); diff --git a/Content.Shared/White/Animations/EmoteAnimationComponent.cs b/Content.Shared/White/Animations/EmoteAnimationComponent.cs index 4e6e18de49..76ff6a8c34 100644 --- a/Content.Shared/White/Animations/EmoteAnimationComponent.cs +++ b/Content.Shared/White/Animations/EmoteAnimationComponent.cs @@ -2,29 +2,25 @@ using Content.Shared.Actions; using Robust.Shared.GameStates; using Robust.Shared.Serialization; -namespace Content.Shared.Animations; +namespace Content.Shared.White.Animations; /// /// Event for playing animations /// public sealed partial class EmoteActionEvent : InstantActionEvent { - [ViewVariables] - [DataField("emote", readOnly: true, required: true)] + [ViewVariables, DataField("emote", readOnly: true, required: true)] public string Emote = default!; }; -[RegisterComponent] -[NetworkedComponent] +[RegisterComponent, NetworkedComponent] public sealed partial class EmoteAnimationComponent : Component { [ViewVariables(VVAccess.ReadWrite)] public string AnimationId = "none"; - public readonly List Actions = new(); - [Serializable, NetSerializable] - public class EmoteAnimationComponentState : ComponentState + public partial class EmoteAnimationComponentState : ComponentState { public string AnimationId { get; init; } diff --git a/Resources/Locale/ru-RU/white/actions/emotes.ftl b/Resources/Locale/ru-RU/white/actions/emotes.ftl deleted file mode 100644 index f6cdedb653..0000000000 --- a/Resources/Locale/ru-RU/white/actions/emotes.ftl +++ /dev/null @@ -1,6 +0,0 @@ -emote-flip-action-name = Сальто -emote-flip-action-description = Сделать крутой акработический трюк! -emote-jump-action-name = Подпрыгнуть -emote-jump-action-description = Подпрыгни из-за радости или испуга от мыши. -emote-turn-action-name = Танцевать -emote-turn-action-description = You spin me right round baby... diff --git a/Resources/Prototypes/White/Actions/emotes.yml b/Resources/Prototypes/White/Actions/emotes.yml index 9ab52fc333..2141500500 100644 --- a/Resources/Prototypes/White/Actions/emotes.yml +++ b/Resources/Prototypes/White/Actions/emotes.yml @@ -1,40 +1,3 @@ -# flip animation -- type: entity - id: EmoteActionFlip - name: emote-flip-action-name - description: emote-flip-action-description - noSpawn: true - components: - - type: InstantAction - icon: White/Actions/EmoteFlip.png - event: !type:EmoteActionEvent - emote: EmoteFlip - -# jump animation -- type: entity - id: EmoteActionJump - name: emote-jump-action-name - description: emote-jump-action-description - noSpawn: true - components: - - type: InstantAction - icon: White/Actions/EmoteJump.png - event: !type:EmoteActionEvent - emote: EmoteJump - - # turn around in 4 directions animation -- type: entity - id: EmoteActionTurn - name: emote-turn-action-name - description: emote-turn-action-description - noSpawn: true - components: - - type: InstantAction - icon: White/Actions/EmoteTurn.png - event: !type:EmoteActionEvent - emote: EmoteTurn - - # Using EmoteAnimation from IC action chat - type: emote id: EmoteFlip