Build 0.21.6.0 (1.0 pre-patch)

This commit is contained in:
Regalis11
2023-01-31 18:08:26 +02:00
parent e1c04bc31d
commit cf9ecd35b3
231 changed files with 4479 additions and 2276 deletions
@@ -1,15 +1,14 @@
using System;
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Xml;
using System.Xml.Linq;
using Microsoft.Xna.Framework;
using File = Barotrauma.IO.File;
using FileStream = Barotrauma.IO.FileStream;
using Path = Barotrauma.IO.Path;
@@ -315,7 +314,7 @@ namespace Barotrauma
}
catch (Exception e)
{
DebugConsole.ThrowError($"Error when reading attribute \"{name}\" from {element}!", e);
LogAttributeError(attribute, element, e);
}
}
@@ -357,7 +356,7 @@ namespace Barotrauma
}
catch (Exception e)
{
DebugConsole.ThrowError($"Error when reading attribute \"{name}\" from {element}!", e);
LogAttributeError(attribute, element, e);
}
return val;
@@ -376,7 +375,7 @@ namespace Barotrauma
}
catch (Exception e)
{
DebugConsole.ThrowError($"Error when reading attribute \"{name}\" from {element}!", e);
LogAttributeError(attribute, element, e);
}
return val;
@@ -395,12 +394,22 @@ namespace Barotrauma
}
catch (Exception e)
{
DebugConsole.ThrowError($"Error when reading attribute \"{name}\" from {element}!", e);
LogAttributeError(attribute, element, e);
}
return val;
}
public static Option<SerializableDateTime> GetAttributeDateTime(
this XElement element, string name)
{
var attribute = element?.GetAttribute(name);
if (attribute == null) { return Option<SerializableDateTime>.None(); }
string attrVal = attribute.Value;
return SerializableDateTime.Parse(attrVal);
}
public static Version GetAttributeVersion(this XElement element, string name, Version defaultValue)
{
var attribute = element?.GetAttribute(name);
@@ -414,7 +423,7 @@ namespace Barotrauma
}
catch (Exception e)
{
DebugConsole.ThrowError($"Error when reading attribute \"{name}\" from {element}!", e);
LogAttributeError(attribute, element, e);
}
return val;
@@ -439,7 +448,7 @@ namespace Barotrauma
}
catch (Exception e)
{
DebugConsole.ThrowError($"Error when reading attribute \"{name}\" from {element}!", e);
LogAttributeError(attribute, element, e);
}
}
@@ -464,7 +473,7 @@ namespace Barotrauma
}
catch (Exception e)
{
DebugConsole.ThrowError($"Error when reading attribute \"{name}\" from {element}!", e);
LogAttributeError(attribute, element, e);
}
}
@@ -566,13 +575,26 @@ namespace Barotrauma
}
catch (Exception e)
{
DebugConsole.ThrowError($"Error when reading attribute \"{name}\" from {element}!", e);
LogAttributeError(attribute, element, e);
}
}
return colorValue;
}
private static void LogAttributeError(XAttribute attribute, XElement element, Exception e)
{
string elementStr = element.ToString();
if (elementStr.Length > 500)
{
DebugConsole.ThrowError($"Error when reading attribute \"{attribute}\"!", e);
}
else
{
DebugConsole.ThrowError($"Error when reading attribute \"{attribute.Name}\" from {elementStr}!", e);
}
}
#if CLIENT
public static KeyOrMouse GetAttributeKeyOrMouse(this XElement element, string name, KeyOrMouse defaultValue)
{
@@ -621,6 +643,15 @@ namespace Barotrauma
return stringValue.Split(';').Select(s => ParseTuple<T1, T2>(s, default)).ToArray();
}
public static Range<int> GetAttributeRange(this XElement element, string name, Range<int> defaultValue)
{
var attribute = element?.GetAttribute(name);
if (attribute is null) { return defaultValue; }
string stringValue = attribute.Value;
return string.IsNullOrEmpty(stringValue) ? defaultValue : ParseRange(stringValue);
}
public static string ElementInnerText(this XElement el)
{
StringBuilder str = new StringBuilder();
@@ -895,6 +926,37 @@ namespace Barotrauma
return floatArray;
}
// parse a range string, e.g "1-3" or "3"
public static Range<int> ParseRange(string rangeString)
{
if (string.IsNullOrWhiteSpace(rangeString)) { return GetDefault(rangeString); }
string[] split = rangeString.Split('-');
return split.Length switch
{
1 when TryParseInt(split[0], out int value) => new Range<int>(value, value),
2 when TryParseInt(split[0], out int min) && TryParseInt(split[1], out int max) && min < max => new Range<int>(min, max),
_ => GetDefault(rangeString)
};
static bool TryParseInt(string value, out int result)
{
if (!string.IsNullOrWhiteSpace(value))
{
return int.TryParse(value, NumberStyles.Any, CultureInfo.InvariantCulture, out result);
}
result = default;
return false;
}
static Range<int> GetDefault(string rangeString)
{
DebugConsole.ThrowError($"Error parsing range: \"{rangeString}\" (using default value 0-99)");
return new Range<int>(0, 99);
}
}
public static Identifier VariantOf(this XElement element) =>
element.GetAttributeIdentifier("inherit", element.GetAttributeIdentifier("variantof", ""));