v0.14.6.0

This commit is contained in:
Joonas Rikkonen
2021-06-17 17:54:52 +03:00
parent 3f324b14e8
commit c27e2ea5ab
348 changed files with 13156 additions and 4266 deletions
@@ -8,6 +8,7 @@ using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Xml.Linq;
using Barotrauma.Networking;
namespace Barotrauma
{
@@ -32,7 +33,7 @@ namespace Barotrauma
public string FallBackTextTag;
/// <summary>
/// Currently implemented only for int fields. TODO: implement the remaining types (SerializableEntityEditor)
/// Currently implemented only for int and bool fields. TODO: implement the remaining types (SerializableEntityEditor)
/// </summary>
public bool ReadOnly;
@@ -60,6 +61,37 @@ namespace Barotrauma
{
}
[AttributeUsage(AttributeTargets.Property)]
class ConditionallyEditable : Editable
{
public ConditionallyEditable(ConditionType conditionType)
{
this.conditionType = conditionType;
}
private readonly ConditionType conditionType;
public enum ConditionType
{
//These need to exist at compile time, so it is a little awkward
//I would love to see a better way to do this
AllowLinkingWifiToChat,
IsSwappableItem
}
public bool IsEditable(ISerializableEntity entity)
{
switch (conditionType)
{
case ConditionType.AllowLinkingWifiToChat:
return GameMain.NetworkMember?.ServerSettings?.AllowLinkingWifiToChat ?? true;
case ConditionType.IsSwappableItem:
return entity is Item item && item.Prefab.SwappableItem != null;
}
return false;
}
}
[AttributeUsage(AttributeTargets.Property)]
public class Serialize : Attribute
@@ -618,7 +650,7 @@ namespace Barotrauma
return dictionary;
}
public static void SerializeProperties(ISerializableEntity obj, XElement element, bool saveIfDefault = false)
public static void SerializeProperties(ISerializableEntity obj, XElement element, bool saveIfDefault = false, bool ignoreEditable = false)
{
var saveProperties = GetProperties<Serialize>(obj);
foreach (var property in saveProperties)
@@ -635,7 +667,7 @@ namespace Barotrauma
foreach (var attribute in property.Attributes.OfType<Serialize>())
{
if ((attribute.isSaveable && !attribute.defaultValue.Equals(value)) ||
property.Attributes.OfType<Editable>().Any())
(!ignoreEditable && property.Attributes.OfType<Editable>().Any()))
{
save = true;
break;
@@ -737,6 +769,10 @@ namespace Barotrauma
if (entity.SerializableProperties.TryGetValue(attributeName, out SerializableProperty property))
{
FixValue(property, entity, attribute);
if (property.Name == nameof(ItemComponent.Msg) && entity is ItemComponent component)
{
component.ParseMsg();
}
}
else if (entity is Item item1)
{
@@ -745,12 +781,16 @@ namespace Barotrauma
if (component.SerializableProperties.TryGetValue(attributeName, out SerializableProperty componentProperty))
{
FixValue(componentProperty, component, attribute);
if (componentProperty.Name == nameof(ItemComponent.Msg))
{
((ItemComponent)component).ParseMsg();
}
}
}
}
}
void FixValue(SerializableProperty property, object parentObject, XAttribute attribute)
static void FixValue(SerializableProperty property, object parentObject, XAttribute attribute)
{
if (attribute.Value.Length > 0 && attribute.Value[0] == '*')
{
@@ -773,6 +813,29 @@ namespace Barotrauma
property.TrySetValue(parentObject, ((Point)property.GetValue(parentObject)).Multiply(multiplier));
}
}
else if (attribute.Value.Length > 0 && attribute.Value[0] == '+')
{
if (property.PropertyType == typeof(int))
{
float.TryParse(attribute.Value.Substring(1), NumberStyles.Float, CultureInfo.InvariantCulture, out float addition);
property.TrySetValue(parentObject, (int)(((int)property.GetValue(parentObject)) + addition));
}
else if (property.PropertyType == typeof(float))
{
float.TryParse(attribute.Value.Substring(1), NumberStyles.Float, CultureInfo.InvariantCulture, out float addition);
property.TrySetValue(parentObject, (float)property.GetValue(parentObject) + addition);
}
else if (property.PropertyType == typeof(Vector2))
{
var addition = XMLExtensions.ParseVector2(attribute.Value.Substring(1));
property.TrySetValue(parentObject, (Vector2)property.GetValue(parentObject) + addition);
}
else if (property.PropertyType == typeof(Point))
{
var addition = XMLExtensions.ParsePoint(attribute.Value.Substring(1));
property.TrySetValue(parentObject, ((Point)property.GetValue(parentObject)) + addition);
}
}
else
{
property.TrySetValue(parentObject, attribute.Value);