From d1a0f5f09ed1ca6f470104fab21b8f14b6dacdf1 Mon Sep 17 00:00:00 2001 From: HerCoyote23 <131214189+HerCoyote23@users.noreply.github.com> Date: Tue, 30 May 2023 10:57:53 -0700 Subject: [PATCH] Set max length of battlecry to 12 chars. (#16958) * Set max length of battlecry to 12 chars. Deleted a duplicate file. * Also cleanup some leftovers --- .../Speech/EntitySystems/MeleeSpeechSystem.cs | 18 ++++++++++++++---- .../Speech/Components/MeleeSpeechComponent.cs | 6 ++++-- .../EntitySystems/SharedMeleeSpeechSystem.cs | 2 +- .../Weapons/Melee/SharedMeleeSpeechSystem.cs | 7 ------- 4 files changed, 19 insertions(+), 14 deletions(-) delete mode 100644 Content.Shared/Weapons/Melee/SharedMeleeSpeechSystem.cs diff --git a/Content.Server/Speech/EntitySystems/MeleeSpeechSystem.cs b/Content.Server/Speech/EntitySystems/MeleeSpeechSystem.cs index 95fcf8f2d1..65cde8f8f4 100644 --- a/Content.Server/Speech/EntitySystems/MeleeSpeechSystem.cs +++ b/Content.Server/Speech/EntitySystems/MeleeSpeechSystem.cs @@ -1,6 +1,6 @@ using Content.Server.Administration.Logs; using Content.Shared.Speech.Components; -using Content.Shared.Weapons.Melee; +using Content.Shared.Speech.EntitySystems; using Content.Shared.Database; @@ -22,10 +22,15 @@ public sealed class MeleeSpeechSystem : SharedMeleeSpeechSystem private void OnBattlecryChanged(EntityUid uid, MeleeSpeechComponent comp, MeleeSpeechBattlecryChangedMessage args) { - if (!TryComp(uid, out var meleeSpeechUser)) + if (!TryComp(uid, out var meleeSpeechUser)) return; - TryChangeBattlecry(uid, args.Battlecry, meleeSpeechUser); + string battlecry = args.Battlecry; + + if (battlecry.Length > comp.MaxBattlecryLength) + battlecry = battlecry[..comp.MaxBattlecryLength]; + + TryChangeBattlecry(uid, battlecry, meleeSpeechUser); } @@ -41,12 +46,14 @@ public sealed class MeleeSpeechSystem : SharedMeleeSpeechSystem public bool TryChangeBattlecry(EntityUid uid, string? battlecry, MeleeSpeechComponent? meleeSpeechComp = null) { - if (!Resolve(uid, ref meleeSpeechComp)) + if (!Resolve(uid, ref meleeSpeechComp)) return false; if (!string.IsNullOrWhiteSpace(battlecry)) { battlecry = battlecry.Trim(); + + } else { @@ -56,6 +63,9 @@ public sealed class MeleeSpeechSystem : SharedMeleeSpeechSystem if (meleeSpeechComp.Battlecry == battlecry) return true; + + + meleeSpeechComp.Battlecry = battlecry; Dirty(meleeSpeechComp); diff --git a/Content.Shared/Speech/Components/MeleeSpeechComponent.cs b/Content.Shared/Speech/Components/MeleeSpeechComponent.cs index 25815f1d84..060d44974d 100644 --- a/Content.Shared/Speech/Components/MeleeSpeechComponent.cs +++ b/Content.Shared/Speech/Components/MeleeSpeechComponent.cs @@ -5,15 +5,17 @@ namespace Content.Shared.Speech.Components; [RegisterComponent] [AutoGenerateComponentState] -[Access(typeof(SharedMeleeSpeechSystem), Other = AccessPermissions.ReadWrite)] public sealed partial class MeleeSpeechComponent : Component { [ViewVariables(VVAccess.ReadWrite)] [DataField("Battlecry")] [AutoNetworkedField] - [Access(typeof(SharedMeleeSpeechSystem), Other = AccessPermissions.ReadWrite)] public string? Battlecry; + + [ViewVariables(VVAccess.ReadWrite)] + [DataField("MaxBattlecryLength")] + public int MaxBattlecryLength = 12; } /// diff --git a/Content.Shared/Speech/EntitySystems/SharedMeleeSpeechSystem.cs b/Content.Shared/Speech/EntitySystems/SharedMeleeSpeechSystem.cs index 4713ab3c5e..21841ef0ac 100644 --- a/Content.Shared/Speech/EntitySystems/SharedMeleeSpeechSystem.cs +++ b/Content.Shared/Speech/EntitySystems/SharedMeleeSpeechSystem.cs @@ -1,6 +1,6 @@ using Robust.Shared.Serialization; -namespace Content.Shared.Weapons.Melee; +namespace Content.Shared.Speech.EntitySystems; public abstract class SharedMeleeSpeechSystem : EntitySystem { diff --git a/Content.Shared/Weapons/Melee/SharedMeleeSpeechSystem.cs b/Content.Shared/Weapons/Melee/SharedMeleeSpeechSystem.cs deleted file mode 100644 index 21841ef0ac..0000000000 --- a/Content.Shared/Weapons/Melee/SharedMeleeSpeechSystem.cs +++ /dev/null @@ -1,7 +0,0 @@ -using Robust.Shared.Serialization; - -namespace Content.Shared.Speech.EntitySystems; - -public abstract class SharedMeleeSpeechSystem : EntitySystem -{ -}