Files
LuaCsForBarotraumaEP/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Plugins/RunConfig.cs
T
MapleWheels e984633ca5 - Fixed NRE in TryBeginDispose
- Made `OnException` event useful.
- Added some null checks where expected.
- Fixed overridden Unload not being called.
- Removed partial from AssemblyManager.cs
- Made ClearTypesList() actually work.
- Made exception details show in console on release builds.
- Made content package name show on plugin load.
- Made execution standard instead of none for autogenerated and erroneous RunConfigs.
2023-10-22 20:54:28 -03:00

112 lines
2.7 KiB
C#

using System;
using System.Xml.Serialization;
namespace Barotrauma;
[Serializable]
public sealed class RunConfig
{
/// <summary>
/// How should scripts be run on the server.
/// </summary>
[XmlElement(ElementName = "Server")] public string Server;
/// <summary>
/// How should scripts be run on the client.
/// </summary>
[XmlElement(ElementName = "Client")] public string Client;
/// <summary>
/// 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.
/// </summary>
[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) = ("Standard", "Standard");
}
}
public RunConfig() { } // For serialization use
[Serializable]
public sealed class Dependency
{
/// <summary>
/// Steam Workshop ID of the dependency.
/// </summary>
[XmlElement(ElementName = "SteamWorkshopId")]
public ulong SteamWorkshopId;
/// <summary>
/// Package Name of the dependency. Not needed if SteamWorkshopId is set.
/// </summary>
[XmlElement(ElementName = "PackageName")]
public string PackageName;
}
public RunConfig Sanitize()
{
try
{
Client = SanitizeRunSetting(Client);
}
catch (Exception)
{
Client = "Standard";
}
try
{
Server = SanitizeRunSetting(Server);
}
catch (Exception)
{
Server = "Standard";
}
Dependencies ??= new RunConfig.Dependency[] { };
static string SanitizeRunSetting(string str) =>
str switch
{
null => "Standard",
"" => "Standard",
" " => "Standard",
_ => str[0].ToString().ToUpper() + str.Substring(1).ToLower()
};
return this;
}
public bool IsForced()
{
#if CLIENT
return this.Client == "Forced";
#elif SERVER
return this.Server == "Forced";
#endif
}
public bool IsStandard()
{
#if CLIENT
return this.Client == "Standard";
#elif SERVER
return this.Server == "Standard";
#endif
}
public bool IsForcedOrStandard() => this.IsForced() || this.IsStandard();
}