using System; using System.Xml.Serialization; namespace Barotrauma; [Serializable] public sealed class RunConfig { /// /// How should scripts be run on the server. /// [XmlElement(ElementName = "Server")] public string Server; /// /// How should scripts be run on the client. /// [XmlElement(ElementName = "Client")] public string Client; /// /// List of dependencies by either Steam Workshop ID or by Partial Inclusive Name (ie. "ModDep" will match a mod named "A ModDependency"). /// PIN Dependency checks if ContentPackage names contains the dependency string. /// [XmlArrayItem(ElementName = "Dependency", IsNullable = true, Type = typeof(Dependency))] [XmlArray] public Dependency[] Dependencies { get; set; } [XmlElement(ElementName = "AutoGenerated")] public bool AutoGenerated { get; set; } public RunConfig(bool autoGenerated) { this.AutoGenerated = autoGenerated; if (autoGenerated) { (Client, Server) = ("None", "None"); } } public RunConfig() { } // For serialization use [Serializable] public sealed class Dependency { /// /// Steam Workshop ID of the dependency. /// [XmlElement(ElementName = "SteamWorkshopId")] public ulong SteamWorkshopId; /// /// Package Name of the dependency. Not needed if SteamWorkshopId is set. /// [XmlElement(ElementName = "PackageName")] public string PackageName; } public RunConfig Sanitize() { try { Client = SanitizeRunSetting(Client); } catch (Exception e) { Client = "None"; } try { Server = SanitizeRunSetting(Server); } catch (Exception e) { Server = "None"; } Dependencies ??= new RunConfig.Dependency[] { }; static string SanitizeRunSetting(string str) => str switch { null => "None", "" => "None", " " => "None", _ => str[0].ToString().ToUpper() + str.Substring(1).ToLower() }; return this; } public bool IsForced() { #if CLIENT return this.Client.Equals("Forced"); #elif SERVER return this.Server.Equals("Forced"); #endif } public bool IsStandard() { #if CLIENT return this.Client.Equals("Standard"); #elif SERVER return this.Server.Equals("Standard"); #endif } public bool IsForcedOrStandard() => this.IsForced() || this.IsStandard(); }