chore: extract ConVarCreationOptions

This commit is contained in:
roflmuffin
2025-07-20 11:45:19 +00:00
parent a84f4244cd
commit 149787d139
2 changed files with 14 additions and 14 deletions

View File

@@ -66,7 +66,7 @@ public class ConVar<T> : ConVarBase
}
public ConVar(string name, string description, T defaultValue = default(T), ConVarFlags flags = ConVarFlags.FCVAR_NONE,
T? minValue = default, T? maxValue = default) : this(new ConVarCreationOptions
T? minValue = default, T? maxValue = default) : this(new ConVarCreationOptions<T>
{
Name = name,
DefaultValue = defaultValue,
@@ -78,7 +78,7 @@ public class ConVar<T> : ConVarBase
{
}
public ConVar(ConVarCreationOptions options)
public ConVar(ConVarCreationOptions<T> options)
{
var type = typeof(T);
var conVarType = type switch
@@ -210,14 +210,14 @@ public class ConVar<T> : ConVarBase
{
return $"ConVar [name={Name}, value={Value}, description={Description}, type={Type}, flags={Flags}]";
}
}
public sealed record ConVarCreationOptions
{
public required string Name { get; init; }
public required T DefaultValue { get; init; }
public string Description { get; init; } = string.Empty;
public ConVarFlags Flags { get; init; } = ConVarFlags.FCVAR_NONE;
public T? MinValue { get; init; }
public T? MaxValue { get; init; }
}
public sealed record ConVarCreationOptions<T>
{
public required string Name { get; init; }
public required T DefaultValue { get; init; }
public string Description { get; init; } = string.Empty;
public ConVarFlags Flags { get; init; } = ConVarFlags.FCVAR_NONE;
public T? MinValue { get; init; }
public T? MaxValue { get; init; }
}

View File

@@ -112,7 +112,7 @@ public class ConVarTests
{
ConVar<Vector>.Find("test_vector_convar")?.Delete();
var conVar = new ConVar<Vector>(new ConVar<Vector>.ConVarCreationOptions()
var conVar = new ConVar<Vector>(new ConVarCreationOptions<Vector>()
{
Name = "test_vector_convar",
DefaultValue = new Vector(1, 2, 3),
@@ -172,7 +172,7 @@ public class ConVarTests
{
ConVar<float>.Find("test_float_convar")?.Delete();
var conVar = new ConVar<float>(new ConVar<float>.ConVarCreationOptions()
var conVar = new ConVar<float>(new ConVarCreationOptions<float>()
{
Name = "test_float_convar",
DefaultValue = 1.23f,
@@ -209,7 +209,7 @@ public class ConVarTests
{
ConVar<int>.Find("test_int_convar")?.Delete();
var conVar = new ConVar<int>(new ConVar<int>.ConVarCreationOptions()
var conVar = new ConVar<int>(new ConVarCreationOptions<int>()
{
Name = "test_int_convar",
DefaultValue = 42,