remove evil shitcode from randommetadata (#36324)
* remove evil * fix non-localizeddataset uses --------- Co-authored-by: deltanedas <@deltanedas:kde.org>
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
using Content.Shared.Dataset;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Server.RandomMetadata;
|
||||
|
||||
/// <summary>
|
||||
@@ -6,15 +9,15 @@
|
||||
[RegisterComponent]
|
||||
public sealed partial class RandomMetadataComponent : Component
|
||||
{
|
||||
[DataField("descriptionSegments")]
|
||||
public List<string>? DescriptionSegments;
|
||||
[DataField]
|
||||
public List<ProtoId<LocalizedDatasetPrototype>>? DescriptionSegments;
|
||||
|
||||
[DataField("nameSegments")]
|
||||
public List<string>? NameSegments;
|
||||
[DataField]
|
||||
public List<ProtoId<LocalizedDatasetPrototype>>? NameSegments;
|
||||
|
||||
[DataField("nameSeparator")]
|
||||
[DataField]
|
||||
public string NameSeparator = " ";
|
||||
|
||||
[DataField("descriptionSeparator")]
|
||||
[DataField]
|
||||
public string DescriptionSeparator = " ";
|
||||
}
|
||||
|
||||
@@ -12,6 +12,8 @@ public sealed class RandomMetadataSystem : EntitySystem
|
||||
[Dependency] private readonly IRobustRandom _random = default!;
|
||||
[Dependency] private readonly MetaDataSystem _metaData = default!;
|
||||
|
||||
private List<string> _outputSegments = new();
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
@@ -43,28 +45,14 @@ public sealed class RandomMetadataSystem : EntitySystem
|
||||
/// <param name="separator">The separator that will be inbetween each segment</param>
|
||||
/// <returns>The newly generated string</returns>
|
||||
[PublicAPI]
|
||||
public string GetRandomFromSegments(List<string> segments, string? separator)
|
||||
public string GetRandomFromSegments(List<ProtoId<LocalizedDatasetPrototype>> segments, string? separator)
|
||||
{
|
||||
var outputSegments = new List<string>();
|
||||
_outputSegments.Clear();
|
||||
foreach (var segment in segments)
|
||||
{
|
||||
if (_prototype.TryIndex<LocalizedDatasetPrototype>(segment, out var localizedProto))
|
||||
{
|
||||
outputSegments.Add(_random.Pick(localizedProto));
|
||||
var localizedProto = _prototype.Index(segment);
|
||||
_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))
|
||||
outputSegments.Add(localizedSegment);
|
||||
else
|
||||
outputSegments.Add(segment);
|
||||
}
|
||||
return string.Join(separator, outputSegments);
|
||||
return string.Join(separator, _outputSegments);
|
||||
}
|
||||
}
|
||||
|
||||
2
Resources/Locale/en-US/datasets/names/joining.ftl
Normal file
2
Resources/Locale/en-US/datasets/names/joining.ftl
Normal file
@@ -0,0 +1,2 @@
|
||||
names-word-the-1 = The
|
||||
names-word-of-1 = of
|
||||
3
Resources/Locale/en-US/datasets/names/nukie_first.ftl
Normal file
3
Resources/Locale/en-US/datasets/names/nukie_first.ftl
Normal file
@@ -0,0 +1,3 @@
|
||||
names-nukie-commander-1 = Commander
|
||||
names-nukie-agent-1 = Agent
|
||||
names-nukie-operator-1 = Operator
|
||||
14
Resources/Prototypes/Datasets/Names/joining.yml
Normal file
14
Resources/Prototypes/Datasets/Names/joining.yml
Normal file
@@ -0,0 +1,14 @@
|
||||
# These can be inserted inbetween name datasets
|
||||
# Ideally it would be localized since just swapping words doesnt help much for a lot of languages
|
||||
|
||||
- type: localizedDataset
|
||||
id: WordThe
|
||||
values:
|
||||
prefix: names-word-the-
|
||||
count: 1
|
||||
|
||||
- type: localizedDataset
|
||||
id: WordOf
|
||||
values:
|
||||
prefix: names-word-of-
|
||||
count: 1
|
||||
17
Resources/Prototypes/Datasets/Names/nukies.yml
Normal file
17
Resources/Prototypes/Datasets/Names/nukies.yml
Normal file
@@ -0,0 +1,17 @@
|
||||
- type: localizedDataset
|
||||
id: NamesNukieFirstCommander
|
||||
values:
|
||||
prefix: names-nukie-commander-
|
||||
count: 1
|
||||
|
||||
- type: localizedDataset
|
||||
id: NamesNukieFirstAgent
|
||||
values:
|
||||
prefix: names-nukie-agent-
|
||||
count: 1
|
||||
|
||||
- type: localizedDataset
|
||||
id: NamesNukieFirstOperator
|
||||
values:
|
||||
prefix: names-nukie-operator-
|
||||
count: 1
|
||||
@@ -72,9 +72,9 @@
|
||||
- StolenEssence
|
||||
- type: RandomMetadata
|
||||
nameSegments:
|
||||
- The
|
||||
- WordThe
|
||||
- NamesRevenantType
|
||||
- of
|
||||
- WordOf
|
||||
- NamesRevenantAdjective
|
||||
- NamesRevenantTheme
|
||||
- type: Speech
|
||||
|
||||
@@ -68,7 +68,7 @@
|
||||
- type: NukeOperative
|
||||
- type: RandomMetadata
|
||||
nameSegments:
|
||||
- nukeops-role-operator
|
||||
- NamesNukieFirstOperator
|
||||
- NamesSyndicateNormal
|
||||
- type: Loadout
|
||||
prototypes: [SyndicateOperativeGearFullNoUplink]
|
||||
|
||||
@@ -129,7 +129,7 @@
|
||||
- type: NukeOperative
|
||||
- type: RandomMetadata
|
||||
nameSegments:
|
||||
- nukeops-role-commander
|
||||
- NamesNukieFirstCommander
|
||||
- NamesSyndicateElite
|
||||
- type: NpcFactionMember
|
||||
factions:
|
||||
@@ -146,7 +146,7 @@
|
||||
- type: NukeOperative
|
||||
- type: RandomMetadata
|
||||
nameSegments:
|
||||
- nukeops-role-agent
|
||||
- NamesNukieFirstAgent
|
||||
- NamesSyndicateNormal
|
||||
- type: NpcFactionMember
|
||||
factions:
|
||||
@@ -165,7 +165,7 @@
|
||||
- type: NukeOperative
|
||||
- type: RandomMetadata
|
||||
nameSegments:
|
||||
- nukeops-role-operator
|
||||
- NamesNukieFirstOperator
|
||||
- NamesSyndicateNormal
|
||||
- type: NpcFactionMember
|
||||
factions:
|
||||
|
||||
Reference in New Issue
Block a user