mirror of
https://github.com/WWhiteDreamProject/wwdpublic.git
synced 2026-04-17 13:37:47 +03:00
<!-- This is a semi-strict format, you can add/remove sections as needed but the order/format should be kept the same Remove these comments before submitting --> # Description <!-- Explain this PR in as much detail as applicable Some example prompts to consider: How might this affect the game? The codebase? What might be some alternatives to this? How/Who does this benefit/hurt [the game/codebase]? --> Adds cosmetic pronouns, visible through examining people (if they have any) as a PushMarkup. Adds Station AI/borg name customization. CCVars: customize.allow_cosmetic_pronouns (default false) customize.allow_custom_station_ai_name (default false) customize.allow_custom_cyborg_name (default false, for borgs, mediborgs, etc) --- # Changelog <!-- You can add an author after the `🆑` to change the name that appears in the changelog (ex: `🆑 Death`) Leaving it blank will default to your GitHub display name This includes all available types for the changelog --> 🆑 - add: Added cosmetic pronouns. (disabled by default) - add: Added Station AI name customization through character customization. (disabled by default) - add: Added Cyborg name customization through character customization. (disabled by default) (cherry picked from commit 07fb6bc9a1a770f969bf44690676128970cb9eb7)
64 lines
2.4 KiB
C#
64 lines
2.4 KiB
C#
using Content.Shared.Dataset;
|
|
using Content.Shared.Humanoid;
|
|
using JetBrains.Annotations;
|
|
using Robust.Shared.Prototypes;
|
|
using Robust.Shared.Random;
|
|
|
|
namespace Content.Server.RandomMetadata;
|
|
|
|
public sealed class RandomMetadataSystem : EntitySystem
|
|
{
|
|
[Dependency] private readonly IPrototypeManager _prototype = default!;
|
|
[Dependency] private readonly IRobustRandom _random = default!;
|
|
[Dependency] private readonly MetaDataSystem _metaData = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
SubscribeLocalEvent<RandomMetadataComponent, MapInitEvent>(OnMapInit);
|
|
}
|
|
|
|
// This is done on map init so that map-placed entities have it randomized each time the map loads, for fun.
|
|
private void OnMapInit(EntityUid uid, RandomMetadataComponent component, MapInitEvent args)
|
|
{
|
|
var meta = MetaData(uid);
|
|
|
|
if (component.NameSegments != null
|
|
&& !HasComp<RandomMetadataExcludedComponent>(uid))
|
|
_metaData.SetEntityName(uid, GetRandomFromSegments(component.NameSegments, component.NameSeparator), meta);
|
|
|
|
if (component.DescriptionSegments != null)
|
|
{
|
|
_metaData.SetEntityDescription(uid,
|
|
GetRandomFromSegments(component.DescriptionSegments, component.DescriptionSeparator), meta);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 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>
|
|
/// <returns>The newly generated string</returns>
|
|
[PublicAPI]
|
|
public string GetRandomFromSegments(List<string> segments, string? separator)
|
|
{
|
|
var outputSegments = new List<string>();
|
|
foreach (var segment in segments)
|
|
{
|
|
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);
|
|
}
|
|
}
|