(d9829ac) v0.9.4.0

This commit is contained in:
Regalis
2019-10-24 18:05:42 +02:00
parent 9aa12bcac2
commit b39922a074
319 changed files with 12516 additions and 6815 deletions
@@ -210,7 +210,7 @@ namespace Barotrauma
}
}
if (formatCapitals != null && !GameMain.Config.Language.Contains("Chinese"))
if (formatCapitals != null && (GameMain.Config == null || !GameMain.Config.Language.Contains("Chinese")))
{
for (int i = 0; i < variableTags.Length; i++)
{
@@ -313,8 +313,8 @@ namespace Barotrauma
try
{
return string.Format(text, args);
}
return string.Format(text, args);
}
catch (FormatException)
{
string errorMsg = "Failed to format text \"" + text + "\", args: " + string.Join(", ", args);
@@ -361,7 +361,7 @@ namespace Barotrauma
);
}
static readonly string[] genderPronounVariables = new string[] {
static readonly string[] genderPronounVariables = {
"[genderpronoun]",
"[genderpronounpossessive]",
"[genderpronounreflexive]",
@@ -370,7 +370,7 @@ namespace Barotrauma
"[Genderpronounreflexive]"
};
static readonly string[] genderPronounMaleValues = new string[] {
static readonly string[] genderPronounMaleValues = {
"PronounMaleLowercase",
"PronounPossessiveMaleLowercase",
"PronounReflexiveMaleLowercase",
@@ -379,7 +379,7 @@ namespace Barotrauma
"PronounReflexiveMale"
};
static readonly string[] genderPronounFemaleValues = new string[] {
static readonly string[] genderPronounFemaleValues = {
"PronounFemaleLowercase",
"PronounPossessiveFemaleLowercase",
"PronounReflexiveFemaleLowercase",
@@ -393,10 +393,29 @@ namespace Barotrauma
return FormatServerMessage(message, keys.Concat(genderPronounVariables), values.Concat(gender == Gender.Male ? genderPronounMaleValues : genderPronounFemaleValues));
}
static readonly Regex reReplacedMessage = new Regex(@"^(?<variable>[\[\].A-Za-z0-9_]+?)=(?<message>.*)$", RegexOptions.Compiled);
// Same as string.Join(separator, parts) but performs the operation taking into account server message string replacements.
public static string JoinServerMessages(string separator, string[] parts, string namePrefix = "part.")
{
return string.Join("/",
string.Join("/", parts.Select((part, index) =>
{
var partStart = part.LastIndexOf('/') + 1;
return partStart > 0 ? $"{part.Substring(0, partStart)}/[{namePrefix}{index}]={part.Substring(partStart)}" : $"[{namePrefix}{index}]={part.Substring(partStart)}";
})),
string.Join(separator, parts.Select((part, index) => $"[{namePrefix}{index}]")));
}
static readonly Regex reFormattedMessage = new Regex(@"^(?<variable>[\[\].a-z0-9_]+?)=(?<formatter>[a-z0-9_]+?)\((?<value>.+?)\)", RegexOptions.Compiled|RegexOptions.IgnoreCase);
static readonly Regex reReplacedMessage = new Regex(@"^(?<variable>[\[\].a-z0-9_]+?)=(?<message>.*)$", RegexOptions.Compiled|RegexOptions.IgnoreCase);
static readonly Dictionary<string, Func<string, string>> messageFormatters = new Dictionary<string, Func<string, string>>
{
{ "duration", secondsValue => double.TryParse(secondsValue, out var seconds) ? $"{TimeSpan.FromSeconds(seconds):g}" : null }
};
// Format: ServerMessage.Identifier1/ServerMessage.Indentifier2~[variable1]=value~[variable2]=value
// Also: replacement=ServerMessage.Identifier1~[variable1]=value/ServerMessage.Identifier2~[variable2]=replacement
// And: replacement=formatter(value)
public static string GetServerMessage(string serverMessage)
{
if (!textPacks.ContainsKey(Language))
@@ -439,12 +458,29 @@ namespace Barotrauma
}
else
{
var match = reReplacedMessage.Match(messages[i]);
string messageVariable = null;
if (match.Success)
var matchFormatted = reFormattedMessage.Match(messages[i]);
if (matchFormatted.Success)
{
messageVariable = match.Groups["variable"].ToString();
messages[i] = match.Groups["message"].ToString();
var formatter = matchFormatted.Groups["formatter"].ToString();
if (messageFormatters.TryGetValue(formatter, out var formatterFn))
{
var formattedValue = formatterFn(matchFormatted.Groups["value"].ToString());
if (formattedValue != null)
{
messageVariable = matchFormatted.Groups["variable"].ToString();
messages[i] = formattedValue;
}
}
}
if (messageVariable == null)
{
var matchReplaced = reReplacedMessage.Match(messages[i]);
if (matchReplaced.Success)
{
messageVariable = matchReplaced.Groups["variable"].ToString();
messages[i] = matchReplaced.Groups["message"].ToString();
}
}
foreach (var replacedMessage in replacedMessages)