Client LuaCsForBarotrauma
RuinGenerationParams.cs
1 using Microsoft.Xna.Framework;
2 using System;
3 using System.Collections.Generic;
4 using System.Linq;
5 using System.Xml.Linq;
6 using System.Collections.Immutable;
8 #if DEBUG
9 using System.Xml;
10 #else
11 using Barotrauma.IO;
12 #endif
13 
14 
16 {
17  [Flags]
18  enum RuinEntityType
19  {
20  Wall, Back, Door, Hatch, Prop
21  }
22 
24  {
27 
28  public override string Name => "RuinGenerationParams";
29 
30  [Serialize(true, IsPropertySaveable.Yes, description: "Are these params designed to be used for alien ruins targeted by missions. If false, the params are ignored when there's any missions targeting ruins."), Editable]
31  public bool IsMissionReady { get; set; }
32 
33  public RuinGenerationParams(ContentXElement element, RuinConfigFile file) : base(element, file) { }
34 
35  public static void SaveAll()
36  {
37  #warning TODO: revise
38  System.Xml.XmlWriterSettings settings = new System.Xml.XmlWriterSettings
39  {
40  Indent = true,
41  NewLineOnAttributes = true
42  };
43 
44  IEnumerable<ContentPackage> packages = ContentPackageManager.LocalPackages;
45 #if DEBUG
46  packages = packages.Union(ContentPackageManager.VanillaCorePackage.ToEnumerable());
47 #endif
48  foreach (RuinGenerationParams generationParams in RuinParams)
49  {
50  foreach (RuinConfigFile configFile in packages.SelectMany(p => p.GetFiles<RuinConfigFile>()))
51  {
52  if (configFile.Path != generationParams.ContentFile.Path) { continue; }
53 
54  XDocument doc = XMLExtensions.TryLoadXml(configFile.Path);
55  if (doc == null) { continue; }
56 
57  SerializableProperty.SerializeProperties(generationParams, doc.Root);
58 
59  using (var writer = XmlWriter.Create(configFile.Path.Value, settings))
60  {
61  doc.WriteTo(writer);
62  writer.Flush();
63  }
64  }
65  }
66  }
67 
68  public override void Dispose() { }
69  }
70 }
readonly ContentPath Path
Definition: ContentFile.cs:137
static XmlWriter Create(string path, System.Xml.XmlWriterSettings settings)
Definition: SafeIO.cs:164
readonly ContentFile ContentFile
Definition: Prefab.cs:35
static readonly PrefabCollection< RuinGenerationParams > RuinParams
RuinGenerationParams(ContentXElement element, RuinConfigFile file)
static void SerializeProperties(ISerializableEntity obj, XElement element, bool saveIfDefault=false, bool ignoreEditable=false)