Client LuaCsForBarotrauma
BarotraumaShared/SharedSource/Sprite/ConditionalSprite.cs
1 using System.Collections.Generic;
2 using System.Linq;
3 
4 namespace Barotrauma
5 {
6  partial class ConditionalSprite
7  {
8  public readonly List<PropertyConditional> conditionals = new List<PropertyConditional>();
9  public bool IsActive { get; private set; } = true;
10 
12  public readonly bool Exclusive;
13  public ISerializableEntity Target { get; private set; }
14  public Sprite Sprite { get; private set; }
15  public DeformableSprite DeformableSprite { get; private set; }
17 
18  public ConditionalSprite(ContentXElement element, ISerializableEntity target, string file = "", bool lazyLoad = false, float sourceRectScale = 1)
19  {
20  Target = target;
21  Exclusive = element.GetAttributeBool("exclusive", Exclusive);
22  LogicalOperator = element.GetAttributeEnum("comparison", LogicalOperator);
23  foreach (var subElement in element.Elements())
24  {
25  switch (subElement.Name.ToString().ToLowerInvariant())
26  {
27  case "conditional":
28  conditionals.AddRange(PropertyConditional.FromXElement(subElement));
29  break;
30  case "sprite":
31  Sprite = new Sprite(subElement, file: file, lazyLoad: lazyLoad, sourceRectScale: sourceRectScale);
32  break;
33  case "deformablesprite":
34  DeformableSprite = new DeformableSprite(subElement, filePath: file, lazyLoad: lazyLoad, sourceRectScale: sourceRectScale);
35  break;
36  }
37  }
38  }
39 
40  public void CheckConditionals()
41  {
42  if (Target == null)
43  {
44  IsActive = false;
45  }
46  else
47  {
48  IsActive = LogicalOperator == PropertyConditional.LogicalOperatorType.And ? conditionals.All(c => c.Matches(Target)) : conditionals.Any(c => c.Matches(Target));
49  }
50  }
51  }
52 }
readonly PropertyConditional.LogicalOperatorType LogicalOperator
ConditionalSprite(ContentXElement element, ISerializableEntity target, string file="", bool lazyLoad=false, float sourceRectScale=1)
bool GetAttributeBool(string key, bool def)
Conditionals are used by some in-game mechanics to require one or more conditions to be met for those...
static IEnumerable< PropertyConditional > FromXElement(ContentXElement element, Predicate< XAttribute >? predicate=null)