Faction Test v1.0.1.0

This commit is contained in:
Regalis11
2023-02-16 15:01:28 +02:00
parent caa5a2f762
commit 2c5a7923b0
309 changed files with 7502 additions and 4335 deletions
@@ -154,6 +154,7 @@ namespace Barotrauma
{ typeof(float), "float" },
{ typeof(string), "string" },
{ typeof(Identifier), "identifier" },
{ typeof(LanguageIdentifier), "languageidentifier" },
{ typeof(LocalizedString), "localizedstring" },
{ typeof(Point), "point" },
{ typeof(Vector2), "vector2" },
@@ -240,7 +241,7 @@ namespace Barotrauma
switch (typeName)
{
case "bool":
bool boolValue = value == "true" || value == "True";
bool boolValue = value.ToIdentifier() == "true";
if (TrySetBoolValueWithoutReflection(parentObject, boolValue)) { return true; }
PropertyInfo.SetValue(parentObject, boolValue, null);
break;
@@ -290,6 +291,9 @@ namespace Barotrauma
case "identifier":
PropertyInfo.SetValue(parentObject, value.ToIdentifier());
break;
case "languageidentifier":
PropertyInfo.SetValue(parentObject, value.ToLanguageIdentifier());
break;
case "localizedstring":
PropertyInfo.SetValue(parentObject, new RawLString(value));
break;
@@ -373,6 +377,9 @@ namespace Barotrauma
case "identifier":
PropertyInfo.SetValue(parentObject, new Identifier((string)value));
return true;
case "languageidentifier":
PropertyInfo.SetValue(parentObject, ((string)value).ToLanguageIdentifier());
return true;
case "localizedstring":
PropertyInfo.SetValue(parentObject, new RawLString((string)value));
return true;
@@ -556,7 +563,7 @@ namespace Barotrauma
public static string GetSupportedTypeName(Type type)
{
if (type.IsEnum) return "Enum";
if (type.IsEnum) { return "Enum"; }
if (!supportedTypes.TryGetValue(type, out string typeName))
{
return null;
@@ -693,6 +700,29 @@ namespace Barotrauma
case nameof(Character.SpeedMultiplier):
{ if (parentObject is Character character) { value = character.SpeedMultiplier; return true; } }
break;
case nameof(Character.PropulsionSpeedMultiplier):
{ if (parentObject is Character character) { value = character.PropulsionSpeedMultiplier; return true; } }
break;
case nameof(Character.LowPassMultiplier):
{ if (parentObject is Character character) { value = character.LowPassMultiplier; return true; } }
break;
case nameof(Character.HullOxygenPercentage):
{
if (parentObject is Character character)
{
value = character.HullOxygenPercentage;
return true;
}
else if (parentObject is Item item)
{
value = item.HullOxygenPercentage;
return true;
}
}
break;
case nameof(Door.Stuck):
{ if (parentObject is Door door) { value = door.Stuck; return true; } }
break;
}
return false;
}
@@ -740,6 +770,23 @@ namespace Barotrauma
case nameof(Controller.State):
if (parentObject is Controller controller) { value = controller.State; return true; }
break;
case nameof(Character.InWater):
{
if (parentObject is Character character)
{
value = character.InWater;
return true;
}
else if (parentObject is Item item)
{
value = item.InWater;
return true;
}
}
break;
case nameof(Rope.Snapped):
if (parentObject is Rope rope) { value = rope.Snapped; return true; }
break;
}
return false;
}
@@ -769,7 +816,7 @@ namespace Barotrauma
switch (Name)
{
case nameof(Item.Condition):
if (parentObject is Item item) { item.Condition = value; return true; }
{ if (parentObject is Item item) { item.Condition = value; return true; } }
break;
case nameof(Powered.Voltage):
if (parentObject is Powered powered) { powered.Voltage = value; return true; }
@@ -801,6 +848,9 @@ namespace Barotrauma
case nameof(Character.PropulsionSpeedMultiplier):
{ if (parentObject is Character character) { character.PropulsionSpeedMultiplier = value; return true; } }
break;
case nameof(Item.Scale):
{ if (parentObject is Item item) { item.Scale = value; return true; } }
break;
}
return false;
}
@@ -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);
}
}
@@ -475,9 +484,18 @@ namespace Barotrauma
{
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;
if (Enum.TryParse(attr.Value, true, out T result))
{
return result;
}
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;
}
public static bool GetAttributeBool(this XElement element, string name, bool defaultValue)
@@ -566,13 +584,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)
{
@@ -586,10 +617,18 @@ namespace Barotrauma
return mouseButton;
}
else if (int.TryParse(strValue, NumberStyles.Any, CultureInfo.InvariantCulture, out int mouseButtonInt) &&
(Enum.GetValues(typeof(MouseButton)) as MouseButton[]).Contains((MouseButton)mouseButtonInt))
Enum.GetValues<MouseButton>().Contains((MouseButton)mouseButtonInt))
{
return (MouseButton)mouseButtonInt;
}
else if (string.Equals(strValue, "LeftMouse", StringComparison.OrdinalIgnoreCase))
{
return !PlayerInput.MouseButtonsSwapped() ? MouseButton.PrimaryMouse : MouseButton.SecondaryMouse;
}
else if (string.Equals(strValue, "RightMouse", StringComparison.OrdinalIgnoreCase))
{
return !PlayerInput.MouseButtonsSwapped() ? MouseButton.SecondaryMouse : MouseButton.PrimaryMouse;
}
return defaultValue;
}
#endif