Make `RandomMetadata` properly support localization (#36343)
* Make _outputSegments readonly * Remove mystery character * Use Fluent instead of string concatenation * Adjust format * Convert existing content * Don't need these anymore * Docs
This commit is contained in:
parent
0976afface
commit
8570bde958
|
|
@ -1,7 +1,7 @@
|
|||
using Content.Shared.Dataset;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Server.RandomMetadata;
|
||||
namespace Content.Server.RandomMetadata;
|
||||
|
||||
/// <summary>
|
||||
/// Randomizes the description and/or the name for an entity by creating it from list of dataset prototypes or strings.
|
||||
|
|
@ -15,9 +15,17 @@ public sealed partial class RandomMetadataComponent : Component
|
|||
[DataField]
|
||||
public List<ProtoId<LocalizedDatasetPrototype>>? NameSegments;
|
||||
|
||||
/// <summary>
|
||||
/// LocId of the formatting string to use to assemble the <see cref="NameSegments"/> into the entity's name.
|
||||
/// Segments will be passed to the localization system with this string as variables named $part0, $part1, $part2, etc.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public string NameSeparator = " ";
|
||||
public LocId NameFormat = "random-metadata-name-format-default";
|
||||
|
||||
/// <summary>
|
||||
/// LocId of the formatting string to use to assemble the <see cref="DescriptionSegments"/> into the entity's description.
|
||||
/// Segments will be passed to the localization system with this string as variables named $part0, $part1, $part2, etc.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public string DescriptionSeparator = " ";
|
||||
public LocId DescriptionFormat = "random-metadata-description-format-default";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ public sealed class RandomMetadataSystem : EntitySystem
|
|||
[Dependency] private readonly IRobustRandom _random = default!;
|
||||
[Dependency] private readonly MetaDataSystem _metaData = default!;
|
||||
|
||||
private List<string> _outputSegments = new();
|
||||
private readonly List<(string, object)> _outputSegments = new();
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
|
|
@ -28,13 +28,13 @@ public sealed class RandomMetadataSystem : EntitySystem
|
|||
|
||||
if (component.NameSegments != null)
|
||||
{
|
||||
_metaData.SetEntityName(uid, GetRandomFromSegments(component.NameSegments, component.NameSeparator), meta);
|
||||
_metaData.SetEntityName(uid, GetRandomFromSegments(component.NameSegments, component.NameFormat), meta);
|
||||
}
|
||||
|
||||
if (component.DescriptionSegments != null)
|
||||
{
|
||||
_metaData.SetEntityDescription(uid,
|
||||
GetRandomFromSegments(component.DescriptionSegments, component.DescriptionSeparator), meta);
|
||||
GetRandomFromSegments(component.DescriptionSegments, component.DescriptionFormat), meta);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -42,17 +42,18 @@ public sealed class RandomMetadataSystem : EntitySystem
|
|||
/// Generates a random string from segments and a separator.
|
||||
/// </summary>
|
||||
/// <param name="segments">The segments that it will be generated from</param>
|
||||
/// <param name="separator">The separator that will be inbetween each segment</param>
|
||||
/// <param name="format">The format string used to combine the segments.</param>
|
||||
/// <returns>The newly generated string</returns>
|
||||
[PublicAPI]
|
||||
public string GetRandomFromSegments(List<ProtoId<LocalizedDatasetPrototype>> segments, string? separator)
|
||||
public string GetRandomFromSegments(List<ProtoId<LocalizedDatasetPrototype>> segments, LocId format)
|
||||
{
|
||||
_outputSegments.Clear();
|
||||
foreach (var segment in segments)
|
||||
for (var i = 0; i < segments.Count; ++i)
|
||||
{
|
||||
var localizedProto = _prototype.Index(segment);
|
||||
_outputSegments.Add(_random.Pick(localizedProto));
|
||||
var localizedProto = _prototype.Index(segments[i]);
|
||||
_outputSegments.Add(($"part{i}", _random.Pick(localizedProto)));
|
||||
}
|
||||
return string.Join(separator, _outputSegments);
|
||||
|
||||
return Loc.GetString(format, _outputSegments.ToArray());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,2 +0,0 @@
|
|||
names-word-the-1 = The
|
||||
names-word-of-1 = of
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
names-nukie-commander-1 = Commander
|
||||
names-nukie-agent-1 = Agent
|
||||
names-nukie-operator-1 = Operator
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
random-metadata-name-format-default = {$part0}
|
||||
random-metadata-description-format-default = {$part0}
|
||||
|
||||
# Used for standard humanoid names - "<firstName> <lastName>"
|
||||
name-format-standard = {$part0} {$part1}
|
||||
|
||||
name-format-regal-rat = {$part0} {$part1}
|
||||
name-format-revenant = The {$part0} of {$part1} {$part2}
|
||||
name-format-ninja = {$part0} {$part1}
|
||||
name-format-wizard = {$part0} {$part1}
|
||||
|
||||
# "<title> <name>"
|
||||
name-format-nukie-generic = {$part0} {$part1}
|
||||
name-format-nukie-agent = Agent {$part0}
|
||||
name-format-nukie-commander = Commander {$part0}
|
||||
name-format-nukie-operator = Operator {$part0}
|
||||
# "<title> <name>"
|
||||
name-format-ert = {$part0} {$part1}
|
||||
|
||||
# "<appearance> <type>"
|
||||
name-format-book = {$part0} {$part1}
|
||||
|
||||
name-format-nuclear-operation = {$part0} {$part1}
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
# 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
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
- 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
|
||||
|
|
@ -123,6 +123,7 @@
|
|||
nameSegments:
|
||||
- NamesRegalratKingdom
|
||||
- NamesRegalratTitle
|
||||
nameFormat: name-format-regal-rat
|
||||
- type: GuideHelp
|
||||
guides:
|
||||
- MinorAntagonists
|
||||
|
|
|
|||
|
|
@ -79,11 +79,10 @@
|
|||
- StolenEssence
|
||||
- type: RandomMetadata
|
||||
nameSegments:
|
||||
- WordThe
|
||||
- NamesRevenantType
|
||||
- WordOf
|
||||
- NamesRevenantAdjective
|
||||
- NamesRevenantTheme
|
||||
nameFormat: name-format-revenant
|
||||
- type: Speech
|
||||
speechVerb: Ghost
|
||||
- type: Reactive
|
||||
|
|
|
|||
|
|
@ -580,6 +580,7 @@
|
|||
nameSegments:
|
||||
- NamesFirst
|
||||
- NamesLast
|
||||
nameFormat: name-format-standard
|
||||
|
||||
- type: randomHumanoidSettings
|
||||
id: ChallengeVictimChiefEngineer
|
||||
|
|
@ -599,6 +600,7 @@
|
|||
nameSegments:
|
||||
- NamesFirst
|
||||
- NamesLast
|
||||
nameFormat: name-format-standard
|
||||
|
||||
- type: randomHumanoidSettings
|
||||
id: ChallengeVictimCMO
|
||||
|
|
@ -618,6 +620,7 @@
|
|||
nameSegments:
|
||||
- NamesFirst
|
||||
- NamesLast
|
||||
nameFormat: name-format-standard
|
||||
|
||||
- type: randomHumanoidSettings
|
||||
id: ChallengeVictimHeadOfPersonnel
|
||||
|
|
@ -637,6 +640,7 @@
|
|||
nameSegments:
|
||||
- NamesFirst
|
||||
- NamesLast
|
||||
nameFormat: name-format-standard
|
||||
|
||||
- type: randomHumanoidSettings
|
||||
id: ChallengeVictimHeadOfSecurity
|
||||
|
|
@ -656,6 +660,7 @@
|
|||
nameSegments:
|
||||
- NamesFirst
|
||||
- NamesLast
|
||||
nameFormat: name-format-standard
|
||||
|
||||
- type: randomHumanoidSettings
|
||||
id: ChallengeVictimResearchDirector
|
||||
|
|
@ -675,6 +680,7 @@
|
|||
nameSegments:
|
||||
- NamesFirst
|
||||
- NamesLast
|
||||
nameFormat: name-format-standard
|
||||
|
||||
- type: randomHumanoidSettings
|
||||
id: ChallengeVictimQuartermaster
|
||||
|
|
@ -694,6 +700,7 @@
|
|||
nameSegments:
|
||||
- NamesFirst
|
||||
- NamesLast
|
||||
nameFormat: name-format-standard
|
||||
|
||||
# Security
|
||||
# Following use EventHumanoidMindShielded since they are heads and probably should have mindshields
|
||||
|
|
@ -718,6 +725,7 @@
|
|||
nameSegments:
|
||||
- NamesFirst
|
||||
- NamesLast
|
||||
nameFormat: name-format-standard
|
||||
|
||||
# Engineering
|
||||
|
||||
|
|
|
|||
|
|
@ -68,8 +68,8 @@
|
|||
- type: NukeOperative
|
||||
- type: RandomMetadata
|
||||
nameSegments:
|
||||
- NamesNukieFirstOperator
|
||||
- NamesSyndicateNormal
|
||||
nameFormat: name-format-nukie-operator
|
||||
- type: Loadout
|
||||
prototypes: [SyndicateOperativeGearFullNoUplink]
|
||||
|
||||
|
|
@ -102,6 +102,7 @@
|
|||
nameSegments:
|
||||
- NamesSyndicatePrefix
|
||||
- NamesSyndicateNormal
|
||||
nameFormat: name-format-nukie-generic
|
||||
- type: NpcFactionMember
|
||||
factions:
|
||||
- Syndicate
|
||||
|
|
|
|||
|
|
@ -41,6 +41,7 @@
|
|||
nameSegments:
|
||||
- NamesMilitaryFirstLeader
|
||||
- NamesMilitaryLast
|
||||
nameFormat: name-format-ert
|
||||
- type: RandomHumanoidSpawner
|
||||
settings: DeathSquad
|
||||
|
||||
|
|
@ -64,6 +65,7 @@
|
|||
nameSegments:
|
||||
- NamesMilitaryFirstLeader
|
||||
- NamesMilitaryLast
|
||||
nameFormat: name-format-ert
|
||||
|
||||
|
||||
## ERT Leader
|
||||
|
|
@ -80,6 +82,7 @@
|
|||
nameSegments:
|
||||
- NamesMilitaryFirstLeader
|
||||
- NamesMilitaryLast
|
||||
nameFormat: name-format-ert
|
||||
- type: RandomHumanoidSpawner
|
||||
settings: ERTLeader
|
||||
|
||||
|
|
@ -102,6 +105,7 @@
|
|||
nameSegments:
|
||||
- NamesMilitaryFirstLeader
|
||||
- NamesMilitaryLast
|
||||
nameFormat: name-format-ert
|
||||
|
||||
- type: entity
|
||||
id: RandomHumanoidSpawnerERTLeaderEVA
|
||||
|
|
@ -168,6 +172,7 @@
|
|||
nameSegments:
|
||||
- NamesMilitaryFirst
|
||||
- NamesMilitaryLast
|
||||
nameFormat: name-format-ert
|
||||
- type: RandomHumanoidSpawner
|
||||
settings: ERTChaplain
|
||||
|
||||
|
|
@ -187,6 +192,7 @@
|
|||
nameSegments:
|
||||
- NamesMilitaryFirst
|
||||
- NamesMilitaryLast
|
||||
nameFormat: name-format-ert
|
||||
- type: Loadout
|
||||
prototypes: [ ERTChaplainGear ]
|
||||
roleLoadout: [ RoleSurvivalExtended ]
|
||||
|
|
@ -234,6 +240,7 @@
|
|||
nameSegments:
|
||||
- NamesMilitaryFirst
|
||||
- NamesMilitaryLast
|
||||
nameFormat: name-format-ert
|
||||
- type: RandomHumanoidSpawner
|
||||
settings: ERTJanitor
|
||||
|
||||
|
|
@ -252,6 +259,7 @@
|
|||
nameSegments:
|
||||
- NamesMilitaryFirst
|
||||
- NamesMilitaryLast
|
||||
nameFormat: name-format-ert
|
||||
- type: Loadout
|
||||
prototypes: [ ERTJanitorGear ]
|
||||
roleLoadout: [ RoleSurvivalExtended ]
|
||||
|
|
@ -298,6 +306,7 @@
|
|||
nameSegments:
|
||||
- NamesMilitaryFirst
|
||||
- NamesMilitaryLast
|
||||
nameFormat: name-format-ert
|
||||
- type: RandomHumanoidSpawner
|
||||
settings: ERTEngineer
|
||||
|
||||
|
|
@ -316,6 +325,7 @@
|
|||
nameSegments:
|
||||
- NamesMilitaryFirst
|
||||
- NamesMilitaryLast
|
||||
nameFormat: name-format-ert
|
||||
- type: Loadout
|
||||
prototypes: [ ERTEngineerGear ]
|
||||
roleLoadout: [ RoleSurvivalExtended ]
|
||||
|
|
@ -362,6 +372,7 @@
|
|||
nameSegments:
|
||||
- NamesMilitaryFirst
|
||||
- NamesMilitaryLast
|
||||
nameFormat: name-format-ert
|
||||
- type: RandomHumanoidSpawner
|
||||
settings: ERTSecurity
|
||||
|
||||
|
|
@ -380,6 +391,7 @@
|
|||
nameSegments:
|
||||
- NamesMilitaryFirst
|
||||
- NamesMilitaryLast
|
||||
nameFormat: name-format-ert
|
||||
- type: Loadout
|
||||
prototypes: [ ERTSecurityGear ]
|
||||
roleLoadout: [ RoleSurvivalExtended ]
|
||||
|
|
@ -449,6 +461,7 @@
|
|||
nameSegments:
|
||||
- NamesMilitaryFirst
|
||||
- NamesMilitaryLast
|
||||
nameFormat: name-format-ert
|
||||
- type: RandomHumanoidSpawner
|
||||
settings: ERTMedical
|
||||
|
||||
|
|
@ -467,6 +480,7 @@
|
|||
nameSegments:
|
||||
- NamesMilitaryFirst
|
||||
- NamesMilitaryLast
|
||||
nameFormat: name-format-ert
|
||||
- type: Loadout
|
||||
prototypes: [ ERTMedicalGear ]
|
||||
roleLoadout: [ RoleSurvivalExtended ]
|
||||
|
|
@ -528,6 +542,7 @@
|
|||
nameSegments:
|
||||
- NamesMilitaryFirst
|
||||
- NamesMilitaryLast
|
||||
nameFormat: name-format-ert
|
||||
|
||||
## Central Command
|
||||
|
||||
|
|
@ -612,6 +627,7 @@
|
|||
nameSegments:
|
||||
- NamesFirst
|
||||
- NamesLast
|
||||
nameFormat: name-format-standard
|
||||
|
||||
- type: randomHumanoidSettings
|
||||
id: Cluwne
|
||||
|
|
|
|||
|
|
@ -357,6 +357,7 @@
|
|||
nameSegments:
|
||||
- BookHintAppearances
|
||||
- BookTypes
|
||||
nameFormat: name-format-book
|
||||
- type: RandomSprite
|
||||
available:
|
||||
- cover:
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@
|
|||
nameSegments:
|
||||
- NamesSyndicatePrefix
|
||||
- NamesSyndicateNormal
|
||||
nameFormat: name-format-nukie-generic
|
||||
- type: Damageable
|
||||
damageContainer: Inorganic
|
||||
- type: ToggleableLightVisuals
|
||||
|
|
|
|||
|
|
@ -261,6 +261,7 @@
|
|||
nameSegments:
|
||||
- NamesNinjaTitle
|
||||
- NamesNinja
|
||||
nameFormat: name-format-ninja
|
||||
mindRoles:
|
||||
- MindRoleNinja
|
||||
|
||||
|
|
@ -350,6 +351,7 @@
|
|||
nameSegments:
|
||||
- NamesWizardFirst
|
||||
- NamesWizardLast
|
||||
nameFormat: name-format-wizard
|
||||
mindRoles:
|
||||
- MindRoleWizard
|
||||
|
||||
|
|
@ -603,6 +605,7 @@
|
|||
nameSegments:
|
||||
- NamesSyndicatePrefix
|
||||
- NamesSyndicateNormal
|
||||
nameFormat: name-format-nukie-generic
|
||||
- type: NpcFactionMember
|
||||
factions:
|
||||
- Syndicate
|
||||
|
|
|
|||
|
|
@ -97,6 +97,7 @@
|
|||
nameSegments:
|
||||
- NamesOperationPrefix
|
||||
- NamesOperationSuffix
|
||||
nameFormat: name-format-nuclear-operation
|
||||
- type: NukeopsRule
|
||||
- type: RuleGrids
|
||||
- type: AntagSelection
|
||||
|
|
@ -132,8 +133,8 @@
|
|||
- type: TargetObjectiveImmune # DeltaV - Makes sleepers unable to get nukie kill objectives
|
||||
- type: RandomMetadata
|
||||
nameSegments:
|
||||
- NamesNukieFirstCommander
|
||||
- NamesSyndicateElite
|
||||
nameFormat: name-format-nukie-commander
|
||||
- type: NpcFactionMember
|
||||
factions:
|
||||
- Syndicate
|
||||
|
|
@ -150,8 +151,8 @@
|
|||
- type: TargetObjectiveImmune # DeltaV - Makes sleepers unable to get nukie kill objectives
|
||||
- type: RandomMetadata
|
||||
nameSegments:
|
||||
- NamesNukieFirstAgent
|
||||
- NamesSyndicateNormal
|
||||
nameFormat: name-format-nukie-agent
|
||||
- type: NpcFactionMember
|
||||
factions:
|
||||
- Syndicate
|
||||
|
|
@ -170,8 +171,8 @@
|
|||
- type: TargetObjectiveImmune # DeltaV - Makes sleepers unable to get nukie kill objectives
|
||||
- type: RandomMetadata
|
||||
nameSegments:
|
||||
- NamesNukieFirstOperator
|
||||
- NamesSyndicateNormal
|
||||
nameFormat: name-format-nukie-operator
|
||||
- type: NpcFactionMember
|
||||
factions:
|
||||
- Syndicate
|
||||
|
|
@ -312,6 +313,7 @@
|
|||
nameSegments:
|
||||
- NamesWizardFirst
|
||||
- NamesWizardLast
|
||||
nameFormat: name-format-wizard
|
||||
mindRoles:
|
||||
- MindRoleWizard
|
||||
|
||||
|
|
|
|||
|
|
@ -62,5 +62,6 @@
|
|||
nameSegments:
|
||||
- NamesWizardFirst
|
||||
- NamesWizardLast
|
||||
nameFormat: name-format-wizard
|
||||
mindRoles:
|
||||
- MindRoleWizard
|
||||
|
|
|
|||
Loading…
Reference in New Issue