]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
remove evil shitcode from randommetadata (#36324)
authordeltanedas <39013340+deltanedas@users.noreply.github.com>
Sat, 5 Apr 2025 15:56:22 +0000 (16:56 +0100)
committerGitHub <noreply@github.com>
Sat, 5 Apr 2025 15:56:22 +0000 (17:56 +0200)
* remove evil

* fix non-localizeddataset uses

---------

Co-authored-by: deltanedas <@deltanedas:kde.org>
Content.Server/RandomMetadata/RandomMetadataComponent.cs
Content.Server/RandomMetadata/RandomMetadataSystem.cs
Resources/Locale/en-US/datasets/names/joining.ftl [new file with mode: 0644]
Resources/Locale/en-US/datasets/names/nukie_first.ftl [new file with mode: 0644]
Resources/Prototypes/Datasets/Names/joining.yml [new file with mode: 0644]
Resources/Prototypes/Datasets/Names/nukies.yml [new file with mode: 0644]
Resources/Prototypes/Entities/Mobs/NPCs/revenant.yml
Resources/Prototypes/Entities/Mobs/Player/human.yml
Resources/Prototypes/GameRules/roundstart.yml

index 7ad97625e3fa315c92e269ce16eb85af95e5f1e8..24d07f427721cd35618f8598d28d5b8548cfec8b 100644 (file)
@@ -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 = " ";
 }
index e287b54c8f77f534d1cb2eeea00754d346f0d232..2127f825e94191a765d8cab456c56c948fa9733d 100644 (file)
@@ -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));
-            }
-            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);
+            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 (file)
index 0000000..3baeb89
--- /dev/null
@@ -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 (file)
index 0000000..42433d2
--- /dev/null
@@ -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 (file)
index 0000000..16ad080
--- /dev/null
@@ -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 (file)
index 0000000..cf2c6b7
--- /dev/null
@@ -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
index ab78e2ac182f0cd6eae026637d037e05f6395e58..dfdb96b35adb3d2517b72954309c333fca01e7bc 100644 (file)
@@ -72,9 +72,9 @@
     - StolenEssence
   - type: RandomMetadata
     nameSegments:
-    - The
+    - WordThe
     - NamesRevenantType
-    - of
+    - WordOf
     - NamesRevenantAdjective
     - NamesRevenantTheme
   - type: Speech
index 5ed2c524272577213449ce172596f7714895d547..11842f30f07099d46c5e4a1e3a2d1ff5d6a9b7ff 100644 (file)
@@ -68,7 +68,7 @@
   - type: NukeOperative
   - type: RandomMetadata
     nameSegments:
-    - nukeops-role-operator
+    - NamesNukieFirstOperator
     - NamesSyndicateNormal
   - type: Loadout
     prototypes: [SyndicateOperativeGearFullNoUplink]
index 87f8981d8d7ad5dbc8c320f977f359cc4e37f100..a7072bde728d59e303c16921696d5d19fc59c10d 100644 (file)
       - type: NukeOperative
       - type: RandomMetadata
         nameSegments:
-        - nukeops-role-commander
+        - NamesNukieFirstCommander
         - NamesSyndicateElite
       - type: NpcFactionMember
         factions:
       - type: NukeOperative
       - type: RandomMetadata
         nameSegments:
-        - nukeops-role-agent
+        - NamesNukieFirstAgent
         - NamesSyndicateNormal
       - type: NpcFactionMember
         factions:
       - type: NukeOperative
       - type: RandomMetadata
         nameSegments:
-        - nukeops-role-operator
+        - NamesNukieFirstOperator
         - NamesSyndicateNormal
       - type: NpcFactionMember
         factions: