Add support for LocalizedDatasets to RandomMetadata (#28601)
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
using Content.Shared.Dataset;
|
using Content.Shared.Dataset;
|
||||||
|
using Content.Shared.Random.Helpers;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using Robust.Shared.Prototypes;
|
using Robust.Shared.Prototypes;
|
||||||
using Robust.Shared.Random;
|
using Robust.Shared.Random;
|
||||||
@@ -47,13 +48,19 @@ public sealed class RandomMetadataSystem : EntitySystem
|
|||||||
var outputSegments = new List<string>();
|
var outputSegments = new List<string>();
|
||||||
foreach (var segment in segments)
|
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);
|
var random = _random.Pick(proto.Values);
|
||||||
if (Loc.TryGetString(random, out var localizedSegment))
|
if (Loc.TryGetString(random, out var localizedSegment))
|
||||||
outputSegments.Add(localizedSegment);
|
outputSegments.Add(localizedSegment);
|
||||||
else
|
else
|
||||||
outputSegments.Add(random);
|
outputSegments.Add(random);
|
||||||
} else if (Loc.TryGetString(segment, out var localizedSegment))
|
}
|
||||||
|
else if (Loc.TryGetString(segment, out var localizedSegment))
|
||||||
outputSegments.Add(localizedSegment);
|
outputSegments.Add(localizedSegment);
|
||||||
else
|
else
|
||||||
outputSegments.Add(segment);
|
outputSegments.Add(segment);
|
||||||
|
|||||||
@@ -12,9 +12,13 @@ namespace Content.Shared.Random.Helpers
|
|||||||
return random.Pick(prototype.Values);
|
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)
|
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)
|
public static string Pick(this IWeightedRandomPrototype prototype, System.Random random)
|
||||||
|
|||||||
Reference in New Issue
Block a user