Client LuaCsForBarotrauma
OrdersFile.cs
1 using System.Xml.Linq;
2 
3 namespace Barotrauma
4 {
5  #warning TODO: this is almost a GenericPrefabFile. Must refactor further.
6  [RequiredByCorePackage]
7  sealed class OrdersFile : ContentFile
8  {
9  public OrdersFile(ContentPackage contentPackage, ContentPath path) : base(contentPackage, path) { }
10 
11  public void LoadFromXElement(ContentXElement parentElement, bool overriding)
12  {
13  Identifier elemName = new Identifier(parentElement.Name.ToString());
14  if (parentElement.IsOverride())
15  {
16  foreach (var element in parentElement.Elements())
17  {
18  LoadFromXElement(element, true);
19  }
20  }
21  else if (elemName == "order")
22  {
23  OrderPrefab prefab = new OrderPrefab(parentElement, this);
24  OrderPrefab.Prefabs.Add(prefab, overriding);
25  }
26  else if (elemName == "ordercategory")
27  {
28  OrderCategoryIcon prefab = new OrderCategoryIcon(parentElement, this);
29  OrderCategoryIcon.OrderCategoryIcons.Add(prefab, overriding);
30  }
31  else if (elemName == "orders")
32  {
33  foreach (var element in parentElement.Elements())
34  {
35  LoadFromXElement(element, overriding);
36  }
37  }
38  else if (elemName == "clear")
39  {
40  OrderCategoryIcon.OrderCategoryIcons.AddOverrideFile(this);
41  OrderPrefab.Prefabs.AddOverrideFile(this);
42  }
43  else
44  {
45  DebugConsole.ThrowError($"OrdersFile: Invalid {GetType().Name} element: {parentElement.Name} in {Path}",
46  contentPackage: parentElement?.ContentPackage);
47  }
48  }
49 
50  public override sealed void LoadFile()
51  {
52  XDocument doc = XMLExtensions.TryLoadXml(Path);
53  if (doc == null) { return; }
54 
55  var rootElement = doc.Root.FromPackage(ContentPackage);
56  LoadFromXElement(rootElement, false);
57  }
58 
59  public override sealed void UnloadFile()
60  {
61  OrderCategoryIcon.OrderCategoryIcons.RemoveByFile(this);
62  OrderPrefab.Prefabs.RemoveByFile(this);
63  }
64 
65  public override sealed void Sort()
66  {
68  OrderPrefab.Prefabs.SortAll();
69  }
70  }
71 }
Base class for content file types, which are loaded from filelist.xml via reflection....
Definition: ContentFile.cs:23
IEnumerable< ContentXElement > Elements()
static readonly PrefabCollection< OrderCategoryIcon > OrderCategoryIcons
Definition: Order.cs:22
static readonly PrefabCollection< OrderPrefab > Prefabs
Definition: Order.cs:41
void LoadFromXElement(ContentXElement parentElement, bool overriding)
Definition: OrdersFile.cs:11
OrdersFile(ContentPackage contentPackage, ContentPath path)
Definition: OrdersFile.cs:9
override sealed void UnloadFile()
Definition: OrdersFile.cs:59
override sealed void Sort()
Definition: OrdersFile.cs:65
override sealed void LoadFile()
Definition: OrdersFile.cs:50