Client LuaCsForBarotrauma
LevelGenerationParametersFile.cs
1 using System;
2 using System.Xml.Linq;
3 
4 namespace Barotrauma
5 {
7  {
8  public LevelGenerationParametersFile(ContentPackage contentPackage, ContentPath path) : base(contentPackage, path) { }
9 
10  private void LoadBiomes(ContentXElement element, bool isOverride)
11  {
12  foreach (var subElement in element.Elements())
13  {
14  Biome biome = new Biome(subElement, this);
15  Biome.Prefabs.Add(biome, isOverride);
16  }
17  }
18 
19  private void LoadLevelGenerationParams(ContentXElement element, bool isOverride)
20  {
21  LevelGenerationParams lParams = new LevelGenerationParams(element, this);
22  LevelGenerationParams.LevelParams.Add(lParams, isOverride);
23  }
24 
25  private void LoadSubElements(ContentXElement element, bool overridePropagation)
26  {
27  foreach (var subElement in element.Elements())
28  {
29  if (subElement.IsOverride())
30  {
31  LoadSubElements(subElement, true);
32  }
33  else if (subElement.NameAsIdentifier() == "clear")
34  {
35  LevelGenerationParams.LevelParams.AddOverrideFile(this);
36  Biome.Prefabs.AddOverrideFile(this);
37  }
38  else if (subElement.NameAsIdentifier() == "biomes")
39  {
40  LoadBiomes(subElement, overridePropagation);
41  }
42  else
43  {
44  LoadLevelGenerationParams(subElement, overridePropagation);
45  }
46  }
47  }
48 
49  public override void LoadFile()
50  {
51  XDocument doc = XMLExtensions.TryLoadXml(Path);
52  if (doc is null) { return; }
53  LoadSubElements(doc.Root.FromPackage(ContentPackage), false);
54  }
55 
56  public override void UnloadFile()
57  {
58  LevelGenerationParams.LevelParams.RemoveByFile(this);
59  Biome.Prefabs.RemoveByFile(this);
60  }
61 
62  public override void Sort()
63  {
65  Biome.Prefabs.SortAll();
66  }
67  }
68 }
static readonly PrefabCollection< Biome > Prefabs
Definition: Biome.cs:10
Base class for content file types, which are loaded from filelist.xml via reflection....
Definition: ContentFile.cs:23
IEnumerable< ContentXElement > Elements()
LevelGenerationParametersFile(ContentPackage contentPackage, ContentPath path)
static readonly PrefabCollection< LevelGenerationParams > LevelParams