Client LuaCsForBarotrauma
RandomEventsFile.cs
1 using System.Xml.Linq;
2 
3 namespace Barotrauma
4 {
5  [RequiredByCorePackage]
7  {
8  public RandomEventsFile(ContentPackage contentPackage, ContentPath path) : base(contentPackage, path) { }
9 
10  public void LoadFromXElement(ContentXElement parentElement, bool overriding)
11  {
12  Identifier elemName = new Identifier(parentElement.Name.ToString());
13  if (parentElement.IsOverride())
14  {
15  foreach (var element in parentElement.Elements())
16  {
17  LoadFromXElement(element, true);
18  }
19  }
20  else if (elemName == "randomevents")
21  {
22  foreach (var element in parentElement.Elements())
23  {
24  LoadFromXElement(element, overriding);
25  }
26  }
27  else if (elemName == "eventprefabs")
28  {
29  foreach (var subElement in parentElement.Elements())
30  {
31  if (subElement.NameAsIdentifier() == "traitorevent")
32  {
33  var prefab = new TraitorEventPrefab(subElement, this);
34  EventPrefab.Prefabs.Add(prefab, overriding);
35  }
36  else
37  {
38  var prefab = new EventPrefab(subElement, this);
39  EventPrefab.Prefabs.Add(prefab, overriding);
40  }
41  }
42  }
43  else if (elemName == "eventsprites")
44  {
45 #if CLIENT
46  foreach (var subElement in parentElement.Elements())
47  {
48  var prefab = new EventSprite(subElement, this);
49  EventSprite.Prefabs.Add(prefab, overriding);
50  }
51 #endif
52  }
53  else if (elemName == "eventset")
54  {
55  var prefab = new EventSet(parentElement, this);
56  EventSet.Prefabs.Add(prefab, overriding);
57  }
58  else if (elemName == "clear")
59  {
60  EventPrefab.Prefabs.AddOverrideFile(this);
61  EventSet.Prefabs.AddOverrideFile(this);
62 #if CLIENT
63  EventSprite.Prefabs.AddOverrideFile(this);
64 #endif
65  }
66  else
67  {
68  DebugConsole.ThrowError($"RandomEventsFile: Invalid {GetType().Name} element: {parentElement.Name} in {Path}",
69  contentPackage: parentElement.ContentPackage);
70  }
71  }
72 
73  public override void LoadFile()
74  {
75  XDocument doc = XMLExtensions.TryLoadXml(Path);
76  if (doc == null) { return; }
77 
78  var rootElement = doc.Root.FromPackage(ContentPackage);
79  LoadFromXElement(rootElement, false);
80  }
81 
82  public override void UnloadFile()
83  {
84  EventPrefab.Prefabs.RemoveByFile(this);
85  EventSet.Prefabs.RemoveByFile(this);
86 #if CLIENT
87  EventSprite.Prefabs.RemoveByFile(this);
88 #endif
89  }
90 
91  public override void Sort()
92  {
93  EventPrefab.Prefabs.SortAll();
94  EventSet.Prefabs.SortAll();
95 #if CLIENT
96  EventSprite.Prefabs.SortAll();
97 #endif
98  }
99  }
100 }
Base class for content file types, which are loaded from filelist.xml via reflection....
Definition: ContentFile.cs:23
ContentPackage? ContentPackage
IEnumerable< ContentXElement > Elements()
static readonly PrefabCollection< EventPrefab > Prefabs
Definition: EventPrefab.cs:11
Event sets are sets of random events that occur within a level (most commonly, monster spawns and scr...
Definition: EventSet.cs:31
static readonly PrefabCollection< EventSet > Prefabs
Definition: EventSet.cs:44
static readonly PrefabCollection< EventSprite > Prefabs
Definition: EventSet.cs:13
void LoadFromXElement(ContentXElement parentElement, bool overriding)
RandomEventsFile(ContentPackage contentPackage, ContentPath path)