]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Add support for LocalizedDatasets to RandomMetadata (#28601)
authorTayrtahn <tayrtahn@gmail.com>
Thu, 6 Jun 2024 06:37:49 +0000 (02:37 -0400)
committerGitHub <noreply@github.com>
Thu, 6 Jun 2024 06:37:49 +0000 (02:37 -0400)
Content.Server/RandomMetadata/RandomMetadataSystem.cs
Content.Shared/Random/Helpers/SharedRandomExtensions.cs

index abab5e5fc3899f77a625ca5936a1ec1037d2e2ce..e287b54c8f77f534d1cb2eeea00754d346f0d232 100644 (file)
@@ -1,4 +1,5 @@
 using Content.Shared.Dataset;
+using Content.Shared.Random.Helpers;
 using JetBrains.Annotations;
 using Robust.Shared.Prototypes;
 using Robust.Shared.Random;
@@ -47,13 +48,19 @@ public sealed class RandomMetadataSystem : EntitySystem
         var outputSegments = new List<string>();
         foreach (var segment in segments)
         {
-            if (_prototype.TryIndex<DatasetPrototype>(segment, out var proto)) {
+            if (_prototype.TryIndex<LocalizedDatasetPrototype>(segment, out var localizedProto))
+            {
+                outputSegments.Add(_random.Pick(localizedProto));
+            }
+            else if (_prototype.TryIndex<DatasetPrototype>(segment, out var proto))
+            {
                 var random = _random.Pick(proto.Values);
                 if (Loc.TryGetString(random, out var localizedSegment))
                     outputSegments.Add(localizedSegment);
                 else
                     outputSegments.Add(random);
-            } else if (Loc.TryGetString(segment, out var localizedSegment))
+            }
+            else if (Loc.TryGetString(segment, out var localizedSegment))
                 outputSegments.Add(localizedSegment);
             else
                 outputSegments.Add(segment);
index f5fbc1bd24e830147bddc25b1290b8580041d9a2..0b618a262db4ae332683a948d6c9c25f3dcce1b5 100644 (file)
@@ -12,9 +12,13 @@ namespace Content.Shared.Random.Helpers
             return random.Pick(prototype.Values);
         }
 
+        /// <summary>
+        /// Randomly selects an entry from <paramref name="prototype"/>, attempts to localize it, and returns the result.
+        /// </summary>
         public static string Pick(this IRobustRandom random, LocalizedDatasetPrototype prototype)
         {
-            return random.Pick(prototype.Values);
+            var index = random.Next(prototype.Values.Count);
+            return Loc.GetString(prototype.Values[index]);
         }
 
         public static string Pick(this IWeightedRandomPrototype prototype, System.Random random)