Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Анимации крыльев Нианов #719

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 110 additions & 0 deletions Content.Server/Waving/WavingSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
using Content.Server.Actions;
using Content.Server.Chat.Systems;
using Content.Server.Humanoid;
using Content.Shared.Humanoid;
using Content.Shared.Humanoid.Markings;
using Content.Shared.Mobs;
using Content.Shared.Toggleable;
using Content.Shared.Waving;
using Robust.Shared.Prototypes;

namespace Content.Server.Waving;

/// <summary>
/// Adds an action to toggle waving animation for tails markings that supporting this
/// </summary>
public sealed class WavingSystem : EntitySystem
{
[Dependency] private readonly ActionsSystem _actions = default!;
[Dependency] private readonly ChatSystem _chat = default!;
[Dependency] private readonly HumanoidAppearanceSystem _humanoidAppearance = default!;
[Dependency] private readonly IPrototypeManager _prototype = default!;

public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<WavingComponent, MapInitEvent>(OnWavingMapInit);
SubscribeLocalEvent<WavingComponent, ComponentShutdown>(OnWavingShutdown);
SubscribeLocalEvent<WavingComponent, ToggleActionEvent>(OnWavingToggle);
SubscribeLocalEvent<WavingComponent, MobStateChangedEvent>(OnMobStateChanged);
}

private void OnWavingMapInit(EntityUid uid, WavingComponent component, MapInitEvent args)
{
_actions.AddAction(uid, ref component.ActionEntity, component.Action, uid);
}

private void OnWavingShutdown(EntityUid uid, WavingComponent component, ComponentShutdown args)
{
_actions.RemoveAction(uid, component.ActionEntity);
}

private void OnWavingToggle(EntityUid uid, WavingComponent component, ref ToggleActionEvent args)
{
if (args.Handled)
return;

TryToggleWaving(uid, waving: component);
}

private void OnMobStateChanged(EntityUid uid, WavingComponent component, MobStateChangedEvent args)
{
if (args.NewMobState != MobState.Dead)
return;

if (component.Waving)
TryToggleWaving(uid, waving: component);
}

public bool TryToggleWaving(EntityUid uid, WavingComponent? waving = null, HumanoidAppearanceComponent? humanoid = null)
{
if (!Resolve(uid, ref waving, ref humanoid))
return false;

if (!humanoid.MarkingSet.Markings.TryGetValue(MarkingCategories.Tail, out var markings))
return false;

if (markings.Count == 0)
return false;

waving.Waving = !waving.Waving;

for (var idx = 0; idx < markings.Count; idx++) // Animate all possible tails
{
var currentMarkingId = markings[idx].MarkingId;
string newMarkingId;

if (waving.Waving)
{
newMarkingId = $"{currentMarkingId}{waving.Suffix}";
}
else
{
if (currentMarkingId.EndsWith(waving.Suffix))
{
newMarkingId = currentMarkingId[..^waving.Suffix.Length];
}
else
{
newMarkingId = currentMarkingId;
Log.Warning($"Unable to revert waving for {currentMarkingId}");
}
}

if (!_prototype.HasIndex<MarkingPrototype>(newMarkingId))
{
Log.Warning($"{ToPrettyString(uid)} tried toggling waving but {newMarkingId} marking doesn't exist");
continue;
}

_humanoidAppearance.SetMarkingId(uid, MarkingCategories.Tail, idx, newMarkingId,
humanoid: humanoid);
}

var emoteText = Loc.GetString(waving.Waving ? "waving-emote-start" : "waving-emote-stop", ("ent", uid));
_chat.TrySendInGameICMessage(uid, emoteText, InGameICChatType.Emote, ChatTransmitRange.Normal); // Ok while emotes dont have radial menu

return true;
}
}
33 changes: 33 additions & 0 deletions Content.Shared/Waving/WavingComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using Content.Shared.Chat.Prototypes;
using Robust.Shared.GameStates;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;

namespace Content.Shared.Waving;

/// <summary>
/// An emoting wag for markings.
/// </summary>
[RegisterComponent, NetworkedComponent]
public sealed partial class WavingComponent : Component
{
[DataField]
public EntProtoId Action = "ActionToggleWaving";

[DataField]
public EntityUid? ActionEntity;

[DataField]
public ProtoId<EmotePrototype> EmoteId = "WavTail";

/// <summary>
/// Suffix to add to get the animated marking.
/// </summary>
public string Suffix = "Animated";

/// <summary>
/// Is the entity currently wagging.
/// </summary>
[DataField]
public bool Waving = false;
}
4 changes: 4 additions & 0 deletions Resources/Locale/ru-RU/actions/actions/waving.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
action-name-toggle-waving = Махать крыльями.
action-description-toggle-waving = Начать или прекратить махать крыльями.
waving-emote-start = начинает махать { POSS-ADJ($ent) } крыльями.
waving-emote-stop = прекращает махать { POSS-ADJ($ent) } крыльями.
13 changes: 13 additions & 0 deletions Resources/Prototypes/Actions/types.yml
Original file line number Diff line number Diff line change
Expand Up @@ -341,3 +341,16 @@
itemIconStyle: NoItem
useDelay: 1 # emote spam
event: !type:ToggleActionEvent

- type: entity
id: ActionToggleWaving
name: action-name-toggle-waving
description: action-description-toggle-waving
noSpawn: true
components:
- type: InstantAction
icon: { sprite: Mobs/Customization/Moth/moth_wings.rsi, state: default }
iconOn: { sprite: Mobs/Customization/Moth/moth_wings.rsi, state: default }
itemIconStyle: NoItem
useDelay: 3 # emote spam
event: !type:ToggleActionEvent
2 changes: 1 addition & 1 deletion Resources/Prototypes/Entities/Mobs/Species/moth.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
sprite: "Effects/creampie.rsi"
state: "creampie_moth"
visible: false

- type: Waving
- type: entity
parent: BaseSpeciesDummy
id: MobMothDummy
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
- type: marking
id: MothWingsStripedAnimated
bodyPart: Tail
markingCategory: Tail
speciesRestriction: []
sprites:
- sprite: SS220/Mobs/Customization/moth-anim.rsi
state: tail_striped_wagging
15 changes: 15 additions & 0 deletions Resources/Prototypes/Voice/tail_emotes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,18 @@
- wag tail.
- wags tail
- wags tail.

- type: emote
id: WavTail
chatMessages: [wavs tail]
chatTriggers:
- wav
- wav.
- wavs
- wavs.
- waving
- waving.
- wav tail
- wav tail.
- wavs tail
- wavs tail.
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"version": 1,
"license": "EULA/CLA with a hosting restriction, full text: https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/CLA.txt",
"copyright": "created by OperatorXeno",
"size": {
"x": 32,
"y": 32
},
"states": [
{
"name": "tail_striped_wagging",
"directions": 4,
"delays": [
[
0.15,
0.15,
0.15,
0.15,
0.15,
0.15,
0.15,
0.15,
0.15
],
[
0.15,
0.15,
0.15,
0.15,
0.15,
0.15,
0.15,
0.15,
0.15
],
[
0.15,
0.15,
0.15,
0.15,
0.15,
0.15,
0.15,
0.15,
0.15
],
[
0.15,
0.15,
0.15,
0.15,
0.15,
0.15,
0.15,
0.15,
0.15
]
]
}

]
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading