- Renamed a bunch of ObjectProperty-related stuff (ObjectProperty -> SerializableProperty, IPropertyObject -> ISerializableEntity, the "SerializableProperty" attribute -> Serialize).

- Rectangle serialization.
- Option to restrict numeric properties to a range of values.
- WIP generic ISerializableEntity editor.
This commit is contained in:
Joonas Rikkonen
2017-11-08 21:15:03 +02:00
parent a0d606ef5f
commit 8e556f1c76
60 changed files with 1035 additions and 678 deletions
@@ -47,21 +47,21 @@ namespace Barotrauma.Items.Components
set { dockingDir = value; }
}
[SerializableProperty("32.0,32.0", false)]
[Serialize("32.0,32.0", false)]
public Vector2 DistanceTolerance
{
get { return distanceTolerance; }
set { distanceTolerance = value; }
}
[SerializableProperty(32.0f, false)]
[Serialize(32.0f, false)]
public float DockedDistance
{
get;
set;
}
[SerializableProperty(true, false)]
[Serialize(true, false)]
public bool IsHorizontal
{
get;
@@ -111,13 +111,13 @@ namespace Barotrauma.Items.Components
}
}
[SerializableProperty("0.0,0.0,0.0,0.0", false)]
[Serialize("0.0,0.0,0.0,0.0", false)]
public string Window
{
get { return XMLExtensions.Vector4ToString(new Vector4(window.X, window.Y, window.Width, window.Height)); }
set
{
Vector4 vector = XMLExtensions.ParseToVector4(value);
Vector4 vector = XMLExtensions.ParseVector4(value);
if (vector.Z != 0.0f || vector.W != 0.0f)
{
window = new Rectangle((int)vector.X, (int)vector.Y, (int)vector.Z, (int)vector.W);
@@ -130,7 +130,7 @@ namespace Barotrauma.Items.Components
get { return window; }
}
[Editable, SerializableProperty(false, true)]
[Editable, Serialize(false, true)]
public bool IsOpen
{
get { return isOpen; }
@@ -29,49 +29,49 @@ namespace Barotrauma.Items.Components
//the angle in which the Character holds the item
protected float holdAngle;
[SerializableProperty(false, true)]
[Serialize(false, true)]
public bool Attached
{
get { return attached && item.ParentInventory == null; }
set { attached = value; }
}
[SerializableProperty(false, false)]
[Serialize(false, false)]
public bool ControlPose
{
get;
set;
}
[SerializableProperty(false, false)]
[Serialize(false, false)]
public bool Attachable
{
get { return attachable; }
set { attachable = value; }
}
[SerializableProperty(false, false)]
[Serialize(false, false)]
public bool AttachedByDefault
{
get { return attachedByDefault; }
set { attachedByDefault = value; }
}
[SerializableProperty("0.0,0.0", false)]
[Serialize("0.0,0.0", false)]
public Vector2 HoldPos
{
get { return ConvertUnits.ToDisplayUnits(holdPos); }
set { holdPos = ConvertUnits.ToSimUnits(value); }
}
[SerializableProperty("0.0,0.0", false)]
[Serialize("0.0,0.0", false)]
public Vector2 AimPos
{
get { return ConvertUnits.ToDisplayUnits(aimPos); }
set { aimPos = ConvertUnits.ToSimUnits(value); }
}
[SerializableProperty(0.0f, false)]
[Serialize(0.0f, false)]
public float HoldAngle
{
get { return MathHelper.ToDegrees(holdAngle); }
@@ -24,14 +24,14 @@ namespace Barotrauma.Items.Components
private float reloadTimer;
[SerializableProperty(0.0f, false)]
[Serialize(0.0f, false)]
public float Range
{
get { return ConvertUnits.ToDisplayUnits(range); }
set { range = ConvertUnits.ToSimUnits(value); }
}
[SerializableProperty(0.5f, false)]
[Serialize(0.5f, false)]
public float Reload
{
get { return reload; }
@@ -22,7 +22,7 @@ namespace Barotrauma.Items.Components
private UsableIn usableIn;
[SerializableProperty(0.0f, false)]
[Serialize(0.0f, false)]
public float Force
{
get { return force; }
@@ -30,7 +30,7 @@ namespace Barotrauma.Items.Components
}
#if CLIENT
[SerializableProperty("", false)]
[Serialize("", false)]
public string Particles
{
get { return particles; }
@@ -13,28 +13,28 @@ namespace Barotrauma.Items.Components
private Vector2 barrelPos;
[SerializableProperty("0.0,0.0", false)]
[Serialize("0.0,0.0", false)]
public string BarrelPos
{
get { return XMLExtensions.Vector2ToString(ConvertUnits.ToDisplayUnits(barrelPos)); }
set { barrelPos = ConvertUnits.ToSimUnits(XMLExtensions.ParseToVector2(value)); }
set { barrelPos = ConvertUnits.ToSimUnits(XMLExtensions.ParseVector2(value)); }
}
[SerializableProperty(1.0f, false)]
[Serialize(1.0f, false)]
public float Reload
{
get { return reload; }
set { reload = Math.Max(value, 0.0f); }
}
[SerializableProperty(0.0f, false)]
[Serialize(0.0f, false)]
public float Spread
{
get;
set;
}
[SerializableProperty(0.0f, false)]
[Serialize(0.0f, false)]
public float UnskilledSpread
{
get;
@@ -21,44 +21,44 @@ namespace Barotrauma.Items.Components
private float activeTimer;
[SerializableProperty(0.0f, false)]
[Serialize(0.0f, false)]
public float Range
{
get { return range; }
set { range = value; }
}
[SerializableProperty(0.0f, false)]
[Serialize(0.0f, false)]
public float StructureFixAmount
{
get; set;
}
[SerializableProperty(0.0f, false)]
[Serialize(0.0f, false)]
public float LimbFixAmount
{
get; set;
}
[SerializableProperty(0.0f, false)]
[Serialize(0.0f, false)]
public float ExtinquishAmount
{
get; set;
}
[SerializableProperty("", false)]
[Serialize("", false)]
public string Particles
{
get { return particles; }
set { particles = value; }
}
[SerializableProperty(0.0f, false)]
[Serialize(0.0f, false)]
public float ParticleSpeed
{
get; set;
}
[SerializableProperty("0.0,0.0", false)]
[Serialize("0.0,0.0", false)]
public Vector2 BarrelPos
{
get { return barrelPos; }
@@ -12,7 +12,7 @@ namespace Barotrauma.Items.Components
bool throwing;
[SerializableProperty(1.0f, false)]
[Serialize(1.0f, false)]
public float ThrowForce
{
get { return throwForce; }
@@ -18,7 +18,7 @@ namespace Barotrauma.Items.Components
/// <summary>
/// The base class for components holding the different functionalities of the item
/// </summary>
partial class ItemComponent : IPropertyObject
partial class ItemComponent : ISerializableEntity
{
protected Item item;
@@ -47,15 +47,15 @@ namespace Barotrauma.Items.Components
private string msg;
[SerializableProperty(0.0f, false)]
[Serialize(0.0f, false)]
public float PickingTime
{
get;
private set;
}
public readonly Dictionary<string, ObjectProperty> properties;
public Dictionary<string, ObjectProperty> ObjectProperties
public readonly Dictionary<string, SerializableProperty> properties;
public Dictionary<string, SerializableProperty> SerializableProperties
{
get { return properties; }
}
@@ -103,21 +103,21 @@ namespace Barotrauma.Items.Components
}
}
[SerializableProperty(false, false)]
[Serialize(false, false)]
public bool CanBePicked
{
get { return canBePicked; }
set { canBePicked = value; }
}
[SerializableProperty(false, false)]
[Serialize(false, false)]
public bool DrawHudWhenEquipped
{
get;
private set;
}
[SerializableProperty(false, false)]
[Serialize(false, false)]
public bool CanBeSelected
{
get { return canBeSelected; }
@@ -136,7 +136,7 @@ namespace Barotrauma.Items.Components
protected set;
}
[SerializableProperty(false, false)]
[Serialize(false, false)]
public bool DeleteOnUse
{
get;
@@ -153,7 +153,7 @@ namespace Barotrauma.Items.Components
get { return name; }
}
[SerializableProperty("", false)]
[Serialize("", false)]
public string Msg
{
get { return msg; }
@@ -164,7 +164,7 @@ namespace Barotrauma.Items.Components
{
this.item = item;
properties = ObjectProperty.GetProperties(this);
properties = SerializableProperty.GetProperties(this);
//canBePicked = ToolBox.GetAttributeBool(element, "canbepicked", false);
//canBeSelected = ToolBox.GetAttributeBool(element, "canbeselected", false);
@@ -205,7 +205,7 @@ namespace Barotrauma.Items.Components
DebugConsole.ThrowError("Invalid pick key in " + element + "!", e);
}
properties = ObjectProperty.DeserializeProperties(this, element);
properties = SerializableProperty.DeserializeProperties(this, element);
foreach (XElement subElement in element.Elements())
{
@@ -477,7 +477,7 @@ namespace Barotrauma.Items.Components
}
}
public void ApplyStatusEffects(ActionType type, List<IPropertyObject> targets, float deltaTime)
public void ApplyStatusEffects(ActionType type, List<ISerializableEntity> targets, float deltaTime)
{
if (statusEffectLists == null) return;
@@ -496,7 +496,7 @@ namespace Barotrauma.Items.Components
foreach (XAttribute attribute in componentElement.Attributes())
{
ObjectProperty property = null;
SerializableProperty property = null;
if (!properties.TryGetValue(attribute.Name.ToString().ToLowerInvariant(), out property)) continue;
property.TrySetValue(attribute.Value);
@@ -586,7 +586,7 @@ namespace Barotrauma.Items.Components
componentElement.Add(newElement);
}
ObjectProperty.SerializeProperties(this, componentElement);
SerializableProperty.SerializeProperties(this, componentElement);
parentElement.Add(componentElement);
return componentElement;
@@ -18,7 +18,7 @@ namespace Barotrauma.Items.Components
private ushort[] itemIds;
//how many items can be contained
[SerializableProperty(5, false)]
[Serialize(5, false)]
public int Capacity
{
get { return capacity; }
@@ -26,7 +26,7 @@ namespace Barotrauma.Items.Components
}
private int capacity;
[SerializableProperty(true, false)]
[Serialize(true, false)]
public bool HideItems
{
get { return hideItems; }
@@ -38,7 +38,7 @@ namespace Barotrauma.Items.Components
}
private bool hideItems;
[SerializableProperty(false, false)]
[Serialize(false, false)]
public bool DrawInventory
{
get { return drawInventory; }
@@ -47,7 +47,7 @@ namespace Barotrauma.Items.Components
private bool drawInventory;
//the position of the first item in the container
[SerializableProperty("0.0,0.0", false)]
[Serialize("0.0,0.0", false)]
public Vector2 ItemPos
{
get { return itemPos; }
@@ -56,7 +56,7 @@ namespace Barotrauma.Items.Components
private Vector2 itemPos;
//item[i].Pos = itemPos + itemInterval*i
[SerializableProperty("0.0,0.0", false)]
[Serialize("0.0,0.0", false)]
public Vector2 ItemInterval
{
get { return itemInterval; }
@@ -64,7 +64,7 @@ namespace Barotrauma.Items.Components
}
private Vector2 itemInterval;
[SerializableProperty(0.0f, false)]
[Serialize(0.0f, false)]
public float ItemRotation
{
get { return MathHelper.ToDegrees(itemRotation); }
@@ -73,7 +73,7 @@ namespace Barotrauma.Items.Components
private float itemRotation;
[SerializableProperty("0.5,0.9", false)]
[Serialize("0.5,0.9", false)]
public Vector2 HudPos
{
get { return hudPos; }
@@ -84,7 +84,7 @@ namespace Barotrauma.Items.Components
}
private Vector2 hudPos;
[SerializableProperty(5, false)]
[Serialize(5, false)]
public int SlotsPerRow
{
get { return slotsPerRow; }
@@ -23,7 +23,7 @@ namespace Barotrauma.Items.Components
// }
//}
[Editable, SerializableProperty(2000.0f, true)]
[Editable, Serialize(2000.0f, true)]
public float MaxForce
{
get { return maxForce; }
@@ -16,21 +16,21 @@ namespace Barotrauma.Items.Components
bool hasPower;
[Editable, SerializableProperty(false, true)]
[Editable, Serialize(false, true)]
public bool RequireWaterDetectors
{
get;
set;
}
[Editable, SerializableProperty(true, true)]
[Editable, Serialize(true, true)]
public bool RequireOxygenDetectors
{
get;
set;
}
[Editable, SerializableProperty(false, true)]
[Editable, Serialize(false, true)]
public bool ShowHullIntegrity
{
get;
@@ -29,7 +29,7 @@ namespace Barotrauma.Items.Components
private set;
}
[Editable, SerializableProperty(100.0f, true)]
[Editable, Serialize(100.0f, true)]
public float GeneratedAmount
{
get { return generatedAmount; }
@@ -15,7 +15,7 @@ namespace Barotrauma.Items.Components
public Hull hull1;
[SerializableProperty(0.0f, true)]
[Serialize(0.0f, true)]
public float FlowPercentage
{
get { return flowPercentage; }
@@ -27,7 +27,7 @@ namespace Barotrauma.Items.Components
}
}
[SerializableProperty(80.0f, false)]
[Serialize(80.0f, false)]
public float MaxFlow
{
get { return maxFlow; }
@@ -26,14 +26,14 @@ namespace Barotrauma.Items.Components
private float displayBorderSize;
[SerializableProperty(10000.0f, false)]
[Serialize(10000.0f, false)]
public float Range
{
get { return range; }
set { range = MathHelper.Clamp(value, 0.0f, 100000.0f); }
}
[SerializableProperty(false, false)]
[Serialize(false, false)]
public bool DetectSubmarineWalls
{
get;
@@ -54,7 +54,7 @@ namespace Barotrauma.Items.Components
private float? nextServerLogWriteTime;
private float lastServerLogWriteTime;
[Editable, SerializableProperty(9500.0f, true)]
[Editable, Serialize(9500.0f, true)]
public float MeltDownTemp
{
get { return meltDownTemp; }
@@ -64,7 +64,7 @@ namespace Barotrauma.Items.Components
}
}
[Editable, SerializableProperty(9000.0f, true)]
[Editable, Serialize(9000.0f, true)]
public float FireTemp
{
get { return fireTemp; }
@@ -74,7 +74,7 @@ namespace Barotrauma.Items.Components
}
}
[Editable, SerializableProperty(1.0f, true)]
[Editable, Serialize(1.0f, true)]
public float PowerPerTemp
{
get { return powerPerTemp; }
@@ -84,7 +84,7 @@ namespace Barotrauma.Items.Components
}
}
[SerializableProperty(0.0f, true)]
[Serialize(0.0f, true)]
public float FissionRate
{
get { return fissionRate; }
@@ -95,7 +95,7 @@ namespace Barotrauma.Items.Components
}
}
[SerializableProperty(0.0f, true)]
[Serialize(0.0f, true)]
public float CoolingRate
{
get { return coolingRate; }
@@ -106,7 +106,7 @@ namespace Barotrauma.Items.Components
}
}
[SerializableProperty(0.0f, true)]
[Serialize(0.0f, true)]
public float Temperature
{
get { return temperature; }
@@ -122,7 +122,7 @@ namespace Barotrauma.Items.Components
return (temperature > 0.0f);
}
[SerializableProperty(false, true)]
[Serialize(false, true)]
public bool AutoTemp
{
get { return autoTemp; }
@@ -139,7 +139,7 @@ namespace Barotrauma.Items.Components
public float AvailableFuel { get; set; }
[SerializableProperty(500.0f, true)]
[Serialize(500.0f, true)]
public float ShutDownTemp
{
get { return shutDownTemp; }
@@ -67,7 +67,7 @@ namespace Barotrauma.Items.Components
}
}
[Editable, SerializableProperty(0.5f, true)]
[Editable, Serialize(0.5f, true)]
public float NeutralBallastLevel
{
get { return neutralBallastLevel; }
@@ -336,7 +336,7 @@ namespace Barotrauma.Items.Components
{
if (connection.Name == "velocity_in")
{
currVelocity = XMLExtensions.ParseToVector2(signal, false);
currVelocity = XMLExtensions.ParseVector2(signal, false);
}
else
{
@@ -32,21 +32,21 @@ namespace Barotrauma.Items.Components
private set;
}
[Editable, SerializableProperty(10.0f, true)]
[Editable, Serialize(10.0f, true)]
public float MaxOutPut
{
set { maxOutput = value; }
get { return maxOutput; }
}
[SerializableProperty(10.0f, true), Editable]
[Serialize(10.0f, true), Editable]
public float Capacity
{
get { return capacity; }
set { capacity = Math.Max(value, 1.0f); }
}
[Editable, SerializableProperty(0.0f, true)]
[Editable, Serialize(0.0f, true)]
public float Charge
{
get { return charge; }
@@ -63,7 +63,7 @@ namespace Barotrauma.Items.Components
}
}
[SerializableProperty(10.0f, true), Editable]
[Serialize(10.0f, true), Editable]
public float RechargeSpeed
{
get { return rechargeSpeed; }
@@ -75,7 +75,7 @@ namespace Barotrauma.Items.Components
}
}
[SerializableProperty(10.0f, false), Editable]
[Serialize(10.0f, false), Editable]
public float MaxRechargeSpeed
{
get { return maxRechargeSpeed; }
@@ -18,14 +18,14 @@ namespace Barotrauma.Items.Components
//the maximum amount of power the item can draw from connected items
protected float powerConsumption;
[Editable, SerializableProperty(0.5f, true)]
[Editable, Serialize(0.5f, true)]
public float MinVoltage
{
get { return minVoltage; }
set { minVoltage = value; }
}
[Editable, SerializableProperty(0.0f, true)]
[Editable, Serialize(0.0f, true)]
public float PowerConsumption
{
get { return powerConsumption; }
@@ -33,7 +33,7 @@ namespace Barotrauma.Items.Components
}
[SerializableProperty(false,true)]
[Serialize(false,true)]
public override bool IsActive
{
get { return base.IsActive; }
@@ -44,14 +44,14 @@ namespace Barotrauma.Items.Components
}
}
[SerializableProperty(0.0f, true)]
[Serialize(0.0f, true)]
public float CurrPowerConsumption
{
get {return currPowerConsumption; }
set { currPowerConsumption = value; }
}
[SerializableProperty(0.0f, true)]
[Serialize(0.0f, true)]
public float Voltage
{
get { return voltage; }
@@ -23,35 +23,35 @@ namespace Barotrauma.Items.Components
public Character User;
[SerializableProperty(10.0f, false)]
[Serialize(10.0f, false)]
public float LaunchImpulse
{
get { return launchImpulse; }
set { launchImpulse = value; }
}
[SerializableProperty(false, false)]
[Serialize(false, false)]
public bool CharacterUsable
{
get { return characterUsable; }
set { characterUsable = value; }
}
[SerializableProperty(false, false)]
[Serialize(false, false)]
public bool DoesStick
{
get { return doesStick; }
set { doesStick = value; }
}
[SerializableProperty(false, false)]
[Serialize(false, false)]
public bool Hitscan
{
get;
set;
}
[SerializableProperty(false, false)]
[Serialize(false, false)]
public bool RemoveOnHit
{
get;
@@ -13,7 +13,7 @@ namespace Barotrauma.Items.Components
//the output is sent if both inputs have received a signal within the timeframe
protected float timeFrame;
[InGameEditable, SerializableProperty(0.0f, true)]
[InGameEditable, Serialize(0.0f, true)]
public float TimeFrame
{
get { return timeFrame; }
@@ -23,14 +23,14 @@ namespace Barotrauma.Items.Components
}
}
[InGameEditable, SerializableProperty("1", true)]
[InGameEditable, Serialize("1", true)]
public string Output
{
get { return output; }
set { output = value; }
}
[InGameEditable, SerializableProperty("", true)]
[InGameEditable, Serialize("", true)]
public string FalseOutput
{
get { return falseOutput; }
@@ -15,7 +15,7 @@ namespace Barotrauma.Items.Components
private Queue<Tuple<string, DateTime>> signalQueue;
[InGameEditable, SerializableProperty(1.0f, true)]
[InGameEditable, Serialize(1.0f, true)]
public float Delay
{
get { return (float)delay.TotalSeconds; }
@@ -21,7 +21,7 @@ namespace Barotrauma.Items.Components
private bool castShadows;
[Editable, SerializableProperty(100.0f, true)]
[Editable, Serialize(100.0f, true)]
public float Range
{
get { return range; }
@@ -31,7 +31,7 @@ namespace Barotrauma.Items.Components
}
}
[Editable, SerializableProperty(true, true)]
[Editable, Serialize(true, true)]
public bool CastShadows
{
get { return castShadows; }
@@ -44,7 +44,7 @@ namespace Barotrauma.Items.Components
}
}
[Editable, SerializableProperty(false, true)]
[Editable, Serialize(false, true)]
public bool IsOn
{
get { return IsActive; }
@@ -57,7 +57,7 @@ namespace Barotrauma.Items.Components
}
}
[SerializableProperty(0.0f, false)]
[Serialize(0.0f, false)]
public float Flicker
{
get { return flicker; }
@@ -67,7 +67,7 @@ namespace Barotrauma.Items.Components
}
}
[InGameEditable, SerializableProperty("1.0,1.0,1.0,1.0", true)]
[InGameEditable, Serialize("1.0,1.0,1.0,1.0", true)]
public Color LightColor
{
get { return lightColor; }
@@ -207,7 +207,7 @@ namespace Barotrauma.Items.Components
IsActive = (signal != "0");
break;
case "set_color":
LightColor = XMLExtensions.ParseToColor(signal, false);
LightColor = XMLExtensions.ParseColor(signal, false);
break;
}
}
@@ -17,7 +17,7 @@ namespace Barotrauma.Items.Components
private float updateTimer;
[InGameEditable, SerializableProperty(0.0f, true)]
[InGameEditable, Serialize(0.0f, true)]
public float Range
{
get { return range; }
@@ -27,14 +27,14 @@ namespace Barotrauma.Items.Components
}
}
[InGameEditable, SerializableProperty("1", true)]
[InGameEditable, Serialize("1", true)]
public string Output
{
get { return output; }
set { output = value; }
}
[InGameEditable, SerializableProperty("", true)]
[InGameEditable, Serialize("", true)]
public string FalseOutput
{
get { return falseOutput; }
@@ -20,14 +20,14 @@ namespace Barotrauma.Items.Components
private float phase;
[InGameEditable, SerializableProperty(WaveType.Pulse, true)]
[InGameEditable, Serialize(WaveType.Pulse, true)]
public WaveType OutputType
{
get;
set;
}
[InGameEditable, SerializableProperty(1.0f, true)]
[InGameEditable, Serialize(1.0f, true)]
public float Frequency
{
get { return frequency; }
@@ -16,14 +16,14 @@ namespace Barotrauma.Items.Components
private Regex regex;
[InGameEditable, SerializableProperty("1", true)]
[InGameEditable, Serialize("1", true)]
public string Output
{
get { return output; }
set { output = value; }
}
[InGameEditable, SerializableProperty("", true)]
[InGameEditable, Serialize("", true)]
public string Expression
{
get { return expression; }
@@ -11,7 +11,7 @@ namespace Barotrauma.Items.Components
private bool isOn;
[Editable, SerializableProperty(1000.0f, true)]
[Editable, Serialize(1000.0f, true)]
public float MaxPower
{
get { return maxPower; }
@@ -21,7 +21,7 @@ namespace Barotrauma.Items.Components
}
}
[Editable, SerializableProperty(false, true)]
[Editable, Serialize(false, true)]
public bool IsOn
{
get
@@ -8,20 +8,20 @@ namespace Barotrauma.Items.Components
private string targetSignal;
[InGameEditable, SerializableProperty("1", true)]
[InGameEditable, Serialize("1", true)]
public string Output
{
get { return output; }
set { output = value; }
}
[InGameEditable, SerializableProperty("0", true)]
[InGameEditable, Serialize("0", true)]
public string FalseOutput
{
get { return falseOutput; }
set { falseOutput = value; }
}
[InGameEditable, SerializableProperty("", true)]
[InGameEditable, Serialize("", true)]
public string TargetSignal
{
get { return targetSignal; }
@@ -14,14 +14,14 @@ namespace Barotrauma.Items.Components
private int channel;
[SerializableProperty(20000.0f, false)]
[Serialize(20000.0f, false)]
public float Range
{
get { return range; }
set { range = Math.Max(value, 0.0f); }
}
[InGameEditable, SerializableProperty(1, true)]
[InGameEditable, Serialize(1, true)]
public int Channel
{
get { return channel; }
@@ -31,7 +31,7 @@ namespace Barotrauma.Items.Components
}
}
[Editable, SerializableProperty(false, false)]
[Editable, Serialize(false, false)]
public bool LinkToChat
{
get;
@@ -26,7 +26,7 @@ namespace Barotrauma.Items.Components
Camera cam;
[SerializableProperty("0,0", false)]
[Serialize("0,0", false)]
public Vector2 BarrelPos
{
get
@@ -39,21 +39,21 @@ namespace Barotrauma.Items.Components
}
}
[SerializableProperty(0.0f, false)]
[Serialize(0.0f, false)]
public float LaunchImpulse
{
get { return launchImpulse; }
set { launchImpulse = value; }
}
[SerializableProperty(5.0f, false)]
[Serialize(5.0f, false)]
public float Reload
{
get { return reloadTime; }
set { reloadTime = value; }
}
[SerializableProperty("0.0,0.0", true), Editable]
[Serialize("0.0,0.0", true), Editable]
public Vector2 RotationLimits
{
get
@@ -350,7 +350,7 @@ namespace Barotrauma.Items.Components
switch (connection.Name)
{
case "position_in":
Vector2 receivedPos = XMLExtensions.ParseToVector2(signal, false);
Vector2 receivedPos = XMLExtensions.ParseVector2(signal, false);
Vector2 centerPos = new Vector2(item.WorldRect.X + barrelPos.X, item.WorldRect.Y - barrelPos.Y);
@@ -35,14 +35,14 @@ namespace Barotrauma.Items.Components
private Vector2 armorSector;
[SerializableProperty(0.0f, false)]
[Serialize(0.0f, false)]
public float ArmorValue
{
get { return armorValue; }
set { armorValue = MathHelper.Clamp(value, 0.0f, 100.0f); }
}
[SerializableProperty("0.0,360.0", false)]
[Serialize("0.0,360.0", false)]
public Vector2 ArmorSector
{
get { return armorSector; }
@@ -23,7 +23,7 @@ namespace Barotrauma
OnImpact
}
partial class Item : MapEntity, IDamageable, IPropertyObject, IServerSerializable, IClientSerializable
partial class Item : MapEntity, IDamageable, ISerializableEntity, IServerSerializable, IClientSerializable
{
const float MaxVel = 64.0f;
@@ -64,8 +64,8 @@ namespace Barotrauma
//a dictionary containing lists of the status effects in all the components of the item
private Dictionary<ActionType, List<StatusEffect>> statusEffectLists;
public readonly Dictionary<string, ObjectProperty> properties;
public Dictionary<string, ObjectProperty> ObjectProperties
public readonly Dictionary<string, SerializableProperty> properties;
public Dictionary<string, SerializableProperty> SerializableProperties
{
get { return properties; }
}
@@ -169,14 +169,11 @@ namespace Barotrauma
}
protected Color spriteColor;
[Editable, SerializableProperty("1.0,1.0,1.0,1.0", true)]
public string SpriteColor
[Editable, Serialize("1.0,1.0,1.0,1.0", true)]
public Color SpriteColor
{
get { return XMLExtensions.Vector4ToString(spriteColor.ToVector4()); }
set
{
spriteColor = new Color(XMLExtensions.ParseToVector4(value));
}
get { return spriteColor; }
set { spriteColor = value; }
}
public Color Color
@@ -220,7 +217,7 @@ namespace Barotrauma
get { return condition; }
}
[Editable, SerializableProperty("", true)]
[Editable, Serialize("", true)]
public string Tags
{
get { return string.Join(",",tags); }
@@ -313,11 +310,11 @@ namespace Barotrauma
#endif
}
public List<IPropertyObject> AllPropertyObjects
public List<ISerializableEntity> AllPropertyObjects
{
get
{
List<IPropertyObject> pobjects = new List<IPropertyObject>();
List<ISerializableEntity> pobjects = new List<ISerializableEntity>();
pobjects.Add(this);
foreach (ItemComponent ic in components)
{
@@ -359,7 +356,7 @@ namespace Barotrauma
XElement element = prefab.ConfigElement;
if (element == null) return;
properties = ObjectProperty.DeserializeProperties(this, element);
properties = SerializableProperty.DeserializeProperties(this, element);
if (submarine == null || !submarine.Loading) FindHull();
@@ -457,14 +454,14 @@ namespace Barotrauma
public override MapEntity Clone()
{
Item clone = new Item(rect, prefab, Submarine);
foreach (KeyValuePair<string, ObjectProperty> property in properties)
foreach (KeyValuePair<string, SerializableProperty> property in properties)
{
if (!property.Value.Attributes.OfType<Editable>().Any()) continue;
clone.properties[property.Key].TrySetValue(property.Value.GetValue());
}
for (int i = 0; i < components.Count; i++)
{
foreach (KeyValuePair<string, ObjectProperty> property in components[i].properties)
foreach (KeyValuePair<string, SerializableProperty> property in components[i].properties)
{
if (!property.Value.Attributes.OfType<Editable>().Any()) continue;
clone.components[i].properties[property.Key].TrySetValue(property.Value.GetValue());
@@ -706,7 +703,7 @@ namespace Barotrauma
}
}
List<IPropertyObject> targets = new List<IPropertyObject>();
List<ISerializableEntity> targets = new List<ISerializableEntity>();
if (containedItems != null)
{
if (effect.Targets.HasFlag(StatusEffect.TargetType.Contained))
@@ -1235,13 +1232,13 @@ namespace Barotrauma
}
public List<ObjectProperty> GetProperties<T>()
public List<SerializableProperty> GetProperties<T>()
{
List<ObjectProperty> editableProperties = ObjectProperty.GetProperties<T>(this);
List<SerializableProperty> editableProperties = SerializableProperty.GetProperties<T>(this);
foreach (ItemComponent ic in components)
{
List<ObjectProperty> componentProperties = ObjectProperty.GetProperties<T>(ic);
List<SerializableProperty> componentProperties = SerializableProperty.GetProperties<T>(ic);
foreach (var property in componentProperties)
{
editableProperties.Add(property);
@@ -1355,15 +1352,15 @@ namespace Barotrauma
private void WritePropertyChange(NetBuffer msg, object[] extraData)
{
var allProperties = GetProperties<InGameEditable>();
ObjectProperty objectProperty = extraData[1] as ObjectProperty;
if (objectProperty != null)
SerializableProperty property = extraData[1] as SerializableProperty;
if (property != null)
{
if (allProperties.Count > 1)
{
msg.WriteRangedInteger(0, allProperties.Count - 1, allProperties.IndexOf(objectProperty));
msg.WriteRangedInteger(0, allProperties.Count - 1, allProperties.IndexOf(property));
}
object value = objectProperty.GetValue();
object value = property.GetValue();
if (value is string)
{
msg.Write((string)value);
@@ -1398,24 +1395,24 @@ namespace Barotrauma
propertyIndex = msg.ReadRangedInteger(0, allProperties.Count-1);
}
ObjectProperty objectProperty = allProperties[propertyIndex];
SerializableProperty property = allProperties[propertyIndex];
Type type = objectProperty.PropertyType;
Type type = property.PropertyType;
if (type == typeof(string))
{
objectProperty.TrySetValue(msg.ReadString());
property.TrySetValue(msg.ReadString());
}
else if (type == typeof(float))
{
objectProperty.TrySetValue(msg.ReadFloat());
property.TrySetValue(msg.ReadFloat());
}
else if (type == typeof(int))
{
objectProperty.TrySetValue(msg.ReadInt32());
property.TrySetValue(msg.ReadInt32());
}
else if (type == typeof(bool))
{
objectProperty.TrySetValue(msg.ReadBoolean());
property.TrySetValue(msg.ReadBoolean());
}
else
{
@@ -1424,7 +1421,7 @@ namespace Barotrauma
if (GameMain.Server != null)
{
GameMain.Server.CreateEntityEvent(this, new object[] { NetEntityEvent.Type.ChangeProperty, objectProperty });
GameMain.Server.CreateEntityEvent(this, new object[] { NetEntityEvent.Type.ChangeProperty, property });
}
}
@@ -1638,12 +1635,12 @@ namespace Barotrauma
foreach (XAttribute attribute in element.Attributes())
{
ObjectProperty property = null;
SerializableProperty property = null;
if (!item.properties.TryGetValue(attribute.Name.ToString(), out property)) continue;
bool shouldBeLoaded = false;
foreach (var propertyAttribute in property.Attributes.OfType<SerializableProperty>())
foreach (var propertyAttribute in property.Attributes.OfType<Serialize>())
{
if (propertyAttribute.isSaveable)
{
@@ -1713,7 +1710,7 @@ namespace Barotrauma
element.Add(new XAttribute("linked", string.Join(",", linkedToIDs)));
}
ObjectProperty.SerializeProperties(this, element);
SerializableProperty.SerializeProperties(this, element);
foreach (ItemComponent ic in components)
{
@@ -289,7 +289,7 @@ namespace Barotrauma
string spriteColorStr = element.GetAttributeString("spritecolor", "1.0,1.0,1.0,1.0");
SpriteColor = new Color(XMLExtensions.ParseToVector4(spriteColorStr));
SpriteColor = new Color(XMLExtensions.ParseVector4(spriteColorStr));
price = element.GetAttributeInt("price", 0);