From 67a9809a5eaa36472e595aca8fd1c26a01a269b0 Mon Sep 17 00:00:00 2001 From: deltanedas <39013340+deltanedas@users.noreply.github.com> Date: Sat, 5 Apr 2025 16:56:22 +0100 Subject: [PATCH] remove evil shitcode from randommetadata (#36324) * remove evil * fix non-localizeddataset uses --------- Co-authored-by: deltanedas <@deltanedas:kde.org> --- .../RandomMetadata/RandomMetadataComponent.cs | 15 ++++++----- .../RandomMetadata/RandomMetadataSystem.cs | 26 +++++-------------- .../Locale/en-US/datasets/names/joining.ftl | 2 ++ .../en-US/datasets/names/nukie_first.ftl | 3 +++ .../Prototypes/Datasets/Names/joining.yml | 14 ++++++++++ .../Prototypes/Datasets/Names/nukies.yml | 17 ++++++++++++ .../Entities/Mobs/NPCs/revenant.yml | 4 +-- .../Prototypes/Entities/Mobs/Player/human.yml | 2 +- Resources/Prototypes/GameRules/roundstart.yml | 6 ++--- 9 files changed, 58 insertions(+), 31 deletions(-) create mode 100644 Resources/Locale/en-US/datasets/names/joining.ftl create mode 100644 Resources/Locale/en-US/datasets/names/nukie_first.ftl create mode 100644 Resources/Prototypes/Datasets/Names/joining.yml create mode 100644 Resources/Prototypes/Datasets/Names/nukies.yml diff --git a/Content.Server/RandomMetadata/RandomMetadataComponent.cs b/Content.Server/RandomMetadata/RandomMetadataComponent.cs index 7ad97625e3..24d07f4277 100644 --- a/Content.Server/RandomMetadata/RandomMetadataComponent.cs +++ b/Content.Server/RandomMetadata/RandomMetadataComponent.cs @@ -1,3 +1,6 @@ +using Content.Shared.Dataset; +using Robust.Shared.Prototypes; + namespace Content.Server.RandomMetadata; /// @@ -6,15 +9,15 @@ [RegisterComponent] public sealed partial class RandomMetadataComponent : Component { - [DataField("descriptionSegments")] - public List? DescriptionSegments; + [DataField] + public List>? DescriptionSegments; - [DataField("nameSegments")] - public List? NameSegments; + [DataField] + public List>? NameSegments; - [DataField("nameSeparator")] + [DataField] public string NameSeparator = " "; - [DataField("descriptionSeparator")] + [DataField] public string DescriptionSeparator = " "; } diff --git a/Content.Server/RandomMetadata/RandomMetadataSystem.cs b/Content.Server/RandomMetadata/RandomMetadataSystem.cs index e287b54c8f..2127f825e9 100644 --- a/Content.Server/RandomMetadata/RandomMetadataSystem.cs +++ b/Content.Server/RandomMetadata/RandomMetadataSystem.cs @@ -12,6 +12,8 @@ public sealed class RandomMetadataSystem : EntitySystem [Dependency] private readonly IRobustRandom _random = default!; [Dependency] private readonly MetaDataSystem _metaData = default!; + private List _outputSegments = new(); + public override void Initialize() { base.Initialize(); @@ -43,28 +45,14 @@ public sealed class RandomMetadataSystem : EntitySystem /// The separator that will be inbetween each segment /// The newly generated string [PublicAPI] - public string GetRandomFromSegments(List segments, string? separator) + public string GetRandomFromSegments(List> segments, string? separator) { - var outputSegments = new List(); + _outputSegments.Clear(); foreach (var segment in segments) { - if (_prototype.TryIndex(segment, out var localizedProto)) - { - outputSegments.Add(_random.Pick(localizedProto)); - } - else if (_prototype.TryIndex(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); + var localizedProto = _prototype.Index(segment); + _outputSegments.Add(_random.Pick(localizedProto)); } - return string.Join(separator, outputSegments); + return string.Join(separator, _outputSegments); } } diff --git a/Resources/Locale/en-US/datasets/names/joining.ftl b/Resources/Locale/en-US/datasets/names/joining.ftl new file mode 100644 index 0000000000..3baeb89d56 --- /dev/null +++ b/Resources/Locale/en-US/datasets/names/joining.ftl @@ -0,0 +1,2 @@ +names-word-the-1 = The +names-word-of-1 = of diff --git a/Resources/Locale/en-US/datasets/names/nukie_first.ftl b/Resources/Locale/en-US/datasets/names/nukie_first.ftl new file mode 100644 index 0000000000..42433d26e8 --- /dev/null +++ b/Resources/Locale/en-US/datasets/names/nukie_first.ftl @@ -0,0 +1,3 @@ +names-nukie-commander-1 = Commander +names-nukie-agent-1 = Agent +names-nukie-operator-1 = Operator diff --git a/Resources/Prototypes/Datasets/Names/joining.yml b/Resources/Prototypes/Datasets/Names/joining.yml new file mode 100644 index 0000000000..16ad0803f5 --- /dev/null +++ b/Resources/Prototypes/Datasets/Names/joining.yml @@ -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 diff --git a/Resources/Prototypes/Datasets/Names/nukies.yml b/Resources/Prototypes/Datasets/Names/nukies.yml new file mode 100644 index 0000000000..cf2c6b7ab7 --- /dev/null +++ b/Resources/Prototypes/Datasets/Names/nukies.yml @@ -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 diff --git a/Resources/Prototypes/Entities/Mobs/NPCs/revenant.yml b/Resources/Prototypes/Entities/Mobs/NPCs/revenant.yml index ab78e2ac18..dfdb96b35a 100644 --- a/Resources/Prototypes/Entities/Mobs/NPCs/revenant.yml +++ b/Resources/Prototypes/Entities/Mobs/NPCs/revenant.yml @@ -72,9 +72,9 @@ - StolenEssence - type: RandomMetadata nameSegments: - - The + - WordThe - NamesRevenantType - - of + - WordOf - NamesRevenantAdjective - NamesRevenantTheme - type: Speech diff --git a/Resources/Prototypes/Entities/Mobs/Player/human.yml b/Resources/Prototypes/Entities/Mobs/Player/human.yml index 5ed2c52427..11842f30f0 100644 --- a/Resources/Prototypes/Entities/Mobs/Player/human.yml +++ b/Resources/Prototypes/Entities/Mobs/Player/human.yml @@ -68,7 +68,7 @@ - type: NukeOperative - type: RandomMetadata nameSegments: - - nukeops-role-operator + - NamesNukieFirstOperator - NamesSyndicateNormal - type: Loadout prototypes: [SyndicateOperativeGearFullNoUplink] diff --git a/Resources/Prototypes/GameRules/roundstart.yml b/Resources/Prototypes/GameRules/roundstart.yml index 87f8981d8d..a7072bde72 100644 --- a/Resources/Prototypes/GameRules/roundstart.yml +++ b/Resources/Prototypes/GameRules/roundstart.yml @@ -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: