MapEntityPrefabs are deserialized using SerializableProperty
This commit is contained in:
@@ -105,7 +105,7 @@ namespace Barotrauma
|
||||
List<Vector2> points = new List<Vector2>();
|
||||
|
||||
var wallPrefabs =
|
||||
MapEntityPrefab.List.FindAll(mp => (mp is StructurePrefab) && ((StructurePrefab)mp).HasBody);
|
||||
MapEntityPrefab.List.FindAll(mp => (mp is StructurePrefab) && ((StructurePrefab)mp).Body);
|
||||
|
||||
foreach (XElement element in rootElement.Elements())
|
||||
{
|
||||
|
||||
@@ -17,15 +17,7 @@ namespace Barotrauma
|
||||
public readonly static List<MapEntityPrefab> List = new List<MapEntityPrefab>();
|
||||
|
||||
protected string name;
|
||||
|
||||
public List<string> Tags
|
||||
{
|
||||
get;
|
||||
protected set;
|
||||
}
|
||||
|
||||
protected bool isLinkable;
|
||||
|
||||
|
||||
public Sprite sprite;
|
||||
|
||||
//the position where the structure is being placed (needed when stretching the structure)
|
||||
@@ -34,35 +26,45 @@ namespace Barotrauma
|
||||
protected ConstructorInfo constructor;
|
||||
|
||||
//is it possible to stretch the entity horizontally/vertically
|
||||
[Serialize(false, false)]
|
||||
public bool ResizeHorizontal { get; protected set; }
|
||||
[Serialize(false, false)]
|
||||
public bool ResizeVertical { get; protected set; }
|
||||
|
||||
//which prefab has been selected for placing
|
||||
protected static MapEntityPrefab selected;
|
||||
|
||||
protected int price;
|
||||
private int price;
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return name; }
|
||||
}
|
||||
|
||||
public List<string> Tags
|
||||
{
|
||||
get;
|
||||
protected set;
|
||||
}
|
||||
|
||||
public static MapEntityPrefab Selected
|
||||
{
|
||||
get { return selected; }
|
||||
set { selected = value; }
|
||||
}
|
||||
|
||||
|
||||
[Serialize("", false)]
|
||||
public string Description
|
||||
{
|
||||
get;
|
||||
protected set;
|
||||
}
|
||||
|
||||
[Serialize(false, false)]
|
||||
public virtual bool IsLinkable
|
||||
{
|
||||
get { return isLinkable; }
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public MapEntityCategory Category
|
||||
@@ -71,15 +73,18 @@ namespace Barotrauma
|
||||
protected set;
|
||||
}
|
||||
|
||||
[Serialize("1.0,1.0,1.0,1.0", false)]
|
||||
public Color SpriteColor
|
||||
{
|
||||
get;
|
||||
protected set;
|
||||
}
|
||||
|
||||
[Serialize(0, false)]
|
||||
public int Price
|
||||
{
|
||||
get { return price; }
|
||||
protected set { price = Math.Max(value, 0); }
|
||||
}
|
||||
|
||||
//If a matching prefab is not found when loading a sub, the game will attempt to find a prefab with a matching alias.
|
||||
|
||||
@@ -70,7 +70,7 @@ namespace Barotrauma
|
||||
|
||||
public bool IsPlatform
|
||||
{
|
||||
get { return prefab.IsPlatform; }
|
||||
get { return prefab.Platform; }
|
||||
}
|
||||
|
||||
public Direction StairDirection
|
||||
@@ -86,7 +86,7 @@ namespace Barotrauma
|
||||
|
||||
public bool HasBody
|
||||
{
|
||||
get { return prefab.HasBody; }
|
||||
get { return prefab.Body; }
|
||||
}
|
||||
|
||||
public bool CastShadow
|
||||
@@ -129,7 +129,7 @@ namespace Barotrauma
|
||||
{
|
||||
get
|
||||
{
|
||||
return prefab.HasBody;
|
||||
return prefab.Body;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -156,7 +156,7 @@ namespace Barotrauma
|
||||
{
|
||||
Rectangle oldRect = Rect;
|
||||
base.Rect = value;
|
||||
if (prefab.HasBody) CreateSections();
|
||||
if (prefab.Body) CreateSections();
|
||||
else
|
||||
{
|
||||
foreach (WallSection sec in sections)
|
||||
@@ -227,7 +227,7 @@ namespace Barotrauma
|
||||
|
||||
SerializableProperties = SerializableProperty.GetProperties(this);
|
||||
|
||||
if (prefab.HasBody)
|
||||
if (prefab.Body)
|
||||
{
|
||||
bodies = new List<Body>();
|
||||
//gaps = new List<Gap>();
|
||||
@@ -241,7 +241,7 @@ namespace Barotrauma
|
||||
newBody.Friction = 0.5f;
|
||||
newBody.OnCollision += OnWallCollision;
|
||||
newBody.UserData = this;
|
||||
newBody.CollisionCategories = (prefab.IsPlatform) ? Physics.CollisionPlatform : Physics.CollisionWall;
|
||||
newBody.CollisionCategories = (prefab.Platform) ? Physics.CollisionPlatform : Physics.CollisionWall;
|
||||
|
||||
bodies.Add(newBody);
|
||||
|
||||
@@ -480,7 +480,7 @@ namespace Barotrauma
|
||||
|
||||
private bool OnWallCollision(Fixture f1, Fixture f2, Contact contact)
|
||||
{
|
||||
if (prefab.IsPlatform)
|
||||
if (prefab.Platform)
|
||||
{
|
||||
Limb limb;
|
||||
if ((limb = f2.Body.UserData as Limb) != null)
|
||||
@@ -495,7 +495,7 @@ namespace Barotrauma
|
||||
if (character.DisableImpactDamageTimer > 0.0f || ((Limb)f2.Body.UserData).Mass < 100.0f) return true;
|
||||
}
|
||||
|
||||
if (!prefab.IsPlatform && prefab.StairDirection == Direction.None)
|
||||
if (!prefab.Platform && prefab.StairDirection == Direction.None)
|
||||
{
|
||||
Vector2 pos = ConvertUnits.ToDisplayUnits(f2.Body.Position);
|
||||
|
||||
@@ -557,7 +557,7 @@ namespace Barotrauma
|
||||
|
||||
public void AddDamage(int sectionIndex, float damage)
|
||||
{
|
||||
if (!prefab.HasBody || prefab.IsPlatform) return;
|
||||
if (!prefab.Body || prefab.Platform) return;
|
||||
|
||||
if (sectionIndex < 0 || sectionIndex > sections.Length - 1) return;
|
||||
|
||||
@@ -625,7 +625,7 @@ namespace Barotrauma
|
||||
public AttackResult AddDamage(IDamageable attacker, Vector2 worldPosition, Attack attack, float deltaTime, bool playSound = false)
|
||||
{
|
||||
if (Submarine != null && Submarine.GodMode) return new AttackResult(0.0f, 0.0f);
|
||||
if (!prefab.HasBody || prefab.IsPlatform) return new AttackResult(0.0f, 0.0f);
|
||||
if (!prefab.Body || prefab.Platform) return new AttackResult(0.0f, 0.0f);
|
||||
|
||||
Vector2 transformedPos = worldPosition;
|
||||
if (Submarine != null) transformedPos -= Submarine.Position;
|
||||
@@ -653,7 +653,7 @@ namespace Barotrauma
|
||||
private void SetDamage(int sectionIndex, float damage)
|
||||
{
|
||||
if (Submarine != null && Submarine.GodMode) return;
|
||||
if (!prefab.HasBody) return;
|
||||
if (!prefab.Body) return;
|
||||
|
||||
if (!MathUtils.IsValid(damage)) return;
|
||||
|
||||
|
||||
@@ -8,13 +8,6 @@ namespace Barotrauma
|
||||
{
|
||||
partial class StructurePrefab : MapEntityPrefab
|
||||
{
|
||||
//does the structure have a physics body
|
||||
private bool hasBody;
|
||||
|
||||
private bool castShadow;
|
||||
|
||||
private bool isPlatform;
|
||||
private Direction stairDirection;
|
||||
private bool canSpriteFlipX;
|
||||
|
||||
private float maxHealth;
|
||||
@@ -22,29 +15,40 @@ namespace Barotrauma
|
||||
//default size
|
||||
private Vector2 size;
|
||||
|
||||
public bool HasBody
|
||||
//does the structure have a physics body
|
||||
[Serialize(false, false)]
|
||||
public bool Body
|
||||
{
|
||||
get { return hasBody; }
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public bool IsPlatform
|
||||
[Serialize(false, false)]
|
||||
public bool Platform
|
||||
{
|
||||
get { return isPlatform; }
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
[Serialize(100.0f, false)]
|
||||
public float MaxHealth
|
||||
{
|
||||
get { return maxHealth; }
|
||||
set { maxHealth = Math.Max(value, 0.0f); }
|
||||
}
|
||||
|
||||
[Serialize(false, false)]
|
||||
public bool CastShadow
|
||||
{
|
||||
get { return castShadow; }
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
[Serialize(Direction.None, false)]
|
||||
public Direction StairDirection
|
||||
{
|
||||
get { return stairDirection; }
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public bool CanSpriteFlipX
|
||||
@@ -52,9 +56,11 @@ namespace Barotrauma
|
||||
get { return canSpriteFlipX; }
|
||||
}
|
||||
|
||||
[Serialize("0,0", true)]
|
||||
public Vector2 Size
|
||||
{
|
||||
get { return size; }
|
||||
private set { size = value; }
|
||||
}
|
||||
|
||||
public Sprite BackgroundSprite
|
||||
@@ -115,41 +121,28 @@ namespace Barotrauma
|
||||
}
|
||||
|
||||
MapEntityCategory category;
|
||||
|
||||
if (!Enum.TryParse(element.GetAttributeString("category", "Structure"), true, out category))
|
||||
{
|
||||
category = MapEntityCategory.Structure;
|
||||
}
|
||||
|
||||
sp.Category = category;
|
||||
|
||||
sp.Description = element.GetAttributeString("description", "");
|
||||
|
||||
string aliases = element.GetAttributeString("aliases", "");
|
||||
if (!string.IsNullOrWhiteSpace(aliases))
|
||||
{
|
||||
sp.Aliases = aliases.Split(',');
|
||||
}
|
||||
|
||||
sp.size = Vector2.Zero;
|
||||
sp.size.X = element.GetAttributeFloat("width", 0.0f);
|
||||
sp.size.Y = element.GetAttributeFloat("height", 0.0f);
|
||||
|
||||
string spriteColorStr = element.GetAttributeString("spritecolor", "1.0,1.0,1.0,1.0");
|
||||
sp.SpriteColor = new Color(XMLExtensions.ParseVector4(spriteColorStr));
|
||||
SerializableProperty.DeserializeProperties(sp, element);
|
||||
|
||||
sp.maxHealth = element.GetAttributeFloat("health", 100.0f);
|
||||
//backwards compatibility
|
||||
if (element.Attribute("size") == null)
|
||||
{
|
||||
sp.size = Vector2.Zero;
|
||||
sp.size.X = element.GetAttributeFloat("width", 0.0f);
|
||||
sp.size.Y = element.GetAttributeFloat("height", 0.0f);
|
||||
}
|
||||
|
||||
sp.ResizeHorizontal = element.GetAttributeBool("resizehorizontal", false);
|
||||
sp.ResizeVertical = element.GetAttributeBool("resizevertical", false);
|
||||
|
||||
sp.isPlatform = element.GetAttributeBool("platform", false);
|
||||
sp.stairDirection = (Direction)Enum.Parse(typeof(Direction), element.GetAttributeString("stairdirection", "None"), true);
|
||||
|
||||
sp.castShadow = element.GetAttributeBool("castshadow", false);
|
||||
|
||||
sp.hasBody = element.GetAttributeBool("body", false);
|
||||
|
||||
return sp;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user