MapEntityPrefabs are deserialized using SerializableProperty

This commit is contained in:
Joonas Rikkonen
2017-11-14 23:12:55 +02:00
parent 04e3710a65
commit 08cf902cb8
6 changed files with 94 additions and 115 deletions
@@ -23,28 +23,15 @@ namespace Barotrauma
{
//static string contentFolder = "Content/Items/";
string configFile;
//should the camera focus on the construction when selected
protected bool focusOnSelected;
//the amount of "camera offset" when selecting the construction
protected float offsetOnSelected;
private readonly string configFile;
//default size
protected Vector2 size;
//how close the Character has to be to the item to pick it up
private float interactDistance;
// this can be used to allow items which are behind other items tp
private float interactPriority;
private bool interactThroughWalls;
//an area next to the construction
//the construction can be Activated() by a Character inside the area
public List<Rectangle> Triggers;
public readonly bool FireProof;
private float impactTolerance;
public string ConfigFile
@@ -72,54 +59,75 @@ namespace Barotrauma
private set;
}
//how close the Character has to be to the item to pick it up
[Serialize(120.0f, false)]
public float InteractDistance
{
get { return interactDistance; }
get;
private set;
}
// this can be used to allow items which are behind other items tp
[Serialize(0.0f, false)]
public float InteractPriority
{
get { return interactPriority; }
get;
private set;
}
[Serialize(false, false)]
public bool InteractThroughWalls
{
get { return interactThroughWalls; }
get;
private set;
}
public override bool IsLinkable
{
get { return isLinkable; }
}
//should the camera focus on the item when selected
[Serialize(false, false)]
public bool FocusOnSelected
{
get { return focusOnSelected; }
get;
private set;
}
//the amount of "camera offset" when selecting the construction
[Serialize(0.0f, false)]
public float OffsetOnSelected
{
get { return offsetOnSelected; }
get;
private set;
}
[Serialize(100.0f, false)]
public float Health
{
get;
private set;
}
[Serialize(false, false)]
public bool Indestructible
{
get;
private set;
}
[Serialize(false, false)]
public bool FireProof
{
get;
private set;
}
[Serialize(0.0f, false)]
public float ImpactTolerance
{
get { return impactTolerance; }
set { impactTolerance = Math.Max(value, 0.0f); }
}
[Serialize(false, false)]
public bool CanUseOnSelf
{
get;
@@ -231,7 +239,7 @@ namespace Barotrauma
}
}
public ItemPrefab (XElement element, string filePath)
public ItemPrefab(XElement element, string filePath)
{
configFile = filePath;
ConfigElement = element;
@@ -241,28 +249,6 @@ namespace Barotrauma
DebugConsole.Log(" " + name);
Description = element.GetAttributeString("description", "");
interactThroughWalls = element.GetAttributeBool("interactthroughwalls", false);
interactDistance = element.GetAttributeFloat("interactdistance", 120.0f); // Default to 120 as the new item picking method is tuned to this number
interactPriority = element.GetAttributeFloat("interactpriority", 0.0f);
isLinkable = element.GetAttributeBool("linkable", false);
ResizeHorizontal = element.GetAttributeBool("resizehorizontal", false);
ResizeVertical = element.GetAttributeBool("resizevertical", false);
focusOnSelected = element.GetAttributeBool("focusonselected", false);
offsetOnSelected = element.GetAttributeFloat("offsetonselected", 0.0f);
CanUseOnSelf = element.GetAttributeBool("canuseonself", false);
Health = element.GetAttributeFloat("health", 100.0f);
Indestructible = element.GetAttributeBool("indestructible", false);
FireProof = element.GetAttributeBool("fireproof", false);
ImpactTolerance = element.GetAttributeFloat("impacttolerance", 0.0f);
string aliases = element.GetAttributeString("aliases", "");
if (!string.IsNullOrWhiteSpace(aliases))
{
@@ -270,26 +256,21 @@ namespace Barotrauma
}
MapEntityCategory category;
if (!Enum.TryParse(element.GetAttributeString("category", "Misc"), true, out category))
{
category = MapEntityCategory.Misc;
}
Category = category;
SpriteColor = element.GetAttributeColor("spritecolor", Color.White);
price = element.GetAttributeInt("price", 0);
Triggers = new List<Rectangle>();
DeconstructItems = new List<DeconstructItem>();
DeconstructTime = 1.0f;
Tags = new List<string>();
Tags.AddRange(element.GetAttributeString("tags", "").Split(','));
SerializableProperty.DeserializeProperties(this, element);
foreach (XElement subElement in element.Elements())
{
switch (subElement.Name.ToString().ToLowerInvariant())