Automatically TitleCase IC names (#10986)
This commit is contained in:
@@ -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
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|||||||
Reference in New Issue
Block a user