v1.6.17.0 (Unto the Breach update)

This commit is contained in:
Regalis11
2024-10-22 17:29:04 +03:00
parent e74b3cdb17
commit 6e6c17e100
417 changed files with 17166 additions and 5870 deletions
@@ -44,7 +44,7 @@ sealed class ConditionallyEditable : Editable
ConditionType.IsSwappableItem
=> entity is Item item && item.Prefab.SwappableItem != null,
ConditionType.AllowRotating
=> (entity is Item { body: null } item && item.Prefab.AllowRotatingInEditor)
=> (entity is Item item && (item.body == null || item.body.BodyType == FarseerPhysics.BodyType.Static) && item.Prefab.AllowRotatingInEditor)
|| (entity is Structure structure && structure.Prefab.AllowRotatingInEditor),
ConditionType.Attachable
=> GetComponent<Holdable>(entity) is Holdable { Attachable: true },
@@ -1,11 +1,14 @@
using System;
using System;
namespace Barotrauma;
[AttributeUsage(AttributeTargets.Property)]
class Editable : Attribute
{
public int MaxLength;
/// <summary>
/// Maximum length of the value if the value is a string. Only has an effect is larger than 0.
/// </summary>
public int MaxLength = -1;
public int DecimalCount = 1;
public int MinValueInt = int.MinValue, MaxValueInt = int.MaxValue;
@@ -34,9 +37,8 @@ class Editable : Attribute
/// </summary>
public bool ReadOnly;
public Editable(int maxLength = 20)
public Editable()
{
MaxLength = maxLength;
}
public Editable(int minValue, int maxValue)
@@ -214,10 +214,10 @@ namespace Barotrauma
PropertyInfo.SetValue(parentObject, new RawLString(value));
break;
case "stringarray":
PropertyInfo.SetValue(parentObject, XMLExtensions.ParseStringArray(value));
PropertyInfo.SetValue(parentObject, ParseStringArray(value));
break;
case "identifierarray":
PropertyInfo.SetValue(parentObject, XMLExtensions.ParseIdentifierArray(value));
PropertyInfo.SetValue(parentObject, ParseIdentifierArray(value));
break;
}
}
@@ -229,6 +229,17 @@ namespace Barotrauma
return true;
}
private static string[] ParseStringArray(string stringArrayValues)
{
return string.IsNullOrEmpty(stringArrayValues) ? Array.Empty<string>() : stringArrayValues.Split(';');
}
private static Identifier[] ParseIdentifierArray(string stringArrayValues)
{
return ParseStringArray(stringArrayValues).ToIdentifiers();
}
public bool TrySetValue(object parentObject, object value)
{
if (value == null || parentObject == null || PropertyInfo == null) return false;
@@ -298,10 +309,10 @@ namespace Barotrauma
PropertyInfo.SetValue(parentObject, new RawLString((string)value));
return true;
case "stringarray":
PropertyInfo.SetValue(parentObject, XMLExtensions.ParseStringArray((string)value));
PropertyInfo.SetValue(parentObject, ParseStringArray((string)value));
return true;
case "identifierarray":
PropertyInfo.SetValue(parentObject, XMLExtensions.ParseIdentifierArray((string)value));
PropertyInfo.SetValue(parentObject, ParseIdentifierArray((string)value));
return true;
default:
DebugConsole.ThrowError($"Failed to set the value of the property \"{Name}\" of \"{parentObject}\" to {value}");
@@ -1082,7 +1093,7 @@ namespace Barotrauma
{
var componentElement = subElement.FirstElement();
if (componentElement == null) { continue; }
ItemComponent itemComponent = item2.Components.First(c => c.Name == componentElement.Name.ToString());
ItemComponent itemComponent = item2.Components.FirstOrDefault(c => c.Name == componentElement.Name.ToString());
if (itemComponent == null) { continue; }
foreach (XAttribute attribute in componentElement.Attributes())
{
@@ -3,6 +3,7 @@ using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Linq;
using System.Reflection;
@@ -94,7 +95,7 @@ namespace Barotrauma
try
{
ToolBox.IsProperFilenameCase(filePath);
using FileStream stream = File.Open(filePath, System.IO.FileMode.Open, System.IO.FileAccess.Read);
using FileStream stream = File.Open(filePath, System.IO.FileMode.Open, System.IO.FileAccess.Read, catchUnauthorizedAccessExceptions: false);
using XmlReader reader = CreateReader(stream, Path.GetFullPath(filePath));
doc = XDocument.Load(reader, LoadOptions.SetBaseUri);
}
@@ -511,23 +512,54 @@ namespace Barotrauma
return ushortValue;
}
private static T ParseEnumValue<T>(string value, T defaultValue, XAttribute attribute) where T : struct, Enum
{
if (Enum.TryParse(value, true, out T result))
{
return result;
}
else if (int.TryParse(value, NumberStyles.Any, CultureInfo.InvariantCulture, out int resultInt))
{
return Unsafe.As<int, T>(ref resultInt);
}
else
{
DebugConsole.ThrowError($"Error in {attribute}! \"{value}\" is not a valid {typeof(T).Name} value");
return defaultValue;
}
}
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 ParseEnumValue<T>(attr.Value, defaultValue, attr);
}
if (Enum.TryParse(attr.Value, true, out T result))
[return: NotNullIfNotNull("defaultValue")]
public static T[] GetAttributeEnumArray<T>(this XElement element, string name, T[] defaultValue) where T : struct, Enum
{
string[] stringArray = element.GetAttributeStringArray(name, null);
if (stringArray == null) { return defaultValue; }
else if (stringArray.Length == 0) { return new T[0]; }
T[] enumArray = new T[stringArray.Length];
var attribute = element.GetAttribute(name);
for (int i = 0; i < stringArray.Length; i++)
{
return result;
try
{
enumArray[i] = ParseEnumValue<T>(stringArray[i].Trim(), default(T), attribute);
}
catch (Exception e)
{
LogAttributeError(attribute, element, e);
}
}
else if (int.TryParse(attr.Value, NumberStyles.Any, CultureInfo.InvariantCulture, out int resultInt))
{
return Unsafe.As<int, T>(ref resultInt);
}
DebugConsole.ThrowError($"Error in {attr}! \"{attr}\" is not a valid {typeof(T).Name} value");
return default;
return enumArray;
}
public static bool GetAttributeBool(this XElement element, string name, bool defaultValue)
@@ -1029,16 +1061,6 @@ namespace Barotrauma
public static Identifier VariantOf(this XElement element) =>
element.GetAttributeIdentifier("inherit", element.GetAttributeIdentifier("variantof", ""));
public static string[] ParseStringArray(string stringArrayValues)
{
return string.IsNullOrEmpty(stringArrayValues) ? Array.Empty<string>() : stringArrayValues.Split(';');
}
public static Identifier[] ParseIdentifierArray(string stringArrayValues)
{
return ParseStringArray(stringArrayValues).ToIdentifiers().ToArray();
}
public static bool IsOverride(this XElement element) => element.NameAsIdentifier() == "override";
/// <summary>
@@ -1051,7 +1073,21 @@ namespace Barotrauma
public static XAttribute GetAttribute(this XElement element, string name, StringComparison comparisonMethod = StringComparison.OrdinalIgnoreCase) => element.GetAttribute(a => a.Name.ToString().Equals(name, comparisonMethod));
public static void SetAttributeValue(this XElement element, string name, object value, StringComparison comparisonMethod = StringComparison.OrdinalIgnoreCase) => GetAttribute(element, name, comparisonMethod)?.SetValue(value);
public static bool TrySetAttributeValue(this XElement element, string name, object value, StringComparison comparisonMethod = StringComparison.OrdinalIgnoreCase)
{
var attribute = GetAttribute(element, name, comparisonMethod);
if (attribute == null) { return false; }
attribute.SetValue(value);
return true;
}
public static void SetAttribute(this XElement element, string name, object value)
{
if (!TrySetAttributeValue(element, name, value))
{
element.SetAttributeValue(name, value);
}
}
public static XAttribute GetAttribute(this XElement element, Identifier name) => element.GetAttribute(name.Value, StringComparison.OrdinalIgnoreCase);