Client LuaCsForBarotrauma
JobsFile.cs
1 using Barotrauma;
2 using System;
3 using System.Linq;
4 using System.Xml.Linq;
5 
6 namespace Barotrauma
7 {
8 
10  sealed class JobsFile : ContentFile
11  {
12  public JobsFile(ContentPackage contentPackage, ContentPath path) : base(contentPackage, path) { }
13 
14  public override void LoadFile()
15  {
16  XDocument doc = XMLExtensions.TryLoadXml(Path);
17  if (doc == null) { return; }
18  LoadElements(doc.Root.FromPackage(ContentPackage), false);
19  }
20 
21  private void LoadElements(ContentXElement mainElement, bool isOverride)
22  {
23  foreach (var element in mainElement.Elements())
24  {
25  if (element.NameAsIdentifier() == "ItemRepairPriorities")
26  {
27  foreach (var subElement in element.Elements())
28  {
29  ItemRepairPriority prio = new ItemRepairPriority(subElement, this);
30  ItemRepairPriority.Prefabs.Add(prio, isOverride);
31  }
32  }
33  else if (element.IsOverride())
34  {
35  LoadElements(element, true);
36  }
37  else
38  {
39  var job = new JobPrefab(element, this);
40  JobPrefab.Prefabs.Add(job, isOverride);
41  }
42  }
43  }
44 
45  public override void UnloadFile()
46  {
47  JobPrefab.Prefabs.RemoveByFile(this);
48  ItemRepairPriority.Prefabs.RemoveByFile(this);
49  }
50 
51  public override void Sort()
52  {
53  JobPrefab.Prefabs.SortAll();
54  }
55  }
56 }
Base class for content file types, which are loaded from filelist.xml via reflection....
Definition: ContentFile.cs:23
IEnumerable< ContentXElement > Elements()
static readonly PrefabCollection< ItemRepairPriority > Prefabs
static readonly PrefabCollection< JobPrefab > Prefabs
override void Sort()
Definition: JobsFile.cs:51
override void UnloadFile()
Definition: JobsFile.cs:45
override void LoadFile()
Definition: JobsFile.cs:14
JobsFile(ContentPackage contentPackage, ContentPath path)
Definition: JobsFile.cs:12