Unstable v0.15.17.0 (Hex is out of town edition)

This commit is contained in:
Juan Pablo Arce
2021-12-03 13:31:10 -03:00
parent cd5c8f3e13
commit 617d9ede88
245 changed files with 8088 additions and 5842 deletions
@@ -4,6 +4,7 @@ using System.Collections.Immutable;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Xml;
using System.Xml.Linq;
@@ -414,6 +415,15 @@ namespace Barotrauma
return ushortValue;
}
public static T GetAttributeEnum<T>(this XElement element, string name, T defaultValue) where T : struct, Enum
{
var attr = element?.GetAttribute(name);
if (attr == null) { return defaultValue; }
return Enum.TryParse(attr.Value, true, out T result) ? result :
int.TryParse(attr.Value, NumberStyles.Any, CultureInfo.InvariantCulture, out int resultInt) ? Unsafe.As<int, T>(ref resultInt) :
defaultValue;
}
public static bool GetAttributeBool(this XElement element, string name, bool defaultValue)
{
if (element?.Attribute(name) == null) { return defaultValue; }