diff --git a/Barotrauma/BarotraumaClient/Source/Items/Components/ItemLabel.cs b/Barotrauma/BarotraumaClient/Source/Items/Components/ItemLabel.cs
index bd68e0a6f..5601c342b 100644
--- a/Barotrauma/BarotraumaClient/Source/Items/Components/ItemLabel.cs
+++ b/Barotrauma/BarotraumaClient/Source/Items/Components/ItemLabel.cs
@@ -10,7 +10,7 @@ namespace Barotrauma.Items.Components
private Color textColor;
- [HasDefaultValue("", true), Editable(100)]
+ [SerializableProperty("", true), Editable(100)]
public string Text
{
get { return textBlock.Text.Replace("\n", ""); }
@@ -27,18 +27,17 @@ namespace Barotrauma.Items.Components
}
}
- [Editable, HasDefaultValue("0.0,0.0,0.0,1.0", true)]
- public string TextColor
+ [Editable, SerializableProperty("0.0,0.0,0.0,1.0", true)]
+ public Color TextColor
{
- get { return XMLExtensions.Vector4ToString(textColor.ToVector4()); }
+ get { return textColor; }
set
{
- textColor = new Color(XMLExtensions.ParseToVector4(value));
- if (textBlock != null) textBlock.TextColor = textColor;
+ if (textBlock != null) textBlock.TextColor = value;
}
}
- [Editable, HasDefaultValue(1.0f, true)]
+ [Editable, SerializableProperty(1.0f, true)]
public float TextScale
{
get { return textBlock == null ? 1.0f : textBlock.TextScale; }
diff --git a/Barotrauma/BarotraumaServer/Source/Items/Components/ItemLabel.cs b/Barotrauma/BarotraumaServer/Source/Items/Components/ItemLabel.cs
index d402d04be..7297dd6a1 100644
--- a/Barotrauma/BarotraumaServer/Source/Items/Components/ItemLabel.cs
+++ b/Barotrauma/BarotraumaServer/Source/Items/Components/ItemLabel.cs
@@ -5,21 +5,21 @@ namespace Barotrauma.Items.Components
{
partial class ItemLabel : ItemComponent, IDrawableComponent
{
- [HasDefaultValue("", true), Editable(100)]
+ [SerializableProperty("", true), Editable(100)]
public string Text
{
get;
set;
}
- [Editable, HasDefaultValue("0.0,0.0,0.0,1.0", true)]
- public string TextColor
+ [Editable, SerializableProperty("0.0,0.0,0.0,1.0", true)]
+ public Color TextColor
{
get;
set;
}
- [Editable, HasDefaultValue(1.0f, true)]
+ [Editable, SerializableProperty(1.0f, true)]
public float TextScale
{
get;
diff --git a/Barotrauma/BarotraumaShared/BarotraumaShared.projitems b/Barotrauma/BarotraumaShared/BarotraumaShared.projitems
index 7df40beff..94ccb34d2 100644
--- a/Barotrauma/BarotraumaShared/BarotraumaShared.projitems
+++ b/Barotrauma/BarotraumaShared/BarotraumaShared.projitems
@@ -1381,7 +1381,6 @@
-
@@ -1493,10 +1492,12 @@
-
+
+
+
@@ -1507,6 +1508,5 @@
-
\ No newline at end of file
diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/DockingPort.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/DockingPort.cs
index 6b41f81f0..2d5424c87 100644
--- a/Barotrauma/BarotraumaShared/Source/Items/Components/DockingPort.cs
+++ b/Barotrauma/BarotraumaShared/Source/Items/Components/DockingPort.cs
@@ -47,21 +47,21 @@ namespace Barotrauma.Items.Components
set { dockingDir = value; }
}
- [HasDefaultValue("32.0,32.0", false)]
- public string DistanceTolerance
+ [SerializableProperty("32.0,32.0", false)]
+ public Vector2 DistanceTolerance
{
- get { return XMLExtensions.Vector2ToString(distanceTolerance); }
- set { distanceTolerance = XMLExtensions.ParseToVector2(value); }
+ get { return distanceTolerance; }
+ set { distanceTolerance = value; }
}
- [HasDefaultValue(32.0f, false)]
+ [SerializableProperty(32.0f, false)]
public float DockedDistance
{
get;
set;
}
- [HasDefaultValue(true, false)]
+ [SerializableProperty(true, false)]
public bool IsHorizontal
{
get;
diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Door.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Door.cs
index eb68e1949..72b5d3505 100644
--- a/Barotrauma/BarotraumaShared/Source/Items/Components/Door.cs
+++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Door.cs
@@ -111,7 +111,7 @@ namespace Barotrauma.Items.Components
}
}
- [HasDefaultValue("0.0,0.0,0.0,0.0", false)]
+ [SerializableProperty("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)); }
@@ -130,7 +130,7 @@ namespace Barotrauma.Items.Components
get { return window; }
}
- [Editable, HasDefaultValue(false, true)]
+ [Editable, SerializableProperty(false, true)]
public bool IsOpen
{
get { return isOpen; }
diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/Holdable.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/Holdable.cs
index ce805bd63..78644ec5e 100644
--- a/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/Holdable.cs
+++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/Holdable.cs
@@ -29,49 +29,49 @@ namespace Barotrauma.Items.Components
//the angle in which the Character holds the item
protected float holdAngle;
- [HasDefaultValue(false, true)]
+ [SerializableProperty(false, true)]
public bool Attached
{
get { return attached && item.ParentInventory == null; }
set { attached = value; }
}
- [HasDefaultValue(false, false)]
+ [SerializableProperty(false, false)]
public bool ControlPose
{
get;
set;
}
- [HasDefaultValue(false, false)]
+ [SerializableProperty(false, false)]
public bool Attachable
{
get { return attachable; }
set { attachable = value; }
}
- [HasDefaultValue(false, false)]
+ [SerializableProperty(false, false)]
public bool AttachedByDefault
{
get { return attachedByDefault; }
set { attachedByDefault = value; }
}
- [HasDefaultValue("0.0,0.0", false)]
- public string HoldPos
+ [SerializableProperty("0.0,0.0", false)]
+ public Vector2 HoldPos
{
- get { return XMLExtensions.Vector2ToString(ConvertUnits.ToDisplayUnits(holdPos)); }
- set { holdPos = ConvertUnits.ToSimUnits(XMLExtensions.ParseToVector2(value)); }
+ get { return ConvertUnits.ToDisplayUnits(holdPos); }
+ set { holdPos = ConvertUnits.ToSimUnits(value); }
}
- [HasDefaultValue("0.0,0.0", false)]
- public string AimPos
+ [SerializableProperty("0.0,0.0", false)]
+ public Vector2 AimPos
{
- get { return XMLExtensions.Vector2ToString(ConvertUnits.ToDisplayUnits(aimPos)); }
- set { aimPos = ConvertUnits.ToSimUnits(XMLExtensions.ParseToVector2(value)); }
+ get { return ConvertUnits.ToDisplayUnits(aimPos); }
+ set { aimPos = ConvertUnits.ToSimUnits(value); }
}
- [HasDefaultValue(0.0f, false)]
+ [SerializableProperty(0.0f, false)]
public float HoldAngle
{
get { return MathHelper.ToDegrees(holdAngle); }
diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/MeleeWeapon.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/MeleeWeapon.cs
index b8be537c3..8caf762de 100644
--- a/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/MeleeWeapon.cs
+++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/MeleeWeapon.cs
@@ -24,14 +24,14 @@ namespace Barotrauma.Items.Components
private float reloadTimer;
- [HasDefaultValue(0.0f, false)]
+ [SerializableProperty(0.0f, false)]
public float Range
{
get { return ConvertUnits.ToDisplayUnits(range); }
set { range = ConvertUnits.ToSimUnits(value); }
}
- [HasDefaultValue(0.5f, false)]
+ [SerializableProperty(0.5f, false)]
public float Reload
{
get { return reload; }
diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/Propulsion.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/Propulsion.cs
index 32c761938..4af2d320c 100644
--- a/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/Propulsion.cs
+++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/Propulsion.cs
@@ -22,7 +22,7 @@ namespace Barotrauma.Items.Components
private UsableIn usableIn;
- [HasDefaultValue(0.0f, false)]
+ [SerializableProperty(0.0f, false)]
public float Force
{
get { return force; }
@@ -30,7 +30,7 @@ namespace Barotrauma.Items.Components
}
#if CLIENT
- [HasDefaultValue("", false)]
+ [SerializableProperty("", false)]
public string Particles
{
get { return particles; }
diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/RangedWeapon.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/RangedWeapon.cs
index 1eb88fc9f..fbaf49304 100644
--- a/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/RangedWeapon.cs
+++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/RangedWeapon.cs
@@ -13,28 +13,28 @@ namespace Barotrauma.Items.Components
private Vector2 barrelPos;
- [HasDefaultValue("0.0,0.0", false)]
+ [SerializableProperty("0.0,0.0", false)]
public string BarrelPos
{
get { return XMLExtensions.Vector2ToString(ConvertUnits.ToDisplayUnits(barrelPos)); }
set { barrelPos = ConvertUnits.ToSimUnits(XMLExtensions.ParseToVector2(value)); }
}
- [HasDefaultValue(1.0f, false)]
+ [SerializableProperty(1.0f, false)]
public float Reload
{
get { return reload; }
set { reload = Math.Max(value, 0.0f); }
}
- [HasDefaultValue(0.0f, false)]
+ [SerializableProperty(0.0f, false)]
public float Spread
{
get;
set;
}
- [HasDefaultValue(0.0f, false)]
+ [SerializableProperty(0.0f, false)]
public float UnskilledSpread
{
get;
diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/RepairTool.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/RepairTool.cs
index 4d385c36d..19e08b039 100644
--- a/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/RepairTool.cs
+++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/RepairTool.cs
@@ -21,48 +21,48 @@ namespace Barotrauma.Items.Components
private float activeTimer;
- [HasDefaultValue(0.0f, false)]
+ [SerializableProperty(0.0f, false)]
public float Range
{
get { return range; }
set { range = value; }
}
- [HasDefaultValue(0.0f, false)]
+ [SerializableProperty(0.0f, false)]
public float StructureFixAmount
{
get; set;
}
- [HasDefaultValue(0.0f, false)]
+ [SerializableProperty(0.0f, false)]
public float LimbFixAmount
{
get; set;
}
- [HasDefaultValue(0.0f, false)]
+ [SerializableProperty(0.0f, false)]
public float ExtinquishAmount
{
get; set;
}
- [HasDefaultValue("", false)]
+ [SerializableProperty("", false)]
public string Particles
{
get { return particles; }
set { particles = value; }
}
- [HasDefaultValue(0.0f, false)]
+ [SerializableProperty(0.0f, false)]
public float ParticleSpeed
{
get; set;
}
- [HasDefaultValue("0.0,0.0", false)]
- public string BarrelPos
+ [SerializableProperty("0.0,0.0", false)]
+ public Vector2 BarrelPos
{
- get { return XMLExtensions.Vector2ToString(barrelPos); }
- set { barrelPos = XMLExtensions.ParseToVector2(value); }
+ get { return barrelPos; }
+ set { barrelPos = value; }
}
public Vector2 TransformedBarrelPos
diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/Throwable.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/Throwable.cs
index 344477c91..c53c8e502 100644
--- a/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/Throwable.cs
+++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/Throwable.cs
@@ -12,7 +12,7 @@ namespace Barotrauma.Items.Components
bool throwing;
- [HasDefaultValue(1.0f, false)]
+ [SerializableProperty(1.0f, false)]
public float ThrowForce
{
get { return throwForce; }
diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/ItemComponent.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/ItemComponent.cs
index c18441ad3..9ce4a7441 100644
--- a/Barotrauma/BarotraumaShared/Source/Items/Components/ItemComponent.cs
+++ b/Barotrauma/BarotraumaShared/Source/Items/Components/ItemComponent.cs
@@ -47,7 +47,7 @@ namespace Barotrauma.Items.Components
private string msg;
- [HasDefaultValue(0.0f, false)]
+ [SerializableProperty(0.0f, false)]
public float PickingTime
{
get;
@@ -103,21 +103,21 @@ namespace Barotrauma.Items.Components
}
}
- [HasDefaultValue(false, false)]
+ [SerializableProperty(false, false)]
public bool CanBePicked
{
get { return canBePicked; }
set { canBePicked = value; }
}
- [HasDefaultValue(false, false)]
+ [SerializableProperty(false, false)]
public bool DrawHudWhenEquipped
{
get;
private set;
}
- [HasDefaultValue(false, false)]
+ [SerializableProperty(false, false)]
public bool CanBeSelected
{
get { return canBeSelected; }
@@ -136,7 +136,7 @@ namespace Barotrauma.Items.Components
protected set;
}
- [HasDefaultValue(false, false)]
+ [SerializableProperty(false, false)]
public bool DeleteOnUse
{
get;
@@ -153,7 +153,7 @@ namespace Barotrauma.Items.Components
get { return name; }
}
- [HasDefaultValue("", false)]
+ [SerializableProperty("", false)]
public string Msg
{
get { return msg; }
@@ -205,7 +205,7 @@ namespace Barotrauma.Items.Components
DebugConsole.ThrowError("Invalid pick key in " + element + "!", e);
}
- properties = ObjectProperty.InitProperties(this, element);
+ properties = ObjectProperty.DeserializeProperties(this, element);
foreach (XElement subElement in element.Elements())
{
@@ -586,7 +586,7 @@ namespace Barotrauma.Items.Components
componentElement.Add(newElement);
}
- ObjectProperty.SaveProperties(this, componentElement);
+ ObjectProperty.SerializeProperties(this, componentElement);
parentElement.Add(componentElement);
return componentElement;
diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/ItemContainer.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/ItemContainer.cs
index 724153353..491603d62 100644
--- a/Barotrauma/BarotraumaShared/Source/Items/Components/ItemContainer.cs
+++ b/Barotrauma/BarotraumaShared/Source/Items/Components/ItemContainer.cs
@@ -18,7 +18,7 @@ namespace Barotrauma.Items.Components
private ushort[] itemIds;
//how many items can be contained
- [HasDefaultValue(5, false)]
+ [SerializableProperty(5, false)]
public int Capacity
{
get { return capacity; }
@@ -26,7 +26,7 @@ namespace Barotrauma.Items.Components
}
private int capacity;
- [HasDefaultValue(true, false)]
+ [SerializableProperty(true, false)]
public bool HideItems
{
get { return hideItems; }
@@ -38,7 +38,7 @@ namespace Barotrauma.Items.Components
}
private bool hideItems;
- [HasDefaultValue(false, false)]
+ [SerializableProperty(false, false)]
public bool DrawInventory
{
get { return drawInventory; }
@@ -47,24 +47,24 @@ namespace Barotrauma.Items.Components
private bool drawInventory;
//the position of the first item in the container
- [HasDefaultValue("0.0,0.0", false)]
- public string ItemPos
+ [SerializableProperty("0.0,0.0", false)]
+ public Vector2 ItemPos
{
- get { return XMLExtensions.Vector2ToString(itemPos); }
- set { itemPos = XMLExtensions.ParseToVector2(value); }
+ get { return itemPos; }
+ set { itemPos = value; }
}
private Vector2 itemPos;
//item[i].Pos = itemPos + itemInterval*i
- [HasDefaultValue("0.0,0.0", false)]
- public string ItemInterval
+ [SerializableProperty("0.0,0.0", false)]
+ public Vector2 ItemInterval
{
- get { return XMLExtensions.Vector2ToString(itemInterval); }
- set { itemInterval = XMLExtensions.ParseToVector2(value); }
+ get { return itemInterval; }
+ set { itemInterval = value; }
}
private Vector2 itemInterval;
- [HasDefaultValue(0.0f, false)]
+ [SerializableProperty(0.0f, false)]
public float ItemRotation
{
get { return MathHelper.ToDegrees(itemRotation); }
@@ -73,19 +73,18 @@ namespace Barotrauma.Items.Components
private float itemRotation;
- [HasDefaultValue("0.5,0.9", false)]
- public string HudPos
+ [SerializableProperty("0.5,0.9", false)]
+ public Vector2 HudPos
{
- get { return XMLExtensions.Vector2ToString(hudPos); }
+ get { return hudPos; }
set
{
- hudPos = XMLExtensions.ParseToVector2(value);
- //inventory.CenterPos = hudPos;
+ hudPos = value;
}
}
private Vector2 hudPos;
- [HasDefaultValue(5, false)]
+ [SerializableProperty(5, false)]
public int SlotsPerRow
{
get { return slotsPerRow; }
diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/Engine.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/Engine.cs
index 624ef4509..ba833fff3 100644
--- a/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/Engine.cs
+++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/Engine.cs
@@ -23,7 +23,7 @@ namespace Barotrauma.Items.Components
// }
//}
- [Editable, HasDefaultValue(2000.0f, true)]
+ [Editable, SerializableProperty(2000.0f, true)]
public float MaxForce
{
get { return maxForce; }
diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/MiniMap.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/MiniMap.cs
index 7180f4396..2c6a8c618 100644
--- a/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/MiniMap.cs
+++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/MiniMap.cs
@@ -16,21 +16,21 @@ namespace Barotrauma.Items.Components
bool hasPower;
- [Editable, HasDefaultValue(false, true)]
+ [Editable, SerializableProperty(false, true)]
public bool RequireWaterDetectors
{
get;
set;
}
- [Editable, HasDefaultValue(true, true)]
+ [Editable, SerializableProperty(true, true)]
public bool RequireOxygenDetectors
{
get;
set;
}
- [Editable, HasDefaultValue(false, true)]
+ [Editable, SerializableProperty(false, true)]
public bool ShowHullIntegrity
{
get;
diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/OxygenGenerator.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/OxygenGenerator.cs
index f5cc25cad..300287005 100644
--- a/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/OxygenGenerator.cs
+++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/OxygenGenerator.cs
@@ -29,7 +29,7 @@ namespace Barotrauma.Items.Components
private set;
}
- [Editable, HasDefaultValue(100.0f, true)]
+ [Editable, SerializableProperty(100.0f, true)]
public float GeneratedAmount
{
get { return generatedAmount; }
diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/Pump.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/Pump.cs
index 0a967dbe1..493a1c631 100644
--- a/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/Pump.cs
+++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/Pump.cs
@@ -15,7 +15,7 @@ namespace Barotrauma.Items.Components
public Hull hull1;
- [HasDefaultValue(0.0f, true)]
+ [SerializableProperty(0.0f, true)]
public float FlowPercentage
{
get { return flowPercentage; }
@@ -27,7 +27,7 @@ namespace Barotrauma.Items.Components
}
}
- [HasDefaultValue(80.0f, false)]
+ [SerializableProperty(80.0f, false)]
public float MaxFlow
{
get { return maxFlow; }
diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/Radar.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/Radar.cs
index 24b4f90af..bdf2a652c 100644
--- a/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/Radar.cs
+++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/Radar.cs
@@ -26,14 +26,14 @@ namespace Barotrauma.Items.Components
private float displayBorderSize;
- [HasDefaultValue(10000.0f, false)]
+ [SerializableProperty(10000.0f, false)]
public float Range
{
get { return range; }
set { range = MathHelper.Clamp(value, 0.0f, 100000.0f); }
}
- [HasDefaultValue(false, false)]
+ [SerializableProperty(false, false)]
public bool DetectSubmarineWalls
{
get;
diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/Reactor.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/Reactor.cs
index a36eaad89..8d67e57ea 100644
--- a/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/Reactor.cs
+++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/Reactor.cs
@@ -54,7 +54,7 @@ namespace Barotrauma.Items.Components
private float? nextServerLogWriteTime;
private float lastServerLogWriteTime;
- [Editable, HasDefaultValue(9500.0f, true)]
+ [Editable, SerializableProperty(9500.0f, true)]
public float MeltDownTemp
{
get { return meltDownTemp; }
@@ -64,7 +64,7 @@ namespace Barotrauma.Items.Components
}
}
- [Editable, HasDefaultValue(9000.0f, true)]
+ [Editable, SerializableProperty(9000.0f, true)]
public float FireTemp
{
get { return fireTemp; }
@@ -74,7 +74,7 @@ namespace Barotrauma.Items.Components
}
}
- [Editable, HasDefaultValue(1.0f, true)]
+ [Editable, SerializableProperty(1.0f, true)]
public float PowerPerTemp
{
get { return powerPerTemp; }
@@ -84,7 +84,7 @@ namespace Barotrauma.Items.Components
}
}
- [HasDefaultValue(0.0f, true)]
+ [SerializableProperty(0.0f, true)]
public float FissionRate
{
get { return fissionRate; }
@@ -95,7 +95,7 @@ namespace Barotrauma.Items.Components
}
}
- [HasDefaultValue(0.0f, true)]
+ [SerializableProperty(0.0f, true)]
public float CoolingRate
{
get { return coolingRate; }
@@ -106,7 +106,7 @@ namespace Barotrauma.Items.Components
}
}
- [HasDefaultValue(0.0f, true)]
+ [SerializableProperty(0.0f, true)]
public float Temperature
{
get { return temperature; }
@@ -122,7 +122,7 @@ namespace Barotrauma.Items.Components
return (temperature > 0.0f);
}
- [HasDefaultValue(false, true)]
+ [SerializableProperty(false, true)]
public bool AutoTemp
{
get { return autoTemp; }
@@ -139,7 +139,7 @@ namespace Barotrauma.Items.Components
public float AvailableFuel { get; set; }
- [HasDefaultValue(500.0f, true)]
+ [SerializableProperty(500.0f, true)]
public float ShutDownTemp
{
get { return shutDownTemp; }
diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/Steering.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/Steering.cs
index 64b557a13..b6201f868 100644
--- a/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/Steering.cs
+++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/Steering.cs
@@ -67,7 +67,7 @@ namespace Barotrauma.Items.Components
}
}
- [Editable, HasDefaultValue(0.5f, true)]
+ [Editable, SerializableProperty(0.5f, true)]
public float NeutralBallastLevel
{
get { return neutralBallastLevel; }
diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Power/PowerContainer.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Power/PowerContainer.cs
index 0821bbe09..57269bad5 100644
--- a/Barotrauma/BarotraumaShared/Source/Items/Components/Power/PowerContainer.cs
+++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Power/PowerContainer.cs
@@ -32,21 +32,21 @@ namespace Barotrauma.Items.Components
private set;
}
- [Editable, HasDefaultValue(10.0f, true)]
+ [Editable, SerializableProperty(10.0f, true)]
public float MaxOutPut
{
set { maxOutput = value; }
get { return maxOutput; }
}
- [HasDefaultValue(10.0f, true), Editable]
+ [SerializableProperty(10.0f, true), Editable]
public float Capacity
{
get { return capacity; }
set { capacity = Math.Max(value, 1.0f); }
}
- [Editable, HasDefaultValue(0.0f, true)]
+ [Editable, SerializableProperty(0.0f, true)]
public float Charge
{
get { return charge; }
@@ -63,7 +63,7 @@ namespace Barotrauma.Items.Components
}
}
- [HasDefaultValue(10.0f, true), Editable]
+ [SerializableProperty(10.0f, true), Editable]
public float RechargeSpeed
{
get { return rechargeSpeed; }
@@ -75,7 +75,7 @@ namespace Barotrauma.Items.Components
}
}
- [HasDefaultValue(10.0f, false), Editable]
+ [SerializableProperty(10.0f, false), Editable]
public float MaxRechargeSpeed
{
get { return maxRechargeSpeed; }
diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Power/Powered.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Power/Powered.cs
index ae3b06291..90c5c835d 100644
--- a/Barotrauma/BarotraumaShared/Source/Items/Components/Power/Powered.cs
+++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Power/Powered.cs
@@ -18,14 +18,14 @@ namespace Barotrauma.Items.Components
//the maximum amount of power the item can draw from connected items
protected float powerConsumption;
- [Editable, HasDefaultValue(0.5f, true)]
+ [Editable, SerializableProperty(0.5f, true)]
public float MinVoltage
{
get { return minVoltage; }
set { minVoltage = value; }
}
- [Editable, HasDefaultValue(0.0f, true)]
+ [Editable, SerializableProperty(0.0f, true)]
public float PowerConsumption
{
get { return powerConsumption; }
@@ -33,7 +33,7 @@ namespace Barotrauma.Items.Components
}
- [HasDefaultValue(false,true)]
+ [SerializableProperty(false,true)]
public override bool IsActive
{
get { return base.IsActive; }
@@ -44,14 +44,14 @@ namespace Barotrauma.Items.Components
}
}
- [HasDefaultValue(0.0f, true)]
+ [SerializableProperty(0.0f, true)]
public float CurrPowerConsumption
{
get {return currPowerConsumption; }
set { currPowerConsumption = value; }
}
- [HasDefaultValue(0.0f, true)]
+ [SerializableProperty(0.0f, true)]
public float Voltage
{
get { return voltage; }
diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Projectile.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Projectile.cs
index a095b0062..610d5b7ca 100644
--- a/Barotrauma/BarotraumaShared/Source/Items/Components/Projectile.cs
+++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Projectile.cs
@@ -23,35 +23,35 @@ namespace Barotrauma.Items.Components
public Character User;
- [HasDefaultValue(10.0f, false)]
+ [SerializableProperty(10.0f, false)]
public float LaunchImpulse
{
get { return launchImpulse; }
set { launchImpulse = value; }
}
- [HasDefaultValue(false, false)]
+ [SerializableProperty(false, false)]
public bool CharacterUsable
{
get { return characterUsable; }
set { characterUsable = value; }
}
- [HasDefaultValue(false, false)]
+ [SerializableProperty(false, false)]
public bool DoesStick
{
get { return doesStick; }
set { doesStick = value; }
}
- [HasDefaultValue(false, false)]
+ [SerializableProperty(false, false)]
public bool Hitscan
{
get;
set;
}
- [HasDefaultValue(false, false)]
+ [SerializableProperty(false, false)]
public bool RemoveOnHit
{
get;
diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/AndComponent.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/AndComponent.cs
index 83aaffc9c..2d19980f9 100644
--- a/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/AndComponent.cs
+++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/AndComponent.cs
@@ -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, HasDefaultValue(0.0f, true)]
+ [InGameEditable, SerializableProperty(0.0f, true)]
public float TimeFrame
{
get { return timeFrame; }
@@ -23,14 +23,14 @@ namespace Barotrauma.Items.Components
}
}
- [InGameEditable, HasDefaultValue("1", true)]
+ [InGameEditable, SerializableProperty("1", true)]
public string Output
{
get { return output; }
set { output = value; }
}
- [InGameEditable, HasDefaultValue("", true)]
+ [InGameEditable, SerializableProperty("", true)]
public string FalseOutput
{
get { return falseOutput; }
diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/DelayComponent.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/DelayComponent.cs
index 26f43867d..3524d521b 100644
--- a/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/DelayComponent.cs
+++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/DelayComponent.cs
@@ -15,7 +15,7 @@ namespace Barotrauma.Items.Components
private Queue> signalQueue;
- [InGameEditable, HasDefaultValue(1.0f, true)]
+ [InGameEditable, SerializableProperty(1.0f, true)]
public float Delay
{
get { return (float)delay.TotalSeconds; }
diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/LightComponent.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/LightComponent.cs
index 0eff47348..b029506b0 100644
--- a/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/LightComponent.cs
+++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/LightComponent.cs
@@ -21,7 +21,7 @@ namespace Barotrauma.Items.Components
private bool castShadows;
- [Editable, HasDefaultValue(100.0f, true)]
+ [Editable, SerializableProperty(100.0f, true)]
public float Range
{
get { return range; }
@@ -31,7 +31,7 @@ namespace Barotrauma.Items.Components
}
}
- [Editable, HasDefaultValue(true, true)]
+ [Editable, SerializableProperty(true, true)]
public bool CastShadows
{
get { return castShadows; }
@@ -44,7 +44,7 @@ namespace Barotrauma.Items.Components
}
}
- [Editable, HasDefaultValue(false, true)]
+ [Editable, SerializableProperty(false, true)]
public bool IsOn
{
get { return IsActive; }
@@ -57,7 +57,7 @@ namespace Barotrauma.Items.Components
}
}
- [HasDefaultValue(0.0f, false)]
+ [SerializableProperty(0.0f, false)]
public float Flicker
{
get { return flicker; }
@@ -67,19 +67,11 @@ namespace Barotrauma.Items.Components
}
}
- [InGameEditable, HasDefaultValue("1.0,1.0,1.0,1.0", true)]
- public string LightColor
+ [InGameEditable, SerializableProperty("1.0,1.0,1.0,1.0", true)]
+ public Color LightColor
{
- get { return XMLExtensions.Vector4ToString(lightColor.ToVector4(), "0.00"); }
- set
- {
- Vector4 newColor = XMLExtensions.ParseToVector4(value, false);
- newColor.X = MathHelper.Clamp(newColor.X, 0.0f, 1.0f);
- newColor.Y = MathHelper.Clamp(newColor.Y, 0.0f, 1.0f);
- newColor.Z = MathHelper.Clamp(newColor.Z, 0.0f, 1.0f);
- newColor.W = MathHelper.Clamp(newColor.W, 0.0f, 1.0f);
- lightColor = new Color(newColor);
- }
+ get { return lightColor; }
+ set { lightColor = value; }
}
public override void Move(Vector2 amount)
@@ -215,7 +207,7 @@ namespace Barotrauma.Items.Components
IsActive = (signal != "0");
break;
case "set_color":
- LightColor = signal;
+ LightColor = XMLExtensions.ParseToColor(signal, false);
break;
}
}
diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/MotionSensor.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/MotionSensor.cs
index 96f1a067d..39a287832 100644
--- a/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/MotionSensor.cs
+++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/MotionSensor.cs
@@ -17,7 +17,7 @@ namespace Barotrauma.Items.Components
private float updateTimer;
- [InGameEditable, HasDefaultValue(0.0f, true)]
+ [InGameEditable, SerializableProperty(0.0f, true)]
public float Range
{
get { return range; }
@@ -27,14 +27,14 @@ namespace Barotrauma.Items.Components
}
}
- [InGameEditable, HasDefaultValue("1", true)]
+ [InGameEditable, SerializableProperty("1", true)]
public string Output
{
get { return output; }
set { output = value; }
}
- [InGameEditable, HasDefaultValue("", true)]
+ [InGameEditable, SerializableProperty("", true)]
public string FalseOutput
{
get { return falseOutput; }
diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/OscillatorComponent.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/OscillatorComponent.cs
index f9d28c261..efa4e8a31 100644
--- a/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/OscillatorComponent.cs
+++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/OscillatorComponent.cs
@@ -20,14 +20,14 @@ namespace Barotrauma.Items.Components
private float phase;
- [InGameEditable, HasDefaultValue(WaveType.Pulse, true)]
+ [InGameEditable, SerializableProperty(WaveType.Pulse, true)]
public WaveType OutputType
{
get;
set;
}
- [InGameEditable, HasDefaultValue(1.0f, true)]
+ [InGameEditable, SerializableProperty(1.0f, true)]
public float Frequency
{
get { return frequency; }
diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/RegExFindComponent.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/RegExFindComponent.cs
index 50ee0e452..43a1663ba 100644
--- a/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/RegExFindComponent.cs
+++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/RegExFindComponent.cs
@@ -16,14 +16,14 @@ namespace Barotrauma.Items.Components
private Regex regex;
- [InGameEditable, HasDefaultValue("1", true)]
+ [InGameEditable, SerializableProperty("1", true)]
public string Output
{
get { return output; }
set { output = value; }
}
- [InGameEditable, HasDefaultValue("", true)]
+ [InGameEditable, SerializableProperty("", true)]
public string Expression
{
get { return expression; }
diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/RelayComponent.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/RelayComponent.cs
index 175169d02..7ecec9621 100644
--- a/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/RelayComponent.cs
+++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/RelayComponent.cs
@@ -11,7 +11,7 @@ namespace Barotrauma.Items.Components
private bool isOn;
- [Editable, HasDefaultValue(1000.0f, true)]
+ [Editable, SerializableProperty(1000.0f, true)]
public float MaxPower
{
get { return maxPower; }
@@ -21,7 +21,7 @@ namespace Barotrauma.Items.Components
}
}
- [Editable, HasDefaultValue(false, true)]
+ [Editable, SerializableProperty(false, true)]
public bool IsOn
{
get
diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/SignalCheckComponent.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/SignalCheckComponent.cs
index 8214b6279..9bb1a4a15 100644
--- a/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/SignalCheckComponent.cs
+++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/SignalCheckComponent.cs
@@ -8,20 +8,20 @@ namespace Barotrauma.Items.Components
private string targetSignal;
- [InGameEditable, HasDefaultValue("1", true)]
+ [InGameEditable, SerializableProperty("1", true)]
public string Output
{
get { return output; }
set { output = value; }
}
- [InGameEditable, HasDefaultValue("0", true)]
+ [InGameEditable, SerializableProperty("0", true)]
public string FalseOutput
{
get { return falseOutput; }
set { falseOutput = value; }
}
- [InGameEditable, HasDefaultValue("", true)]
+ [InGameEditable, SerializableProperty("", true)]
public string TargetSignal
{
get { return targetSignal; }
diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/WifiComponent.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/WifiComponent.cs
index d3a3762e3..aa3932a11 100644
--- a/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/WifiComponent.cs
+++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/WifiComponent.cs
@@ -14,14 +14,14 @@ namespace Barotrauma.Items.Components
private int channel;
- [HasDefaultValue(20000.0f, false)]
+ [SerializableProperty(20000.0f, false)]
public float Range
{
get { return range; }
set { range = Math.Max(value, 0.0f); }
}
- [InGameEditable, HasDefaultValue(1, true)]
+ [InGameEditable, SerializableProperty(1, true)]
public int Channel
{
get { return channel; }
@@ -31,7 +31,7 @@ namespace Barotrauma.Items.Components
}
}
- [Editable, HasDefaultValue(false, false)]
+ [Editable, SerializableProperty(false, false)]
public bool LinkToChat
{
get;
diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Turret.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Turret.cs
index 4f7b2e57b..0c924a459 100644
--- a/Barotrauma/BarotraumaShared/Source/Items/Components/Turret.cs
+++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Turret.cs
@@ -26,49 +26,44 @@ namespace Barotrauma.Items.Components
Camera cam;
- [HasDefaultValue("0,0", false)]
- public string BarrelPos
+ [SerializableProperty("0,0", false)]
+ public Vector2 BarrelPos
{
get
{
- return XMLExtensions.Vector2ToString(barrelPos);
+ return barrelPos;
}
set
{
- barrelPos = XMLExtensions.ParseToVector2(value);
+ barrelPos = value;
}
}
- [HasDefaultValue(0.0f, false)]
+ [SerializableProperty(0.0f, false)]
public float LaunchImpulse
{
get { return launchImpulse; }
set { launchImpulse = value; }
}
- [HasDefaultValue(5.0f, false)]
+ [SerializableProperty(5.0f, false)]
public float Reload
{
get { return reloadTime; }
set { reloadTime = value; }
}
- [HasDefaultValue("0.0,0.0", true), Editable]
- public string RotationLimits
+ [SerializableProperty("0.0,0.0", true), Editable]
+ public Vector2 RotationLimits
{
get
{
- Vector2 limits = new Vector2(minRotation, maxRotation);
- limits.X = MathHelper.ToDegrees(limits.X);
- limits.Y = MathHelper.ToDegrees(limits.Y);
-
- return XMLExtensions.Vector2ToString(limits);
+ return new Vector2(MathHelper.ToDegrees(minRotation), MathHelper.ToDegrees(maxRotation));
}
set
{
- Vector2 vector = XMLExtensions.ParseToVector2(value);
- minRotation = MathHelper.ToRadians(vector.X);
- maxRotation = MathHelper.ToRadians(vector.Y);
+ minRotation = MathHelper.ToRadians(value.X);
+ maxRotation = MathHelper.ToRadians(value.Y);
rotation = (minRotation + maxRotation) / 2;
}
diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Wearable.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Wearable.cs
index d928cb4d0..e8f01d43f 100644
--- a/Barotrauma/BarotraumaShared/Source/Items/Components/Wearable.cs
+++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Wearable.cs
@@ -35,22 +35,21 @@ namespace Barotrauma.Items.Components
private Vector2 armorSector;
- [HasDefaultValue(0.0f, false)]
+ [SerializableProperty(0.0f, false)]
public float ArmorValue
{
get { return armorValue; }
set { armorValue = MathHelper.Clamp(value, 0.0f, 100.0f); }
}
- [HasDefaultValue("0.0,360.0", false)]
- public string ArmorSector
+ [SerializableProperty("0.0,360.0", false)]
+ public Vector2 ArmorSector
{
- get { return XMLExtensions.Vector2ToString(armorSector); }
+ get { return armorSector; }
set
{
- armorSector = XMLExtensions.ParseToVector2(value);
- armorSector.X = MathHelper.ToRadians(armorSector.X);
- armorSector.Y = MathHelper.ToRadians(armorSector.Y);
+ armorSector.X = MathHelper.ToRadians(value.X);
+ armorSector.Y = MathHelper.ToRadians(value.Y);
}
}
diff --git a/Barotrauma/BarotraumaShared/Source/Items/Item.cs b/Barotrauma/BarotraumaShared/Source/Items/Item.cs
index 31e1513ac..419d5616e 100644
--- a/Barotrauma/BarotraumaShared/Source/Items/Item.cs
+++ b/Barotrauma/BarotraumaShared/Source/Items/Item.cs
@@ -169,7 +169,7 @@ namespace Barotrauma
}
protected Color spriteColor;
- [Editable, HasDefaultValue("1.0,1.0,1.0,1.0", true)]
+ [Editable, SerializableProperty("1.0,1.0,1.0,1.0", true)]
public string SpriteColor
{
get { return XMLExtensions.Vector4ToString(spriteColor.ToVector4()); }
@@ -220,7 +220,7 @@ namespace Barotrauma
get { return condition; }
}
- [Editable, HasDefaultValue("", true)]
+ [Editable, SerializableProperty("", true)]
public string Tags
{
get { return string.Join(",",tags); }
@@ -359,7 +359,7 @@ namespace Barotrauma
XElement element = prefab.ConfigElement;
if (element == null) return;
- properties = ObjectProperty.InitProperties(this, element);
+ properties = ObjectProperty.DeserializeProperties(this, element);
if (submarine == null || !submarine.Loading) FindHull();
@@ -1400,7 +1400,7 @@ namespace Barotrauma
ObjectProperty objectProperty = allProperties[propertyIndex];
- Type type = objectProperty.GetType();
+ Type type = objectProperty.PropertyType;
if (type == typeof(string))
{
objectProperty.TrySetValue(msg.ReadString());
@@ -1643,7 +1643,7 @@ namespace Barotrauma
bool shouldBeLoaded = false;
- foreach (var propertyAttribute in property.Attributes.OfType())
+ foreach (var propertyAttribute in property.Attributes.OfType())
{
if (propertyAttribute.isSaveable)
{
@@ -1713,7 +1713,7 @@ namespace Barotrauma
element.Add(new XAttribute("linked", string.Join(",", linkedToIDs)));
}
- ObjectProperty.SaveProperties(this, element);
+ ObjectProperty.SerializeProperties(this, element);
foreach (ItemComponent ic in components)
{
diff --git a/Barotrauma/BarotraumaShared/Source/Map/Hull.cs b/Barotrauma/BarotraumaShared/Source/Map/Hull.cs
index a6b7e6856..670f085eb 100644
--- a/Barotrauma/BarotraumaShared/Source/Map/Hull.cs
+++ b/Barotrauma/BarotraumaShared/Source/Map/Hull.cs
@@ -139,7 +139,7 @@ namespace Barotrauma
}
}
- [HasDefaultValue(90.0f, true)]
+ [SerializableProperty(90.0f, true)]
public float Oxygen
{
get { return oxygen; }
diff --git a/Barotrauma/BarotraumaShared/Source/Map/Levels/LevelGenerationParams.cs b/Barotrauma/BarotraumaShared/Source/Map/Levels/LevelGenerationParams.cs
index 1b05bf297..c9136ad02 100644
--- a/Barotrauma/BarotraumaShared/Source/Map/Levels/LevelGenerationParams.cs
+++ b/Barotrauma/BarotraumaShared/Source/Map/Levels/LevelGenerationParams.cs
@@ -102,7 +102,7 @@ namespace Barotrauma
set;
}
- [HasDefaultValue(1000, false)]
+ [SerializableProperty(1000, false)]
public int BackgroundSpriteAmount
{
get;
@@ -115,14 +115,14 @@ namespace Barotrauma
set;
}
- [HasDefaultValue(100000.0f, false)]
+ [SerializableProperty(100000.0f, false)]
public float Width
{
get { return width; }
set { width = Math.Max(value, 2000.0f); }
}
- [HasDefaultValue(50000.0f, false)]
+ [SerializableProperty(50000.0f, false)]
public float Height
{
get { return height; }
@@ -160,7 +160,7 @@ namespace Barotrauma
}
}
- [HasDefaultValue(5, false)]
+ [SerializableProperty(5, false)]
public int SmallTunnelCount
{
get { return smallTunnelCount; }
@@ -177,21 +177,21 @@ namespace Barotrauma
}
}
- [HasDefaultValue(-300000.0f, false)]
+ [SerializableProperty(-300000.0f, false)]
public float SeaFloorDepth
{
get { return seaFloorBaseDepth; }
set { seaFloorBaseDepth = MathHelper.Clamp(value, Level.MaxEntityDepth, 0.0f); }
}
- [HasDefaultValue(1000.0f, false)]
+ [SerializableProperty(1000.0f, false)]
public float SeaFloorVariance
{
get { return seaFloorVariance; }
set { seaFloorVariance = value; }
}
- [HasDefaultValue(0, false)]
+ [SerializableProperty(0, false)]
public int MountainCountMin
{
get { return mountainCountMin; }
@@ -201,7 +201,7 @@ namespace Barotrauma
}
}
- [HasDefaultValue(0, false)]
+ [SerializableProperty(0, false)]
public int MountainCountMax
{
get { return mountainCountMax; }
@@ -211,7 +211,7 @@ namespace Barotrauma
}
}
- [HasDefaultValue(1000.0f, false)]
+ [SerializableProperty(1000.0f, false)]
public float MountainHeightMin
{
get { return mountainHeightMin; }
@@ -221,7 +221,7 @@ namespace Barotrauma
}
}
- [HasDefaultValue(5000.0f, false)]
+ [SerializableProperty(5000.0f, false)]
public float MountainHeightMax
{
get { return mountainHeightMax; }
@@ -231,14 +231,14 @@ namespace Barotrauma
}
}
- [HasDefaultValue(1, false)]
+ [SerializableProperty(1, false)]
public int RuinCount
{
get { return ruinCount; }
set { ruinCount = MathHelper.Clamp(value, 0, 10); }
}
- [HasDefaultValue(0.4f, false)]
+ [SerializableProperty(0.4f, false)]
public float BottomHoleProbability
{
get { return bottomHoleProbability; }
@@ -278,7 +278,7 @@ namespace Barotrauma
private LevelGenerationParams(XElement element)
{
Name = element == null ? "default" : element.Name.ToString();
- ObjectProperties = ObjectProperty.InitProperties(this, element);
+ ObjectProperties = ObjectProperty.DeserializeProperties(this, element);
Vector3 colorVector = element.GetAttributeVector3("BackgroundColor", new Vector3(50, 46, 20));
BackgroundColor = new Color((int)colorVector.X, (int)colorVector.Y, (int)colorVector.Z);
diff --git a/Barotrauma/BarotraumaShared/Source/Networking/GameServerSettings.cs b/Barotrauma/BarotraumaShared/Source/Networking/GameServerSettings.cs
index 11d6a6fc8..d5b8c0faf 100644
--- a/Barotrauma/BarotraumaShared/Source/Networking/GameServerSettings.cs
+++ b/Barotrauma/BarotraumaShared/Source/Networking/GameServerSettings.cs
@@ -86,7 +86,7 @@ namespace Barotrauma.Networking
private List clientPermissions = new List();
- [HasDefaultValue(true, true)]
+ [SerializableProperty(true, true)]
public bool RandomizeSeed
{
get;
@@ -94,21 +94,21 @@ namespace Barotrauma.Networking
}
- [HasDefaultValue(300.0f, true)]
+ [SerializableProperty(300.0f, true)]
public float RespawnInterval
{
get;
private set;
}
- [HasDefaultValue(180.0f, true)]
+ [SerializableProperty(180.0f, true)]
public float MaxTransportTime
{
get;
private set;
}
- [HasDefaultValue(0.2f, true)]
+ [SerializableProperty(0.2f, true)]
public float MinRespawnRatio
{
get;
@@ -116,42 +116,42 @@ namespace Barotrauma.Networking
}
- [HasDefaultValue(60.0f, true)]
+ [SerializableProperty(60.0f, true)]
public float AutoRestartInterval
{
get;
set;
}
- [HasDefaultValue(true, true)]
+ [SerializableProperty(true, true)]
public bool AllowSpectating
{
get;
private set;
}
- [HasDefaultValue(true, true)]
+ [SerializableProperty(true, true)]
public bool EndRoundAtLevelEnd
{
get;
private set;
}
- [HasDefaultValue(true, true)]
+ [SerializableProperty(true, true)]
public bool SaveServerLogs
{
get;
private set;
}
- [HasDefaultValue(true, true)]
+ [SerializableProperty(true, true)]
public bool AllowFileTransfers
{
get;
private set;
}
- [HasDefaultValue(800, true)]
+ [SerializableProperty(800, true)]
private int LinesPerLogFile
{
get
@@ -175,7 +175,7 @@ namespace Barotrauma.Networking
}
}
- [HasDefaultValue(true, true)]
+ [SerializableProperty(true, true)]
public bool AllowRespawn
{
get;
@@ -203,21 +203,21 @@ namespace Barotrauma.Networking
get { return banList; }
}
- [HasDefaultValue(true, true)]
+ [SerializableProperty(true, true)]
public bool AllowVoteKick
{
get;
private set;
}
- [HasDefaultValue(0.6f, true)]
+ [SerializableProperty(0.6f, true)]
public float EndVoteRequiredRatio
{
get;
private set;
}
- [HasDefaultValue(0.6f, true)]
+ [SerializableProperty(0.6f, true)]
public float KickVoteRequiredRatio
{
get;
@@ -228,7 +228,7 @@ namespace Barotrauma.Networking
{
XDocument doc = new XDocument(new XElement("serversettings"));
- ObjectProperty.SaveProperties(this, doc.Root, true);
+ ObjectProperty.SerializeProperties(this, doc.Root, true);
doc.Root.SetAttributeValue("name", name);
doc.Root.SetAttributeValue("public", isPublic);
@@ -279,7 +279,7 @@ namespace Barotrauma.Networking
doc = new XDocument(new XElement("serversettings"));
}
- ObjectProperties = ObjectProperty.InitProperties(this, doc.Root);
+ ObjectProperties = ObjectProperty.DeserializeProperties(this, doc.Root);
AutoRestart = doc.Root.GetAttributeBool("autorestart", false);
#if CLIENT
diff --git a/Barotrauma/BarotraumaShared/Source/IPropertyObject.cs b/Barotrauma/BarotraumaShared/Source/Serialization/IPropertyObject.cs
similarity index 100%
rename from Barotrauma/BarotraumaShared/Source/IPropertyObject.cs
rename to Barotrauma/BarotraumaShared/Source/Serialization/IPropertyObject.cs
diff --git a/Barotrauma/BarotraumaShared/Source/Properties.cs b/Barotrauma/BarotraumaShared/Source/Serialization/Properties.cs
similarity index 54%
rename from Barotrauma/BarotraumaShared/Source/Properties.cs
rename to Barotrauma/BarotraumaShared/Source/Serialization/Properties.cs
index 9cea99346..63a494907 100644
--- a/Barotrauma/BarotraumaShared/Source/Properties.cs
+++ b/Barotrauma/BarotraumaShared/Source/Serialization/Properties.cs
@@ -1,4 +1,5 @@
-using System;
+using Microsoft.Xna.Framework;
+using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
@@ -27,12 +28,12 @@ namespace Barotrauma
[AttributeUsage(AttributeTargets.Property)]
- public class HasDefaultValue : System.Attribute
+ public class SerializableProperty : System.Attribute
{
public object defaultValue;
public bool isSaveable;
- public HasDefaultValue(object defaultValue, bool isSaveable)
+ public SerializableProperty(object defaultValue, bool isSaveable)
{
this.defaultValue = defaultValue;
this.isSaveable = isSaveable;
@@ -41,36 +42,44 @@ namespace Barotrauma
class ObjectProperty
{
- readonly PropertyDescriptor property;
- readonly PropertyInfo propertyInfo;
- readonly object obj;
-
+ private readonly PropertyDescriptor propertyDescriptor;
+ private readonly PropertyInfo propertyInfo;
+ private readonly object obj;
+
public string Name
{
- get { return property.Name; }
+ get { return propertyDescriptor.Name; }
}
public AttributeCollection Attributes
{
- get { return property.Attributes; }
+ get { return propertyDescriptor.Attributes; }
+ }
+
+ public Type PropertyType
+ {
+ get
+ {
+ return propertyInfo.PropertyType;
+ }
}
public ObjectProperty(PropertyDescriptor property, object obj)
{
- this.property = property;
+ this.propertyDescriptor = property;
propertyInfo = property.ComponentType.GetProperty(property.Name);
this.obj = obj;
}
-
+
public bool TrySetValue(string value)
{
if (value == null) return false;
-
- if (property.PropertyType == typeof(string))
+
+ if (propertyDescriptor.PropertyType == typeof(string))
{
propertyInfo.SetValue(obj, value, null);
}
- else if (property.PropertyType == typeof(float))
+ else if (propertyDescriptor.PropertyType == typeof(float))
{
float floatVal;
if (float.TryParse(value, NumberStyles.Float, CultureInfo.InvariantCulture, out floatVal))
@@ -78,11 +87,11 @@ namespace Barotrauma
propertyInfo.SetValue(obj, floatVal, null);
}
}
- else if (property.PropertyType == typeof(bool))
+ else if (propertyDescriptor.PropertyType == typeof(bool))
{
- propertyInfo.SetValue(obj, value.ToLowerInvariant() == "true", null);
+ propertyInfo.SetValue(obj, value.ToLowerInvariant() == "true", null);
}
- else if (property.PropertyType == typeof(int))
+ else if (propertyDescriptor.PropertyType == typeof(int))
{
int intVal;
if (int.TryParse(value, out intVal))
@@ -90,7 +99,23 @@ namespace Barotrauma
propertyInfo.SetValue(obj, intVal, null);
}
}
- else if (property.PropertyType.IsEnum)
+ else if (propertyDescriptor.PropertyType == typeof(Vector2))
+ {
+ propertyInfo.SetValue(obj, XMLExtensions.ParseToVector2(value));
+ }
+ else if (propertyDescriptor.PropertyType == typeof(Vector3))
+ {
+ propertyInfo.SetValue(obj, XMLExtensions.ParseToVector3(value));
+ }
+ else if (propertyDescriptor.PropertyType == typeof(Vector4))
+ {
+ propertyInfo.SetValue(obj, XMLExtensions.ParseToVector4(value));
+ }
+ else if (propertyDescriptor.PropertyType == typeof(Color))
+ {
+ propertyInfo.SetValue(obj, XMLExtensions.ParseToColor(value));
+ }
+ else if (propertyDescriptor.PropertyType.IsEnum)
{
object enumVal;
try
@@ -118,18 +143,36 @@ namespace Barotrauma
public bool TrySetValue(object value)
{
if (value == null) return false;
-
- if (property.PropertyType != value.GetType())
- {
- DebugConsole.ThrowError("Failed to set the value of the property \"" + Name + "\" of \"" + obj.ToString() + "\" to " + value.ToString());
-
- DebugConsole.ThrowError("(Non-matching type, should be " + property.PropertyType + " instead of " + value.GetType() + ")");
- return false;
- }
-
- if (obj == null || property == null) return false;
+ if (obj == null || propertyDescriptor == null) return false;
try
{
+ if (value.GetType() == typeof(string) &&
+ propertyDescriptor.PropertyType == typeof(Vector2))
+ {
+ propertyInfo.SetValue(obj, XMLExtensions.ParseToVector2(value.ToString()));
+ }
+ else if (value.GetType() == typeof(string) &&
+ propertyDescriptor.PropertyType == typeof(Vector3))
+ {
+ propertyInfo.SetValue(obj, XMLExtensions.ParseToVector3(value.ToString()));
+ }
+ else if (value.GetType() == typeof(string) &&
+ propertyDescriptor.PropertyType == typeof(Vector4))
+ {
+ propertyInfo.SetValue(obj, XMLExtensions.ParseToVector4(value.ToString()));
+ }
+ else if (value.GetType() == typeof(string) &&
+ propertyDescriptor.PropertyType == typeof(Color))
+ {
+ propertyInfo.SetValue(obj, XMLExtensions.ParseToColor(value.ToString()));
+ }
+ else if (propertyDescriptor.PropertyType != value.GetType())
+ {
+ DebugConsole.ThrowError("Failed to set the value of the property \"" + Name + "\" of \"" + obj.ToString() + "\" to " + value.ToString());
+ DebugConsole.ThrowError("(Non-matching type, should be " + propertyDescriptor.PropertyType + " instead of " + value.GetType() + ")");
+ return false;
+ }
+
propertyInfo.SetValue(obj, value, null);
}
catch
@@ -143,13 +186,13 @@ namespace Barotrauma
{
try
{
- propertyInfo.SetValue(obj, value, null);
+ propertyInfo.SetValue(obj, value, null);
}
catch
{
return false;
}
-
+
return true;
}
@@ -181,7 +224,7 @@ namespace Barotrauma
public object GetValue()
{
- if (obj == null || property == null) return false;
+ if (obj == null || propertyDescriptor == null) return false;
try
{
@@ -192,12 +235,7 @@ namespace Barotrauma
return false;
}
}
-
- public Type GetType()
- {
- return propertyInfo.PropertyType;
- }
-
+
public static List GetProperties(IPropertyObject obj)
{
List editableProperties = new List();
@@ -210,7 +248,7 @@ namespace Barotrauma
return editableProperties;
}
- public static Dictionary GetProperties(IPropertyObject obj)
+ public static Dictionary GetProperties(IPropertyObject obj)
{
var properties = TypeDescriptor.GetProperties(obj.GetType()).Cast();
@@ -224,12 +262,17 @@ namespace Barotrauma
return dictionary;
}
+ /*///
+ /// Sets all serializable properties to their default value
+ ///
+ ///
+ ///
public static Dictionary InitProperties(IPropertyObject obj)
{
- return InitProperties(obj, null);
- }
+ return DeserializeProperties(obj, null);
+ }*/
- public static Dictionary InitProperties(IPropertyObject obj, XElement element)
+ public static Dictionary DeserializeProperties(IPropertyObject obj, XElement element)
{
var properties = TypeDescriptor.GetProperties(obj.GetType()).Cast();
@@ -241,14 +284,14 @@ namespace Barotrauma
dictionary.Add(property.Name.ToLowerInvariant(), objProperty);
//set the value of the property to the default value if there is one
- foreach (var ini in property.Attributes.OfType())
+ foreach (var ini in property.Attributes.OfType())
{
objProperty.TrySetValue(ini.defaultValue);
break;
}
}
-
- if (element!=null)
+
+ if (element != null)
{
//go through all the attributes in the xml element
//and set the value of the matching property if it is initializable
@@ -256,47 +299,80 @@ namespace Barotrauma
{
ObjectProperty property = null;
if (!dictionary.TryGetValue(attribute.Name.ToString().ToLowerInvariant(), out property)) continue;
- if (!property.Attributes.OfType().Any()) continue;
+ if (!property.Attributes.OfType().Any()) continue;
property.TrySetValue(attribute.Value);
- }
+ }
}
return dictionary;
}
-
- public static void SaveProperties(IPropertyObject obj, XElement element, bool saveIfDefault = false)
+
+ public static void SerializeProperties(IPropertyObject obj, XElement element, bool saveIfDefault = false)
{
- var saveProperties = GetProperties(obj);
+ var saveProperties = GetProperties(obj);
foreach (var property in saveProperties)
{
object value = property.GetValue();
if (value == null) continue;
-
+
if (!saveIfDefault)
{
//only save
// - if the attribute is saveable and it's different from the default value
// - or can be changed in-game or in the editor
bool save = false;
- foreach (var attribute in property.Attributes.OfType())
+ foreach (var attribute in property.Attributes.OfType())
{
- if ((attribute.isSaveable && !attribute.defaultValue.Equals(value)) ||
+ if ((attribute.isSaveable && !attribute.defaultValue.Equals(value)) ||
property.Attributes.OfType().Any())
{
save = true;
break;
- }
+ }
}
if (!save) continue;
}
string stringValue;
- if (value is float)
+ if (value.GetType() == typeof(float))
{
- //do this to make sure the decimal point isn't converted to a comma or anything like that
+ //make sure the decimal point isn't converted to a comma or anything else
stringValue = ((float)value).ToString("G", CultureInfo.InvariantCulture);
}
+ else if (value.GetType() == typeof(Vector2))
+ {
+ Vector2 vector = (Vector2)value;
+ stringValue =
+ vector.X.ToString("G", CultureInfo.InvariantCulture) + "," +
+ vector.Y.ToString("G", CultureInfo.InvariantCulture);
+ }
+ else if (value.GetType() == typeof(Vector3))
+ {
+ Vector3 vector = (Vector3)value;
+ stringValue =
+ vector.X.ToString("G", CultureInfo.InvariantCulture) + "," +
+ vector.Y.ToString("G", CultureInfo.InvariantCulture) + "," +
+ vector.Z.ToString("G", CultureInfo.InvariantCulture);
+ }
+ else if (value.GetType() == typeof(Vector4))
+ {
+ Vector4 vector = (Vector4)value;
+ stringValue =
+ vector.X.ToString("G", CultureInfo.InvariantCulture) + "," +
+ vector.Y.ToString("G", CultureInfo.InvariantCulture) + "," +
+ vector.Z.ToString("G", CultureInfo.InvariantCulture) + "," +
+ vector.W.ToString("G", CultureInfo.InvariantCulture);
+ }
+ else if (value.GetType() == typeof(Color))
+ {
+ Color color = (Color)value;
+ stringValue =
+ (color.R / 255.0f).ToString("G", CultureInfo.InvariantCulture) + "," +
+ (color.G / 255.0f).ToString("G", CultureInfo.InvariantCulture) + "," +
+ (color.B / 255.0f).ToString("G", CultureInfo.InvariantCulture) + "," +
+ (color.A / 255.0f).ToString("G", CultureInfo.InvariantCulture);
+ }
else
{
stringValue = value.ToString();
diff --git a/Barotrauma/BarotraumaShared/Source/Utils/XMLExtensions.cs b/Barotrauma/BarotraumaShared/Source/Serialization/XMLExtensions.cs
similarity index 92%
rename from Barotrauma/BarotraumaShared/Source/Utils/XMLExtensions.cs
rename to Barotrauma/BarotraumaShared/Source/Serialization/XMLExtensions.cs
index e5e4a25a7..d22beb4d3 100644
--- a/Barotrauma/BarotraumaShared/Source/Utils/XMLExtensions.cs
+++ b/Barotrauma/BarotraumaShared/Source/Serialization/XMLExtensions.cs
@@ -289,6 +289,28 @@ namespace Barotrauma
return vector;
}
+ public static Color ParseToColor(string stringColor, bool errorMessages = true)
+ {
+ string[] strComponents = stringColor.Split(',');
+
+ Color color = Color.White;
+
+ if (strComponents.Length < 3)
+ {
+ if (errorMessages) DebugConsole.ThrowError("Failed to parse the string \"" + stringColor + "\" to Color");
+ return Color.White;
+ }
+
+ float[] components = new float[4] { 1.0f, 1.0f, 1.0f, 1.0f };
+
+ for (int i = 0; i < 4 && i < strComponents.Length; i++)
+ {
+ float.TryParse(strComponents[i], NumberStyles.Float, CultureInfo.InvariantCulture, out components[i]);
+ }
+
+ return new Color(components[0], components[1], components[2], components[3]);
+ }
+
public static string Vector4ToString(Vector4 vector, string format = "G")
{
return vector.X.ToString(format, CultureInfo.InvariantCulture) + "," +