Unstable 1.2.1.0

This commit is contained in:
Markus Isberg
2023-11-10 17:45:19 +02:00
parent 2ea58c58a7
commit 8a2e2ea0ae
268 changed files with 4076 additions and 1843 deletions
@@ -0,0 +1,66 @@
using System;
using Barotrauma.Items.Components;
namespace Barotrauma;
[AttributeUsage(AttributeTargets.Property)]
sealed class ConditionallyEditable : Editable
{
public ConditionallyEditable(ConditionType conditionType, bool onlyInEditors = true)
{
this.conditionType = conditionType;
this.onlyInEditors = onlyInEditors;
}
private readonly ConditionType conditionType;
private readonly bool onlyInEditors;
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,
AllowRotating,
Attachable,
HasBody,
Pickable,
OnlyByStatusEffectsAndNetwork,
HasIntegratedButtons,
IsToggleableController,
HasConnectionPanel
}
public bool IsEditable(ISerializableEntity entity)
{
if (onlyInEditors && Screen.Selected is { IsEditor: false }) { return false; }
return conditionType switch
{
ConditionType.AllowLinkingWifiToChat
=> GameMain.NetworkMember is not { ServerSettings.AllowLinkingWifiToChat: false },
ConditionType.IsSwappableItem
=> entity is Item item && item.Prefab.SwappableItem != null,
ConditionType.AllowRotating
=> (entity is Item { body: null } item && item.Prefab.AllowRotatingInEditor)
|| (entity is Structure structure && structure.Prefab.AllowRotatingInEditor),
ConditionType.Attachable
=> entity is Holdable { Attachable: true },
ConditionType.HasBody
=> entity is Structure { HasBody: true } or Item { body: not null },
ConditionType.Pickable
=> entity is Item item && item.GetComponent<Pickable>() != null,
ConditionType.OnlyByStatusEffectsAndNetwork
=> GameMain.NetworkMember is { IsServer: true },
ConditionType.HasIntegratedButtons
=> entity is Door { HasIntegratedButtons: true },
ConditionType.IsToggleableController
=> entity is Controller { IsToggle: true } controller && controller.Item.GetComponent<ConnectionPanel>() != null,
ConditionType.HasConnectionPanel
=> (entity is Item item && item.GetComponent<ConnectionPanel>() != null)
|| (entity is ItemComponent ic && ic.Item.GetComponent<ConnectionPanel>() != null),
_
=> false
};
}
}
@@ -0,0 +1,55 @@
using System;
using Barotrauma.Items.Components;
namespace Barotrauma;
[AttributeUsage(AttributeTargets.Property)]
class Editable : Attribute
{
public int MaxLength;
public int DecimalCount = 1;
public int MinValueInt = int.MinValue, MaxValueInt = int.MaxValue;
public float MinValueFloat = float.MinValue, MaxValueFloat = float.MaxValue;
public bool ForceShowPlusMinusButtons = false;
public float ValueStep;
/// <summary>
/// Labels of the components of a vector property (defaults to x,y,z,w)
/// </summary>
public string[] VectorComponentLabels;
/// <summary>
/// If a translation can't be found for the property name, this tag is used instead
/// </summary>
public string FallBackTextTag;
/// <summary>
/// Currently implemented only for int and bool fields. TODO: implement the remaining types (SerializableEntityEditor)
/// </summary>
public bool ReadOnly;
public Editable(int maxLength = 20)
{
MaxLength = maxLength;
}
public Editable(int minValue, int maxValue)
{
MinValueInt = minValue;
MaxValueInt = maxValue;
}
public Editable(float minValue, float maxValue, int decimals = 1)
{
MinValueFloat = minValue;
MaxValueFloat = maxValue;
DecimalCount = decimals;
}
}
[AttributeUsage(AttributeTargets.Property)]
sealed class InGameEditable : Editable
{
}
@@ -15,135 +15,6 @@ using Barotrauma.Networking;
namespace Barotrauma
{
[AttributeUsage(AttributeTargets.Property)]
class Editable : Attribute
{
public int MaxLength;
public int DecimalCount = 1;
public int MinValueInt = int.MinValue, MaxValueInt = int.MaxValue;
public float MinValueFloat = float.MinValue, MaxValueFloat = float.MaxValue;
public float ValueStep;
/// <summary>
/// Labels of the components of a vector property (defaults to x,y,z,w)
/// </summary>
public string[] VectorComponentLabels;
/// <summary>
/// If a translation can't be found for the property name, this tag is used instead
/// </summary>
public string FallBackTextTag;
/// <summary>
/// Currently implemented only for int and bool fields. TODO: implement the remaining types (SerializableEntityEditor)
/// </summary>
public bool ReadOnly;
public Editable(int maxLength = 20)
{
MaxLength = maxLength;
}
public Editable(int minValue, int maxValue)
{
MinValueInt = minValue;
MaxValueInt = maxValue;
}
public Editable(float minValue, float maxValue, int decimals = 1)
{
MinValueFloat = minValue;
MaxValueFloat = maxValue;
DecimalCount = decimals;
}
}
[AttributeUsage(AttributeTargets.Property)]
class InGameEditable : Editable
{
}
[AttributeUsage(AttributeTargets.Property)]
class ConditionallyEditable : Editable
{
public ConditionallyEditable(ConditionType conditionType, bool onlyInEditors = true)
{
this.conditionType = conditionType;
this.onlyInEditors = onlyInEditors;
}
private readonly ConditionType conditionType;
private readonly bool onlyInEditors;
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,
AllowRotating,
Attachable,
HasBody,
Pickable,
OnlyByStatusEffectsAndNetwork,
HasIntegratedButtons,
IsToggleableController,
HasConnectionPanel
}
public bool IsEditable(ISerializableEntity entity)
{
if (onlyInEditors && Screen.Selected is { IsEditor: false }) { return false; }
switch (conditionType)
{
case ConditionType.AllowLinkingWifiToChat:
return GameMain.NetworkMember?.ServerSettings?.AllowLinkingWifiToChat ?? true;
case ConditionType.IsSwappableItem:
{
return entity is Item item && item.Prefab.SwappableItem != null;
}
case ConditionType.AllowRotating:
{
return entity is Item item && item.body == null && item.Prefab.AllowRotatingInEditor;
}
case ConditionType.Attachable:
{
return entity is Holdable holdable && holdable.Attachable;
}
case ConditionType.HasBody:
{
return entity is Structure { HasBody: true } || entity is Item { body: not null };
}
case ConditionType.Pickable:
{
return entity is Item item && item.GetComponent<Pickable>() != null;
}
case ConditionType.HasIntegratedButtons:
{
return entity is Door door && door.HasIntegratedButtons;
}
case ConditionType.OnlyByStatusEffectsAndNetwork:
#if SERVER
return true;
#else
return false;
#endif
case ConditionType.IsToggleableController:
{
return entity is Controller controller && controller.IsToggle && controller.Item.GetComponent<ConnectionPanel>() != null;
}
case ConditionType.HasConnectionPanel:
{
return
(entity is Item item && item.GetComponent<ConnectionPanel>() != null) ||
(entity is ItemComponent ic && ic.Item.GetComponent<ConnectionPanel>() != null);
}
}
return false;
}
}
public enum IsPropertySaveable
{
Yes,
@@ -151,7 +22,7 @@ namespace Barotrauma
}
[AttributeUsage(AttributeTargets.Property)]
public class Serialize : Attribute
public sealed class Serialize : Attribute
{
public readonly object DefaultValue;
public readonly IsPropertySaveable IsSaveable;
@@ -182,9 +53,9 @@ namespace Barotrauma
}
}
public class SerializableProperty
public sealed class SerializableProperty
{
private readonly static ImmutableDictionary<Type, string> supportedTypes = new Dictionary<Type, string>
private static readonly ImmutableDictionary<Type, string> supportedTypes = new Dictionary<Type, string>
{
{ typeof(bool), "bool" },
{ typeof(int), "int" },
@@ -114,7 +114,7 @@ namespace Barotrauma
self = (T)boxedSelf;
}
public static void TryDeserialize(this object boxedSelf, FieldInfo field, XElement element)
private static void TryDeserialize(this object boxedSelf, FieldInfo field, XElement element)
{
string fieldName = field.Name.ToLowerInvariant();
string valueStr = element.GetAttributeString(fieldName, field.GetValue(boxedSelf)?.ToString() ?? "");