From 03cc0508f3a6a2f1423c33f506b0255e09d24ff5 Mon Sep 17 00:00:00 2001 From: AJCM-git <60196617+AJCM-git@users.noreply.github.com> Date: Wed, 14 Sep 2022 05:50:15 -0400 Subject: [PATCH] Automatically TitleCase IC names (#10986) --- Content.Shared/CCVar/CCVars.cs | 6 ++++++ .../Preferences/HumanoidCharacterProfile.cs | 12 +++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/Content.Shared/CCVar/CCVars.cs b/Content.Shared/CCVar/CCVars.cs index 18896c829a..db1bfcba46 100644 --- a/Content.Shared/CCVar/CCVars.cs +++ b/Content.Shared/CCVar/CCVars.cs @@ -1083,6 +1083,12 @@ namespace Content.Shared.CCVar public static readonly CVarDef ChatPunctuation = CVarDef.Create("ic.punctuation", false, CVar.SERVER); + /// + /// Enables automatically forcing IC name rules. Uppercases the first letter of the first and last words of the name + /// + public static readonly CVarDef ICNameCase = + CVarDef.Create("ic.name_case", true, CVar.SERVER | CVar.REPLICATED); + /* * Salvage */ diff --git a/Content.Shared/Preferences/HumanoidCharacterProfile.cs b/Content.Shared/Preferences/HumanoidCharacterProfile.cs index 97b8369ee5..da69dfe749 100644 --- a/Content.Shared/Preferences/HumanoidCharacterProfile.cs +++ b/Content.Shared/Preferences/HumanoidCharacterProfile.cs @@ -1,4 +1,5 @@ using System.Linq; +using System.Globalization; using System.Text.RegularExpressions; using Content.Shared.CCVar; using Content.Shared.CharacterAppearance; @@ -328,11 +329,20 @@ namespace Content.Shared.Preferences name = name.Trim(); - if (IoCManager.Resolve().GetCVar(CCVars.RestrictedNames)) + var configManager = IoCManager.Resolve(); + if (configManager.GetCVar(CCVars.RestrictedNames)) { name = Regex.Replace(name, @"[^A-Z,a-z,0-9, -]", string.Empty); } + if (configManager.GetCVar(CCVars.ICNameCase)) + { + // This regex replaces the first character of the first and last words of the name with their uppercase version + name = Regex.Replace(name, + @"^(?\w)|\b(?\w)(?=\w*$)", + m => m.Groups["word"].Value.ToUpper()); + } + if (string.IsNullOrEmpty(name)) { name = Sex.GetName(Species);