Config presets system. (#12824)

This commit is contained in:
Pieter-Jan Briers
2022-12-16 23:26:24 +01:00
committed by GitHub
parent 326fdefe85
commit 55c61b9c35
8 changed files with 105 additions and 17 deletions

View File

@@ -60,9 +60,6 @@ public sealed partial class CargoSystem
private void InitializeShuttle()
{
#if !FULL_RELEASE
_configManager.OverrideDefault(CCVars.CargoShuttles, false);
#endif
_enabled = _configManager.GetCVar(CCVars.CargoShuttles);
// Don't want to immediately call this as shuttles will get setup in the natural course of things.
_configManager.OnValueChanged(CCVars.CargoShuttles, SetCargoShuttleEnabled);

View File

@@ -37,6 +37,9 @@ namespace Content.Server.Entry
{
public sealed class EntryPoint : GameServer
{
private const string ConfigPresetsDir = "/ConfigPresets/";
private const string ConfigPresetsDirBuild = $"{ConfigPresetsDir}Build/";
private EuiManager _euiManager = default!;
private IVoteManager _voteManager = default!;
private ServerUpdateManager _updateManager = default!;
@@ -48,6 +51,12 @@ namespace Content.Server.Entry
{
base.Init();
var cfg = IoCManager.Resolve<IConfigurationManager>();
var res = IoCManager.Resolve<IResourceManager>();
var logManager = IoCManager.Resolve<ILogManager>();
LoadConfigPresets(cfg, res, logManager.GetSawmill("configpreset"));
var aczProvider = new ContentMagicAczProvider(IoCManager.Resolve<IDependencyCollection>());
IoCManager.Resolve<IStatusHost>().SetMagicAczProvider(aczProvider);
@@ -85,7 +94,6 @@ namespace Content.Server.Entry
_playTimeTracking = IoCManager.Resolve<PlayTimeTrackingManager>();
_sysMan = IoCManager.Resolve<IEntitySystemManager>();
var logManager = IoCManager.Resolve<ILogManager>();
logManager.GetSawmill("Storage").Level = LogLevel.Info;
logManager.GetSawmill("db.ef").Level = LogLevel.Info;
@@ -165,5 +173,47 @@ namespace Content.Server.Entry
_playTimeTracking?.Shutdown();
_sysMan?.GetEntitySystemOrNull<StationSystem>()?.OnServerDispose();
}
private static void LoadConfigPresets(IConfigurationManager cfg, IResourceManager res, ISawmill sawmill)
{
LoadBuildConfigPresets(cfg, res, sawmill);
var presets = cfg.GetCVar(CCVars.ConfigPresets);
if (presets == "")
return;
foreach (var preset in presets.Split(','))
{
var path = $"{ConfigPresetsDir}{preset}.toml";
if (!res.TryContentFileRead(path, out var file))
{
sawmill.Error("Unable to load config preset {Preset}!", path);
continue;
}
cfg.LoadDefaultsFromTomlStream(file);
sawmill.Info("Loaded config preset: {Preset}", path);
}
}
private static void LoadBuildConfigPresets(IConfigurationManager cfg, IResourceManager res, ISawmill sawmill)
{
#if !FULL_RELEASE
Load(CCVars.ConfigPresetDevelopment, "development");
#endif
#if DEBUG
Load(CCVars.ConfigPresetDebug, "debug");
#endif
void Load(CVarDef<bool> cVar, string name)
{
var path = $"{ConfigPresetsDirBuild}{name}.toml";
if (cfg.GetCVar(cVar) && res.TryContentFileRead(path, out var file))
{
cfg.LoadDefaultsFromTomlStream(file);
sawmill.Info("Loaded config preset: {Preset}", path);
}
}
}
}
}

View File

@@ -34,10 +34,6 @@ namespace Content.Server.NPC.Systems
public override void Initialize()
{
base.Initialize();
// Makes physics etc debugging easier.
#if DEBUG
_configurationManager.OverrideDefault(CCVars.NPCEnabled, false);
#endif
_sawmill = Logger.GetSawmill("npc");
_sawmill.Level = LogLevel.Info;

View File

@@ -55,9 +55,6 @@ public sealed partial class ShuttleSystem
private void InitializeEscape()
{
#if !FULL_RELEASE
_configManager.OverrideDefault(CCVars.EmergencyShuttleEnabled, false);
#endif
_emergencyShuttleEnabled = _configManager.GetCVar(CCVars.EmergencyShuttleEnabled);
// Don't immediately invoke as roundstart will just handle it.
_configManager.OnValueChanged(CCVars.EmergencyShuttleEnabled, SetEmergencyShuttleEnabled);

View File

@@ -30,10 +30,6 @@ public sealed class EventManagerSystem : EntitySystem
_sawmill = Logger.GetSawmill("events");
#if DEBUG
_configurationManager.OverrideDefault(CCVars.EventsEnabled, false);
#endif
_configurationManager.OnValueChanged(CCVars.EventsEnabled, SetEnabled, true);
}

View File

@@ -140,7 +140,7 @@ namespace Content.Shared.CCVar
/// Controls if the lobby is enabled. If it is not, and there are no available jobs, you may get stuck on a black screen.
/// </summary>
public static readonly CVarDef<bool>
GameLobbyEnabled = CVarDef.Create("game.lobbyenabled", false, CVar.ARCHIVE);
GameLobbyEnabled = CVarDef.Create("game.lobbyenabled", true, CVar.ARCHIVE);
/// <summary>
/// Controls the duration of the lobby timer in seconds. Defaults to 2 minutes and 30 seconds.
@@ -1339,7 +1339,6 @@ namespace Content.Shared.CCVar
* PLAYTIME
*/
/// <summary>
/// Time between play time autosaves, in seconds.
/// </summary>
@@ -1391,5 +1390,38 @@ namespace Content.Shared.CCVar
/// </summary>
public static readonly CVarDef<string> InfoLinksBugReport =
CVarDef.Create("infolinks.bug_report", "", CVar.SERVER | CVar.REPLICATED);
/*
* CONFIG
*/
// These are server-only for now since I don't foresee a client use yet,
// and I don't wanna have to start coming up with like .client suffixes and stuff like that.
/// <summary>
/// Configuration presets to load during startup.
/// Multiple presets can be separated by comma and are loaded in order.
/// </summary>
/// <remarks>
/// Loaded presets must be located under the <c>ConfigPresets/</c> resource directory and end with the <c>.toml</c> extension.
/// Only the file name (without extension) must be given for this variable.
/// </remarks>
public static readonly CVarDef<string> ConfigPresets =
CVarDef.Create("config.presets", "", CVar.SERVERONLY);
/// <summary>
/// Whether to load the preset development CVars.
/// This disables some things like lobby to make development easier.
/// Even when true, these are only loaded if the game is compiled with <c>DEVELOPMENT</c> set.
/// </summary>
public static readonly CVarDef<bool> ConfigPresetDevelopment =
CVarDef.Create("config.preset_development", true, CVar.SERVERONLY);
/// <summary>
/// Whether to load the preset debug CVars.
/// Even when true, these are only loaded if the game is compiled with <c>DEBUG</c> set.
/// </summary>
public static readonly CVarDef<bool> ConfigPresetDebug =
CVarDef.Create("config.preset_debug", true, CVar.SERVERONLY);
}
}

View File

@@ -0,0 +1,7 @@
[events]
# Annoying
enabled = false
[npc]
# Makes physics etc debugging easier.
enabled = false

View File

@@ -0,0 +1,13 @@
[game]
# Straight in-game baby
lobbyenabled = false
[physics]
# Makes mapping annoying
grid_splitting = false
[shuttle]
# Wastes startup time
cargo = false
emergency_enabled = false