Automatically TitleCase IC names (#10986)

This commit is contained in:
AJCM-git
2022-09-14 05:50:15 -04:00
committed by GitHub
parent 793dc3a569
commit 03cc0508f3
2 changed files with 17 additions and 1 deletions

View File

@@ -1083,6 +1083,12 @@ namespace Content.Shared.CCVar
public static readonly CVarDef<bool> ChatPunctuation = public static readonly CVarDef<bool> ChatPunctuation =
CVarDef.Create("ic.punctuation", false, CVar.SERVER); CVarDef.Create("ic.punctuation", false, CVar.SERVER);
/// <summary>
/// Enables automatically forcing IC name rules. Uppercases the first letter of the first and last words of the name
/// </summary>
public static readonly CVarDef<bool> ICNameCase =
CVarDef.Create("ic.name_case", true, CVar.SERVER | CVar.REPLICATED);
/* /*
* Salvage * Salvage
*/ */

View File

@@ -1,4 +1,5 @@
using System.Linq; using System.Linq;
using System.Globalization;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using Content.Shared.CCVar; using Content.Shared.CCVar;
using Content.Shared.CharacterAppearance; using Content.Shared.CharacterAppearance;
@@ -328,11 +329,20 @@ namespace Content.Shared.Preferences
name = name.Trim(); name = name.Trim();
if (IoCManager.Resolve<IConfigurationManager>().GetCVar(CCVars.RestrictedNames)) var configManager = IoCManager.Resolve<IConfigurationManager>();
if (configManager.GetCVar(CCVars.RestrictedNames))
{ {
name = Regex.Replace(name, @"[^A-Z,a-z,0-9, -]", string.Empty); 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,
@"^(?<word>\w)|\b(?<word>\w)(?=\w*$)",
m => m.Groups["word"].Value.ToUpper());
}
if (string.IsNullOrEmpty(name)) if (string.IsNullOrEmpty(name))
{ {
name = Sex.GetName(Species); name = Sex.GetName(Species);