Merge remote-tracking branch 'upstream/master' into ed-16-02-2025-planet-light-upstream
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
using Content.Shared.Administration;
|
||||
using Content.Shared.CCVar.CVarAccess;
|
||||
using Robust.Shared;
|
||||
using Robust.Shared.Configuration;
|
||||
|
||||
@@ -14,6 +16,16 @@ public sealed partial class CCVars : CVars
|
||||
{
|
||||
// Only debug stuff lives here.
|
||||
|
||||
#if DEBUG
|
||||
[CVarControl(AdminFlags.Debug)]
|
||||
public static readonly CVarDef<string> DebugTestCVar =
|
||||
CVarDef.Create("debug.test_cvar", "default", CVar.SERVER);
|
||||
|
||||
[CVarControl(AdminFlags.Debug)]
|
||||
public static readonly CVarDef<float> DebugTestCVar2 =
|
||||
CVarDef.Create("debug.test_cvar2", 123.42069f, CVar.SERVER);
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// A simple toggle to test <c>OptionsVisualizerComponent</c>.
|
||||
/// </summary>
|
||||
|
||||
38
Content.Shared/CCVar/CVarAccess/CVarControl.cs
Normal file
38
Content.Shared/CCVar/CVarAccess/CVarControl.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using Content.Shared.Administration;
|
||||
using Robust.Shared.Reflection;
|
||||
|
||||
namespace Content.Shared.CCVar.CVarAccess;
|
||||
|
||||
/// <summary>
|
||||
/// Manages what admin flags can change the cvar value. With optional mins and maxes.
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
|
||||
[Reflect(discoverable: true)]
|
||||
public sealed class CVarControl : Attribute
|
||||
{
|
||||
public AdminFlags AdminFlags { get; }
|
||||
public object? Min { get; }
|
||||
public object? Max { get; }
|
||||
|
||||
public CVarControl(AdminFlags adminFlags, object? min = null, object? max = null, string? helpText = null)
|
||||
{
|
||||
AdminFlags = adminFlags;
|
||||
Min = min;
|
||||
Max = max;
|
||||
|
||||
// Not actually sure if its a good idea to throw exceptions in attributes.
|
||||
|
||||
if (min != null && max != null)
|
||||
{
|
||||
if (min.GetType() != max.GetType())
|
||||
{
|
||||
throw new ArgumentException("Min and max must be of the same type.");
|
||||
}
|
||||
}
|
||||
|
||||
if (min == null && max != null || min != null && max == null)
|
||||
{
|
||||
throw new ArgumentException("Min and max must both be null or both be set.");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user