2f107db...5202af9

This commit is contained in:
Joonas Rikkonen
2019-03-18 21:42:26 +02:00
parent 58c92888b7
commit 044fd3344b
395 changed files with 27417 additions and 19754 deletions
@@ -0,0 +1,25 @@
using System.Collections.Generic;
using System.Xml.Linq;
using System.Linq;
namespace Barotrauma
{
class ConditionalSprite : Sprite
{
public readonly List<PropertyConditional> conditionals = new List<PropertyConditional>();
public bool IsActive => Target != null && conditionals.All(c => c.Matches(Target));
readonly ISerializableEntity Target;
public ConditionalSprite(XElement element, ISerializableEntity target, string path = "", string file = "") : base(element, path, file)
{
Target = target;
foreach (XElement subElement in element.Elements())
{
foreach (XAttribute attribute in subElement.Attributes())
{
conditionals.Add(new PropertyConditional(attribute));
}
}
}
}
}
@@ -4,6 +4,7 @@ using System.Collections.Generic;
using System.Xml.Linq;
using System.Linq;
using Barotrauma.Extensions;
using System.IO;
namespace Barotrauma
{
@@ -16,10 +17,6 @@ namespace Barotrauma
private static HashSet<Sprite> list = new HashSet<Sprite>();
//the file from which the texture is loaded
//if two sprites use the same file, they share the same texture
private string file;
/// <summary>
/// Reference to the xml element from where the sprite was created. Can be null if the sprite was not defined in xml!
/// </summary>
@@ -81,11 +78,11 @@ namespace Barotrauma
origin = new Vector2(_relativeOrigin.X * sourceRect.Width, _relativeOrigin.Y * sourceRect.Height);
}
}
public string FilePath
{
get { return file; }
}
public string FilePath { get; private set; }
public string FullPath { get; private set; }
public override string ToString()
{
@@ -118,11 +115,16 @@ namespace Barotrauma
{
if (!path.EndsWith("/")) path += "/";
}
this.file = path + file;
FilePath = path + file;
if (!string.IsNullOrEmpty(FilePath))
{
FullPath = Path.GetFullPath(FilePath);
}
Name = SourceElement.GetAttributeString("name", null);
Vector4 sourceVector = SourceElement.GetAttributeVector4("sourcerect", Vector4.Zero);
bool shouldReturn = false;
LoadTexture(ref sourceVector, ref shouldReturn, SourceElement.GetAttributeBool("premultiplyalpha", false));
LoadTexture(ref sourceVector, ref shouldReturn, SourceElement.GetAttributeBool("premultiplyalpha", true));
if (shouldReturn) return;
sourceRect = new Rectangle((int)sourceVector.X, (int)sourceVector.Y, (int)sourceVector.Z, (int)sourceVector.W);
size = SourceElement.GetAttributeVector2("size", Vector2.One);
@@ -162,7 +164,11 @@ namespace Barotrauma
private void Init(string newFile, Rectangle? sourceRectangle = null, Vector2? newOrigin = null, Vector2? newOffset = null, float newRotation = 0,
bool preMultiplyAlpha = true)
{
file = newFile;
FilePath = newFile;
if (!string.IsNullOrEmpty(FilePath))
{
FullPath = Path.GetFullPath(FilePath);
}
Vector4 sourceVector = Vector4.Zero;
bool shouldReturn = false;
LoadTexture(ref sourceVector, ref shouldReturn, preMultiplyAlpha);