mirror of
https://github.com/roflmuffin/CounterStrikeSharp.git
synced 2025-12-05 23:58:24 -08:00
chore: extract ConVarCreationOptions
This commit is contained in:
@@ -66,7 +66,7 @@ public class ConVar<T> : ConVarBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ConVar(string name, string description, T defaultValue = default(T), ConVarFlags flags = ConVarFlags.FCVAR_NONE,
|
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,
|
Name = name,
|
||||||
DefaultValue = defaultValue,
|
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 type = typeof(T);
|
||||||
var conVarType = type switch
|
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}]";
|
return $"ConVar [name={Name}, value={Value}, description={Description}, type={Type}, flags={Flags}]";
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public sealed record ConVarCreationOptions
|
public sealed record ConVarCreationOptions<T>
|
||||||
{
|
{
|
||||||
public required string Name { get; init; }
|
public required string Name { get; init; }
|
||||||
public required T DefaultValue { get; init; }
|
public required T DefaultValue { get; init; }
|
||||||
public string Description { get; init; } = string.Empty;
|
public string Description { get; init; } = string.Empty;
|
||||||
public ConVarFlags Flags { get; init; } = ConVarFlags.FCVAR_NONE;
|
public ConVarFlags Flags { get; init; } = ConVarFlags.FCVAR_NONE;
|
||||||
public T? MinValue { get; init; }
|
public T? MinValue { get; init; }
|
||||||
public T? MaxValue { get; init; }
|
public T? MaxValue { get; init; }
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -112,7 +112,7 @@ public class ConVarTests
|
|||||||
{
|
{
|
||||||
ConVar<Vector>.Find("test_vector_convar")?.Delete();
|
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",
|
Name = "test_vector_convar",
|
||||||
DefaultValue = new Vector(1, 2, 3),
|
DefaultValue = new Vector(1, 2, 3),
|
||||||
@@ -172,7 +172,7 @@ public class ConVarTests
|
|||||||
{
|
{
|
||||||
ConVar<float>.Find("test_float_convar")?.Delete();
|
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",
|
Name = "test_float_convar",
|
||||||
DefaultValue = 1.23f,
|
DefaultValue = 1.23f,
|
||||||
@@ -209,7 +209,7 @@ public class ConVarTests
|
|||||||
{
|
{
|
||||||
ConVar<int>.Find("test_int_convar")?.Delete();
|
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",
|
Name = "test_int_convar",
|
||||||
DefaultValue = 42,
|
DefaultValue = 42,
|
||||||
|
|||||||
Reference in New Issue
Block a user