]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
ringer bugfixes (#36936)
authorMilon <milonpl.git@proton.me>
Tue, 29 Apr 2025 17:08:23 +0000 (19:08 +0200)
committerGitHub <noreply@github.com>
Tue, 29 Apr 2025 17:08:23 +0000 (19:08 +0200)
AAAAAAAAAA

Content.Client/PDA/Ringer/RingtoneMenu.xaml.cs
Content.Server/PDA/Ringer/RingerSystem.cs
Content.Shared/PDA/Ringer/RingerUplinkComponent.cs
Content.Shared/PDA/SharedRingerSystem.cs

index 989fe658430344211bc38f32a70a0dd30bab7e75..83024c22fb94ad4ac86258db196cea5d3084b413 100644 (file)
@@ -1,3 +1,4 @@
+using System.Linq;
 using System.Numerics;
 using Content.Client.UserInterface.Controls;
 using Robust.Client.AutoGenerated;
@@ -29,48 +30,47 @@ namespace Content.Client.PDA.Ringer
             {
                 var input = RingerNoteInputs[i];
                 var index = i;
-                var foo = () => // Prevents unauthorized characters from being entered into the LineEdit
+
+                input.OnTextChanged += args =>
                 {
-                    input.Text = input.Text.ToUpper();
+                    if (input.Text.Length <= 0)
+                        return;
 
-                    if (!IsNote(input.Text))
+                    input.Text = args.Text.ToUpper();
+
+                    var isValid = IsNote(input.Text);
+
+                    if (!isValid)
                     {
                         input.Text = PreviousNoteInputs[index];
+                        input.AddStyleClass("Caution");
                     }
                     else
+                    {
                         PreviousNoteInputs[index] = input.Text;
+                        input.RemoveStyleClass("Caution");
+                    }
 
-                    input.RemoveStyleClass("Caution");
+                    input.CursorPosition = input.Text.Length;
                 };
 
-                input.OnFocusExit += _ => foo();
-                input.OnTextEntered += _ =>
+                input.OnFocusExit += _ =>
                 {
-                    foo();
-                    input.CursorPosition = input.Text.Length; // Resets caret position to the end of the typed input
+                    if (!IsNote(input.Text))
+                    {
+                        input.Text = PreviousNoteInputs[index];
+                        input.RemoveStyleClass("Caution");
+                    }
                 };
 
-                input.OnTextChanged += args =>
+                input.OnTextEntered += _ =>
                 {
-                    // Convert to uppercase
-                    var upperText = args.Text.ToUpper();
-
-                    // Filter to only valid notes
-                    var newText = upperText;
-                    if (!IsNote(newText))
-                    {
-                        newText = PreviousNoteInputs[index];
-                        input.AddStyleClass("Caution");
-                    }
-                    else
+                    if (!IsNote(input.Text))
                     {
-                        PreviousNoteInputs[index] = newText;
+                        input.Text = PreviousNoteInputs[index];
                         input.RemoveStyleClass("Caution");
                     }
-
-                    // Only update if there's a change
-                    if (newText != input.Text)
-                        input.Text = newText;
+                    input.CursorPosition = input.Text.Length;
                 };
             }
         }
@@ -86,6 +86,9 @@ namespace Content.Client.PDA.Ringer
         /// </summary>
         public static bool IsNote(string input)
         {
+            if (input.Any(char.IsDigit))
+                return false;
+
             input = input.Replace("#", "sharp");
 
             return Enum.TryParse(input, true, out Note _);
index dbdc5e83f3f8f2d8cd9762958bfe0f6774ffb774..b47ca0fde3bd4a14e7e4bd42c4d251e7987a9045 100644 (file)
@@ -55,7 +55,6 @@ public sealed class RingerSystem : SharedRingerSystem
     /// </summary>
     private void OnGenerateUplinkCode(Entity<RingerUplinkComponent> ent, ref GenerateUplinkCodeEvent ev)
     {
-        // Generate a new uplink code
         var code = GenerateRingtone();
 
         // Set the code on the component
@@ -74,6 +73,10 @@ public sealed class RingerSystem : SharedRingerSystem
         if (!HasComp<StoreComponent>(uid))
             return false;
 
+        // Wasn't generated yet
+        if (uplink.Code is null)
+            return false;
+
         // On the server, we always check if the code matches
         if (!uplink.Code.SequenceEqual(ringtone))
             return false;
index e3170c84e35b6bc763b35f5b75919aeedd83e463..2dbbfb5efca7787665a2c76cf568b49232791418 100644 (file)
@@ -14,7 +14,7 @@ public sealed partial class RingerUplinkComponent : Component
     /// Set via GenerateUplinkCodeEvent.
     /// </summary>
     [DataField]
-    public Note[] Code = new Note[SharedRingerSystem.RingtoneLength];
+    public Note[]? Code;
 
     /// <summary>
     /// Whether to show the toggle uplink button in PDA settings.
index 0fa5a570aaed8f81685720d67547abcf309eaa0f..8a9d8156a31ef9138e23589cd007aaa8b04211a7 100644 (file)
@@ -45,8 +45,8 @@ public abstract class SharedRingerSystem : EntitySystem
     /// <inheritdoc/>
     public override void Update(float frameTime)
     {
-        var ringerQuery = EntityQueryEnumerator<RingerComponent>();
-        while (ringerQuery.MoveNext(out var uid, out var ringer))
+        var ringerQuery = EntityQueryEnumerator<RingerComponent, TransformComponent>();
+        while (ringerQuery.MoveNext(out var uid, out var ringer, out var xform))
         {
             if (!ringer.Active || !ringer.NextNoteTime.HasValue)
                 continue;
@@ -63,10 +63,9 @@ public abstract class SharedRingerSystem : EntitySystem
             // and play it separately with PlayLocal, so that it's actually predicted
             if (_net.IsServer)
             {
-                var ringerXform = Transform(uid);
                 _audio.PlayEntity(
                     GetSound(ringer.Ringtone[ringer.NoteCount]),
-                    Filter.Empty().AddInRange(_xform.GetMapCoordinates(uid, ringerXform), ringer.Range),
+                    Filter.Empty().AddInRange(_xform.GetMapCoordinates(uid, xform), ringer.Range),
                     uid,
                     true,
                     AudioParams.Default.WithMaxDistance(ringer.Range).WithVolume(ringer.Volume)
@@ -257,14 +256,6 @@ public abstract class SharedRingerSystem : EntitySystem
         return true;
     }
 
-    /// <summary>
-    /// Helper method to determine if the mind is an antagonist.
-    /// </summary>
-    protected bool IsAntagonist(EntityUid? user)
-    {
-        return user != null && _mind.TryGetMind(user.Value, out var mindId, out _) && _role.MindIsAntagonist(mindId);
-    }
-
     /// <summary>
     /// Gets the sound path for a specific note.
     /// </summary>