Client LuaCsForBarotrauma
RunConfig.cs
1 using System;
2 using System.ComponentModel;
3 using System.Xml.Serialization;
4 
5 namespace Barotrauma;
6 
7 [Serializable]
8 public sealed class RunConfig
9 {
13  [XmlElement(ElementName = "Server")]
14  [DefaultValue("Standard")]
15  public string Server;
16 
20  [XmlElement(ElementName = "Client")]
21  [DefaultValue("Standard")]
22  public string Client;
23 
28  [XmlArrayItem(ElementName = "Dependency", IsNullable = true, Type = typeof(Dependency))]
29  [XmlArray]
30  public Dependency[] Dependencies { get; set; }
31 
35  [XmlElement(ElementName = "UseNonPublicizedAssemblies")]
36  public bool UseNonPublicizedAssemblies { get; set; }
37 
41  [XmlElement(ElementName = "UseInternalAssemblyName")]
42  [DefaultValue(false)]
43  public bool UseInternalAssemblyName { get; set; }
44 
45  [XmlElement(ElementName = "AutoGenerated")]
46  public bool AutoGenerated { get; set; }
47 
48  public RunConfig(bool autoGenerated)
49  {
50  this.AutoGenerated = autoGenerated;
51  if (autoGenerated)
52  {
53  (Client, Server) = ("Standard", "Standard");
55  }
56  }
57 
58  public RunConfig() { } // For serialization use
59 
60  [Serializable]
61  public sealed class Dependency
62  {
66  [XmlElement(ElementName = "SteamWorkshopId")]
67  public ulong SteamWorkshopId;
68 
72  [XmlElement(ElementName = "PackageName")]
73  public string PackageName;
74  }
75 
77  {
78  try
79  {
80  Client = SanitizeRunSetting(Client);
81  }
82  catch (Exception)
83  {
84  Client = "Standard";
85  }
86 
87  try
88  {
89  Server = SanitizeRunSetting(Server);
90  }
91  catch (Exception)
92  {
93  Server = "Standard";
94  }
95 
96  Dependencies ??= new RunConfig.Dependency[] { };
97 
98  static string SanitizeRunSetting(string str) =>
99  str switch
100  {
101  null => "Standard",
102  "" => "Standard",
103  " " => "Standard",
104  _ => str[0].ToString().ToUpper() + str.Substring(1).ToLower()
105  };
106 
107  return this;
108  }
109 
110  public bool IsForced()
111  {
112 #if CLIENT
113  return this.Client == "Forced";
114 #elif SERVER
115  return this.Server == "Forced";
116 #endif
117  }
118 
119  public bool IsStandard()
120  {
121 #if CLIENT
122  return this.Client == "Standard";
123 #elif SERVER
124  return this.Server == "Standard";
125 #endif
126  }
127 
128  public bool IsForcedOrStandard() => this.IsForced() || this.IsStandard();
129 
130 }
string PackageName
Package Name of the dependency. Not needed if SteamWorkshopId is set.
Definition: RunConfig.cs:73
ulong SteamWorkshopId
Steam Workshop ID of the dependency.
Definition: RunConfig.cs:67
string Server
How should scripts be run on the server.
Definition: RunConfig.cs:15
bool AutoGenerated
Definition: RunConfig.cs:46
Dependency[] Dependencies
List of dependencies by either Steam Workshop ID or by Partial Inclusive Name (ie....
Definition: RunConfig.cs:30
RunConfig Sanitize()
Definition: RunConfig.cs:76
RunConfig()
Definition: RunConfig.cs:58
bool IsStandard()
Definition: RunConfig.cs:119
string Client
How should scripts be run on the client.
Definition: RunConfig.cs:22
RunConfig(bool autoGenerated)
Definition: RunConfig.cs:48
bool UseNonPublicizedAssemblies
Compiles the mod using non-publicized assemblies.
Definition: RunConfig.cs:36
bool IsForced()
Definition: RunConfig.cs:110
bool UseInternalAssemblyName
If the mod includes source files, the compiled assembly will be named "CompiledAssembly" and have the...
Definition: RunConfig.cs:43
bool IsForcedOrStandard()