Release v0.15.12.0
This commit is contained in:
@@ -88,11 +88,11 @@ namespace Barotrauma
|
||||
return GameMain.NetworkMember?.ServerSettings?.AllowLinkingWifiToChat ?? true;
|
||||
case ConditionType.IsSwappableItem:
|
||||
{
|
||||
return entity is Item item && item.Prefab.SwappableItem != null;
|
||||
return entity is Item item && item.Prefab.SwappableItem != null && Screen.Selected == GameMain.SubEditorScreen;
|
||||
}
|
||||
case ConditionType.AllowRotating:
|
||||
{
|
||||
return entity is Item item && item.Prefab.AllowRotatingInEditor && Screen.Selected == GameMain.SubEditorScreen;
|
||||
return entity is Item item && item.body == null && item.Prefab.AllowRotatingInEditor && Screen.Selected == GameMain.SubEditorScreen;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
@@ -146,6 +146,7 @@ namespace Barotrauma
|
||||
{ typeof(Vector4), "vector4" },
|
||||
{ typeof(Rectangle), "rectangle" },
|
||||
{ typeof(Color), "color" },
|
||||
{ typeof(string[]), "stringarray" }
|
||||
};
|
||||
|
||||
private static readonly Dictionary<Type, Dictionary<string, SerializableProperty>> cachedProperties =
|
||||
@@ -273,6 +274,9 @@ namespace Barotrauma
|
||||
case "rectangle":
|
||||
PropertyInfo.SetValue(parentObject, XMLExtensions.ParseRect(value, true));
|
||||
break;
|
||||
case "stringarray":
|
||||
PropertyInfo.SetValue(parentObject, XMLExtensions.ParseStringArray(value));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -345,6 +349,9 @@ namespace Barotrauma
|
||||
case "rectangle":
|
||||
PropertyInfo.SetValue(parentObject, XMLExtensions.ParseRect((string)value, false));
|
||||
return true;
|
||||
case "stringarray":
|
||||
PropertyInfo.SetValue(parentObject, XMLExtensions.ParseStringArray((string)value));
|
||||
break;
|
||||
default:
|
||||
DebugConsole.ThrowError("Failed to set the value of the property \"" + Name + "\" of \"" + parentObject.ToString() + "\" to " + value.ToString());
|
||||
DebugConsole.ThrowError("(Cannot convert a string to a " + PropertyType.ToString() + ")");
|
||||
@@ -723,6 +730,10 @@ namespace Barotrauma
|
||||
case "rectangle":
|
||||
stringValue = XMLExtensions.RectToString((Rectangle)value);
|
||||
break;
|
||||
case "stringarray":
|
||||
string[] stringArray = (string[])value;
|
||||
stringValue = stringArray != null ? string.Join(';', stringArray) : "";
|
||||
break;
|
||||
default:
|
||||
stringValue = value.ToString();
|
||||
break;
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Xml;
|
||||
@@ -8,21 +10,42 @@ using System.Xml.Linq;
|
||||
using Microsoft.Xna.Framework;
|
||||
using File = Barotrauma.IO.File;
|
||||
using FileStream = Barotrauma.IO.FileStream;
|
||||
using Path = Barotrauma.IO.Path;
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
public static class XMLExtensions
|
||||
{
|
||||
public static string ParseContentPathFromUri(this XObject element) => ToolBox.ConvertAbsoluteToRelativePath(element.BaseUri);
|
||||
private static ImmutableDictionary<Type, Func<string, object, object>> converters
|
||||
= new Dictionary<Type, Func<string, object, object>>()
|
||||
{
|
||||
{ typeof(string), (str, defVal) => str },
|
||||
{ typeof(int), (str, defVal) => int.TryParse(str, NumberStyles.Any, CultureInfo.InvariantCulture, out int result) ? result : defVal },
|
||||
{ typeof(uint), (str, defVal) => uint.TryParse(str, NumberStyles.Any, CultureInfo.InvariantCulture, out uint result) ? result : defVal },
|
||||
{ typeof(UInt64), (str, defVal) => UInt64.TryParse(str, NumberStyles.Any, CultureInfo.InvariantCulture, out UInt64 result) ? result : defVal },
|
||||
{ typeof(float), (str, defVal) => float.TryParse(str, NumberStyles.Any, CultureInfo.InvariantCulture, out float result) ? result : defVal },
|
||||
{ typeof(bool), (str, defVal) => bool.TryParse(str, out bool result) ? result : defVal },
|
||||
{ typeof(Color), (str, defVal) => ParseColor(str) },
|
||||
{ typeof(Vector2), (str, defVal) => ParseVector2(str) },
|
||||
{ typeof(Vector3), (str, defVal) => ParseVector3(str) },
|
||||
{ typeof(Vector4), (str, defVal) => ParseVector4(str) },
|
||||
{ typeof(Rectangle), (str, defVal) => ParseRect(str, true) }
|
||||
}.ToImmutableDictionary();
|
||||
|
||||
public static string ParseContentPathFromUri(this XObject element)
|
||||
=> !string.IsNullOrWhiteSpace(element.BaseUri)
|
||||
? System.IO.Path.GetRelativePath(Environment.CurrentDirectory, element.BaseUri.CleanUpPath())
|
||||
: "";
|
||||
|
||||
public static readonly XmlReaderSettings ReaderSettings = new XmlReaderSettings
|
||||
{
|
||||
DtdProcessing = DtdProcessing.Prohibit,
|
||||
XmlResolver = null
|
||||
XmlResolver = null,
|
||||
IgnoreWhitespace = true,
|
||||
};
|
||||
|
||||
public static XmlReader CreateReader(System.IO.Stream stream)
|
||||
=> XmlReader.Create(stream, ReaderSettings);
|
||||
|
||||
public static XmlReader CreateReader(System.IO.Stream stream, string baseUri = "")
|
||||
=> XmlReader.Create(stream, ReaderSettings, baseUri);
|
||||
|
||||
public static XDocument TryLoadXml(System.IO.Stream stream)
|
||||
{
|
||||
@@ -52,8 +75,8 @@ namespace Barotrauma
|
||||
{
|
||||
ToolBox.IsProperFilenameCase(filePath);
|
||||
using FileStream stream = File.Open(filePath, System.IO.FileMode.Open, System.IO.FileAccess.Read);
|
||||
using XmlReader reader = CreateReader(stream);
|
||||
doc = XDocument.Load(reader);
|
||||
using XmlReader reader = CreateReader(stream, Path.GetFullPath(filePath));
|
||||
doc = XDocument.Load(reader, LoadOptions.SetBaseUri);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -79,7 +102,7 @@ namespace Barotrauma
|
||||
try
|
||||
{
|
||||
using FileStream stream = File.Open(filePath, System.IO.FileMode.Open, System.IO.FileAccess.Read);
|
||||
using XmlReader reader = CreateReader(stream);
|
||||
using XmlReader reader = CreateReader(stream, Path.GetFullPath(filePath));
|
||||
doc = XDocument.Load(reader);
|
||||
}
|
||||
catch
|
||||
@@ -87,7 +110,7 @@ namespace Barotrauma
|
||||
return null;
|
||||
}
|
||||
|
||||
if (doc.Root == null) return null;
|
||||
if (doc.Root == null) { return null; }
|
||||
}
|
||||
|
||||
return doc;
|
||||
@@ -95,20 +118,18 @@ namespace Barotrauma
|
||||
|
||||
public static object GetAttributeObject(XAttribute attribute)
|
||||
{
|
||||
if (attribute == null) return null;
|
||||
if (attribute == null) { return null; }
|
||||
|
||||
return ParseToObject(attribute.Value.ToString());
|
||||
}
|
||||
|
||||
public static object ParseToObject(string value)
|
||||
{
|
||||
float floatVal;
|
||||
int intVal;
|
||||
if (value.Contains(".") && Single.TryParse(value, NumberStyles.Float, CultureInfo.InvariantCulture, out floatVal))
|
||||
if (value.Contains(".") && Single.TryParse(value, NumberStyles.Float, CultureInfo.InvariantCulture, out float floatVal))
|
||||
{
|
||||
return floatVal;
|
||||
}
|
||||
if (Int32.TryParse(value, out intVal))
|
||||
if (Int32.TryParse(value, out int intVal))
|
||||
{
|
||||
return intVal;
|
||||
}
|
||||
@@ -129,7 +150,7 @@ namespace Barotrauma
|
||||
|
||||
public static string GetAttributeString(this XElement element, string name, string defaultValue)
|
||||
{
|
||||
if (element?.Attribute(name) == null) return defaultValue;
|
||||
if (element?.Attribute(name) == null) { return defaultValue; }
|
||||
return GetAttributeString(element.Attribute(name), defaultValue);
|
||||
}
|
||||
|
||||
@@ -141,10 +162,10 @@ namespace Barotrauma
|
||||
|
||||
public static string[] GetAttributeStringArray(this XElement element, string name, string[] defaultValue, bool trim = true, bool convertToLowerInvariant = false)
|
||||
{
|
||||
if (element?.Attribute(name) == null) return defaultValue;
|
||||
if (element?.Attribute(name) == null) { return defaultValue; }
|
||||
|
||||
string stringValue = element.Attribute(name).Value;
|
||||
if (string.IsNullOrEmpty(stringValue)) return defaultValue;
|
||||
if (string.IsNullOrEmpty(stringValue)) { return defaultValue; }
|
||||
|
||||
string[] splitValue = stringValue.Split(',', ',');
|
||||
|
||||
@@ -168,11 +189,11 @@ namespace Barotrauma
|
||||
|
||||
public static float GetAttributeFloat(this XElement element, float defaultValue, params string[] matchingAttributeName)
|
||||
{
|
||||
if (element == null) return defaultValue;
|
||||
if (element == null) { return defaultValue; }
|
||||
|
||||
foreach (string name in matchingAttributeName)
|
||||
{
|
||||
if (element.Attribute(name) == null) continue;
|
||||
if (element.Attribute(name) == null) { continue; }
|
||||
|
||||
float val;
|
||||
try
|
||||
@@ -197,7 +218,7 @@ namespace Barotrauma
|
||||
|
||||
public static float GetAttributeFloat(this XElement element, string name, float defaultValue)
|
||||
{
|
||||
if (element?.Attribute(name) == null) return defaultValue;
|
||||
if (element?.Attribute(name) == null) { return defaultValue; }
|
||||
|
||||
float val = defaultValue;
|
||||
try
|
||||
@@ -219,7 +240,7 @@ namespace Barotrauma
|
||||
|
||||
public static float GetAttributeFloat(this XAttribute attribute, float defaultValue)
|
||||
{
|
||||
if (attribute == null) return defaultValue;
|
||||
if (attribute == null) { return defaultValue; }
|
||||
|
||||
float val = defaultValue;
|
||||
|
||||
@@ -242,10 +263,10 @@ namespace Barotrauma
|
||||
|
||||
public static float[] GetAttributeFloatArray(this XElement element, string name, float[] defaultValue)
|
||||
{
|
||||
if (element?.Attribute(name) == null) return defaultValue;
|
||||
if (element?.Attribute(name) == null) { return defaultValue; }
|
||||
|
||||
string stringValue = element.Attribute(name).Value;
|
||||
if (string.IsNullOrEmpty(stringValue)) return defaultValue;
|
||||
if (string.IsNullOrEmpty(stringValue)) { return defaultValue; }
|
||||
|
||||
string[] splitValue = stringValue.Split(',');
|
||||
float[] floatValue = new float[splitValue.Length];
|
||||
@@ -271,13 +292,16 @@ namespace Barotrauma
|
||||
|
||||
public static int GetAttributeInt(this XElement element, string name, int defaultValue)
|
||||
{
|
||||
if (element?.Attribute(name) == null) return defaultValue;
|
||||
if (element?.Attribute(name) == null) { return defaultValue; }
|
||||
|
||||
int val = defaultValue;
|
||||
|
||||
try
|
||||
{
|
||||
val = Int32.Parse(element.Attribute(name).Value, CultureInfo.InvariantCulture);
|
||||
if (!Int32.TryParse(element.Attribute(name).Value, NumberStyles.Any, CultureInfo.InvariantCulture, out val))
|
||||
{
|
||||
val = (int)float.Parse(element.Attribute(name).Value, CultureInfo.InvariantCulture);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -289,7 +313,7 @@ namespace Barotrauma
|
||||
|
||||
public static uint GetAttributeUInt(this XElement element, string name, uint defaultValue)
|
||||
{
|
||||
if (element?.Attribute(name) == null) return defaultValue;
|
||||
if (element?.Attribute(name) == null) { return defaultValue; }
|
||||
|
||||
uint val = defaultValue;
|
||||
|
||||
@@ -307,7 +331,7 @@ namespace Barotrauma
|
||||
|
||||
public static UInt64 GetAttributeUInt64(this XElement element, string name, UInt64 defaultValue)
|
||||
{
|
||||
if (element?.Attribute(name) == null) return defaultValue;
|
||||
if (element?.Attribute(name) == null) { return defaultValue; }
|
||||
|
||||
UInt64 val = defaultValue;
|
||||
|
||||
@@ -325,7 +349,7 @@ namespace Barotrauma
|
||||
|
||||
public static UInt64 GetAttributeSteamID(this XElement element, string name, UInt64 defaultValue)
|
||||
{
|
||||
if (element?.Attribute(name) == null) return defaultValue;
|
||||
if (element?.Attribute(name) == null) { return defaultValue; }
|
||||
|
||||
UInt64 val = defaultValue;
|
||||
|
||||
@@ -343,10 +367,10 @@ namespace Barotrauma
|
||||
|
||||
public static int[] GetAttributeIntArray(this XElement element, string name, int[] defaultValue)
|
||||
{
|
||||
if (element?.Attribute(name) == null) return defaultValue;
|
||||
if (element?.Attribute(name) == null) { return defaultValue; }
|
||||
|
||||
string stringValue = element.Attribute(name).Value;
|
||||
if (string.IsNullOrEmpty(stringValue)) return defaultValue;
|
||||
if (string.IsNullOrEmpty(stringValue)) { return defaultValue; }
|
||||
|
||||
string[] splitValue = stringValue.Split(',');
|
||||
int[] intValue = new int[splitValue.Length];
|
||||
@@ -367,10 +391,10 @@ namespace Barotrauma
|
||||
}
|
||||
public static ushort[] GetAttributeUshortArray(this XElement element, string name, ushort[] defaultValue)
|
||||
{
|
||||
if (element?.Attribute(name) == null) return defaultValue;
|
||||
if (element?.Attribute(name) == null) { return defaultValue; }
|
||||
|
||||
string stringValue = element.Attribute(name).Value;
|
||||
if (string.IsNullOrEmpty(stringValue)) return defaultValue;
|
||||
if (string.IsNullOrEmpty(stringValue)) { return defaultValue; }
|
||||
|
||||
string[] splitValue = stringValue.Split(',');
|
||||
ushort[] ushortValue = new ushort[splitValue.Length];
|
||||
@@ -392,13 +416,13 @@ namespace Barotrauma
|
||||
|
||||
public static bool GetAttributeBool(this XElement element, string name, bool defaultValue)
|
||||
{
|
||||
if (element?.Attribute(name) == null) return defaultValue;
|
||||
if (element?.Attribute(name) == null) { return defaultValue; }
|
||||
return element.Attribute(name).GetAttributeBool(defaultValue);
|
||||
}
|
||||
|
||||
public static bool GetAttributeBool(this XAttribute attribute, bool defaultValue)
|
||||
{
|
||||
if (attribute == null) return defaultValue;
|
||||
if (attribute == null) { return defaultValue; }
|
||||
|
||||
string val = attribute.Value.ToLowerInvariant().Trim();
|
||||
if (val == "true")
|
||||
@@ -416,31 +440,31 @@ namespace Barotrauma
|
||||
|
||||
public static Point GetAttributePoint(this XElement element, string name, Point defaultValue)
|
||||
{
|
||||
if (element?.Attribute(name) == null) return defaultValue;
|
||||
if (element?.Attribute(name) == null) { return defaultValue; }
|
||||
return ParsePoint(element.Attribute(name).Value);
|
||||
}
|
||||
|
||||
public static Vector2 GetAttributeVector2(this XElement element, string name, Vector2 defaultValue)
|
||||
{
|
||||
if (element?.Attribute(name) == null) return defaultValue;
|
||||
if (element?.Attribute(name) == null) { return defaultValue; }
|
||||
return ParseVector2(element.Attribute(name).Value);
|
||||
}
|
||||
|
||||
public static Vector3 GetAttributeVector3(this XElement element, string name, Vector3 defaultValue)
|
||||
{
|
||||
if (element == null || element.Attribute(name) == null) return defaultValue;
|
||||
if (element == null || element.Attribute(name) == null) { return defaultValue; }
|
||||
return ParseVector3(element.Attribute(name).Value);
|
||||
}
|
||||
|
||||
public static Vector4 GetAttributeVector4(this XElement element, string name, Vector4 defaultValue)
|
||||
{
|
||||
if (element == null || element.Attribute(name) == null) return defaultValue;
|
||||
if (element == null || element.Attribute(name) == null) { return defaultValue; }
|
||||
return ParseVector4(element.Attribute(name).Value);
|
||||
}
|
||||
|
||||
public static Color GetAttributeColor(this XElement element, string name, Color defaultValue)
|
||||
{
|
||||
if (element == null || element.Attribute(name) == null) return defaultValue;
|
||||
if (element == null || element.Attribute(name) == null) { return defaultValue; }
|
||||
return ParseColor(element.Attribute(name).Value);
|
||||
}
|
||||
|
||||
@@ -452,35 +476,54 @@ namespace Barotrauma
|
||||
|
||||
public static Color[] GetAttributeColorArray(this XElement element, string name, Color[] defaultValue)
|
||||
{
|
||||
if (element?.Attribute(name) == null) return defaultValue;
|
||||
if (element?.Attribute(name) == null) { return defaultValue; }
|
||||
|
||||
string stringValue = element.Attribute(name).Value;
|
||||
if (string.IsNullOrEmpty(stringValue)) return defaultValue;
|
||||
string stringValue = element.Attribute(name).Value;
|
||||
if (string.IsNullOrEmpty(stringValue)) { return defaultValue; }
|
||||
|
||||
string[] splitValue = stringValue.Split(';');
|
||||
Color[] colorValue = new Color[splitValue.Length];
|
||||
for (int i = 0; i < splitValue.Length; i++)
|
||||
string[] splitValue = stringValue.Split(';');
|
||||
Color[] colorValue = new Color[splitValue.Length];
|
||||
for (int i = 0; i < splitValue.Length; i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
try
|
||||
{
|
||||
Color val = ParseColor(splitValue[i], true);
|
||||
colorValue[i] = val;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
DebugConsole.ThrowError("Error in " + element + "! ", e);
|
||||
}
|
||||
Color val = ParseColor(splitValue[i], true);
|
||||
colorValue[i] = val;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
DebugConsole.ThrowError("Error in " + element + "! ", e);
|
||||
}
|
||||
}
|
||||
|
||||
return colorValue;
|
||||
return colorValue;
|
||||
}
|
||||
|
||||
public static Rectangle GetAttributeRect(this XElement element, string name, Rectangle defaultValue)
|
||||
{
|
||||
if (element == null || element.Attribute(name) == null) return defaultValue;
|
||||
if (element == null || element.Attribute(name) == null) { return defaultValue; }
|
||||
return ParseRect(element.Attribute(name).Value, false);
|
||||
}
|
||||
|
||||
//TODO: nested tuples and and n-uples where n!=2 are unsupported
|
||||
public static (T1, T2) GetAttributeTuple<T1, T2>(this XElement element, string name, (T1, T2) defaultValue)
|
||||
{
|
||||
string strValue = element.GetAttributeString(name, $"({defaultValue.Item1}, {defaultValue.Item2})").Trim();
|
||||
|
||||
return ParseTuple(strValue, defaultValue);
|
||||
}
|
||||
|
||||
public static (T1, T2)[] GetAttributeTupleArray<T1, T2>(this XElement element, string name,
|
||||
(T1, T2)[] defaultValue)
|
||||
{
|
||||
if (element?.Attribute(name) == null) { return defaultValue; }
|
||||
|
||||
string stringValue = element.Attribute(name).Value;
|
||||
if (string.IsNullOrEmpty(stringValue)) { return defaultValue; }
|
||||
|
||||
return stringValue.Split(';').Select(s => ParseTuple<T1, T2>(s, default)).ToArray();
|
||||
}
|
||||
|
||||
public static string ElementInnerText(this XElement el)
|
||||
{
|
||||
StringBuilder str = new StringBuilder();
|
||||
@@ -516,15 +559,33 @@ namespace Barotrauma
|
||||
vector.W.ToString(format, CultureInfo.InvariantCulture);
|
||||
}
|
||||
|
||||
[Obsolete("Prefer XMLExtensions.ToStringHex")]
|
||||
public static string ColorToString(Color color)
|
||||
{
|
||||
return color.R + "," + color.G + "," + color.B + "," + color.A;
|
||||
}
|
||||
=> $"{color.R},{color.G},{color.B},{color.A}";
|
||||
|
||||
public static string ToStringHex(this Color color)
|
||||
=> $"#{color.R:X2}{color.G:X2}{color.B:X2}"
|
||||
+ ((color.A < 255) ? $"{color.A:X2}" : "");
|
||||
|
||||
public static string RectToString(Rectangle rect)
|
||||
{
|
||||
return rect.X + "," + rect.Y + "," + rect.Width + "," + rect.Height;
|
||||
}
|
||||
|
||||
public static (T1, T2) ParseTuple<T1, T2>(string strValue, (T1, T2) defaultValue)
|
||||
{
|
||||
strValue = strValue.Trim();
|
||||
//require parentheses
|
||||
if (strValue[0] != '(' || strValue[^1] != ')') { return defaultValue; }
|
||||
//remove parentheses
|
||||
strValue = strValue[1..^1];
|
||||
|
||||
string[] elems = strValue.Split(',');
|
||||
if (elems.Length != 2) { return defaultValue; }
|
||||
|
||||
return ((T1)converters[typeof(T1)].Invoke(elems[0], defaultValue.Item1),
|
||||
(T2)converters[typeof(T2)].Invoke(elems[1], defaultValue.Item2));
|
||||
}
|
||||
|
||||
public static Point ParsePoint(string stringPoint, bool errorMessages = true)
|
||||
{
|
||||
@@ -533,7 +594,7 @@ namespace Barotrauma
|
||||
|
||||
if (components.Length != 2)
|
||||
{
|
||||
if (!errorMessages) return point;
|
||||
if (!errorMessages) { return point; }
|
||||
DebugConsole.ThrowError("Failed to parse the string \"" + stringPoint + "\" to Vector2");
|
||||
return point;
|
||||
}
|
||||
@@ -551,7 +612,7 @@ namespace Barotrauma
|
||||
|
||||
if (components.Length != 2)
|
||||
{
|
||||
if (!errorMessages) return vector;
|
||||
if (!errorMessages) { return vector; }
|
||||
DebugConsole.ThrowError("Failed to parse the string \"" + stringVector2 + "\" to Vector2");
|
||||
return vector;
|
||||
}
|
||||
@@ -570,7 +631,7 @@ namespace Barotrauma
|
||||
|
||||
if (components.Length != 3)
|
||||
{
|
||||
if (!errorMessages) return vector;
|
||||
if (!errorMessages) { return vector; }
|
||||
DebugConsole.ThrowError("Failed to parse the string \"" + stringVector3 + "\" to Vector3");
|
||||
return vector;
|
||||
}
|
||||
@@ -590,7 +651,7 @@ namespace Barotrauma
|
||||
|
||||
if (components.Length < 3)
|
||||
{
|
||||
if (errorMessages) DebugConsole.ThrowError("Failed to parse the string \"" + stringVector4 + "\" to Vector4");
|
||||
if (errorMessages) { DebugConsole.ThrowError("Failed to parse the string \"" + stringVector4 + "\" to Vector4"); }
|
||||
return vector;
|
||||
}
|
||||
|
||||
@@ -598,7 +659,9 @@ namespace Barotrauma
|
||||
Single.TryParse(components[1], NumberStyles.Float, CultureInfo.InvariantCulture, out vector.Y);
|
||||
Single.TryParse(components[2], NumberStyles.Float, CultureInfo.InvariantCulture, out vector.Z);
|
||||
if (components.Length > 3)
|
||||
{
|
||||
Single.TryParse(components[3], NumberStyles.Float, CultureInfo.InvariantCulture, out vector.W);
|
||||
}
|
||||
|
||||
return vector;
|
||||
}
|
||||
@@ -638,8 +701,7 @@ namespace Barotrauma
|
||||
{
|
||||
stringColor = stringColor.Substring(1);
|
||||
|
||||
int colorInt = 0;
|
||||
if (int.TryParse(stringColor, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out colorInt))
|
||||
if (int.TryParse(stringColor, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out int colorInt))
|
||||
{
|
||||
if (stringColor.Length == 6)
|
||||
{
|
||||
@@ -656,7 +718,7 @@ namespace Barotrauma
|
||||
|
||||
if (hexFailed)
|
||||
{
|
||||
if (errorMessages) DebugConsole.ThrowError("Failed to parse the string \"" + stringColor + "\" to Color");
|
||||
if (errorMessages) { DebugConsole.ThrowError("Failed to parse the string \"" + stringColor + "\" to Color"); }
|
||||
return Color.White;
|
||||
}
|
||||
}
|
||||
@@ -686,7 +748,7 @@ namespace Barotrauma
|
||||
string[] strComponents = stringRect.Split(',');
|
||||
if ((strComponents.Length < 3 && requireSize) || strComponents.Length < 2)
|
||||
{
|
||||
if (errorMessages) DebugConsole.ThrowError("Failed to parse the string \"" + stringRect + "\" to Rectangle");
|
||||
if (errorMessages) { DebugConsole.ThrowError("Failed to parse the string \"" + stringRect + "\" to Rectangle"); }
|
||||
return new Rectangle(0, 0, 0, 0);
|
||||
}
|
||||
|
||||
@@ -713,6 +775,11 @@ namespace Barotrauma
|
||||
return floatArray;
|
||||
}
|
||||
|
||||
public static string[] ParseStringArray(string stringArrayValues)
|
||||
{
|
||||
return string.IsNullOrEmpty(stringArrayValues) ? new string[0] : stringArrayValues.Split(';');
|
||||
}
|
||||
|
||||
public static bool IsOverride(this XElement element) => element.Name.ToString().Equals("override", StringComparison.OrdinalIgnoreCase);
|
||||
public static bool IsCharacterVariant(this XElement element) => element.Name.ToString().Equals("charactervariant", StringComparison.OrdinalIgnoreCase);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user