Skip to content

Commit b5ea382

Browse files
committed
feat(managed): Add try method to convar
1 parent 62fd546 commit b5ea382

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

managed/src/SwiftlyS2.Core/Modules/Convars/ConVar.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,4 +313,42 @@ public void SetDefaultValue(T defaultValue)
313313
}
314314
}
315315
}
316+
317+
public bool TryGetMinValue(out T minValue)
318+
{
319+
if (!IsMinMaxType) {
320+
minValue = default;
321+
return false;
322+
}
323+
if (!HasMinValue) {
324+
minValue = default;
325+
return false;
326+
}
327+
minValue = GetMinValue();
328+
return true;
329+
}
330+
331+
public bool TryGetMaxValue(out T maxValue)
332+
{
333+
if (!IsMinMaxType) {
334+
maxValue = default;
335+
return false;
336+
}
337+
if (!HasMaxValue) {
338+
maxValue = default;
339+
return false;
340+
}
341+
maxValue = GetMaxValue();
342+
return true;
343+
}
344+
345+
public bool TryGetDefaultValue(out T defaultValue)
346+
{
347+
if (!HasDefaultValue) {
348+
defaultValue = default;
349+
return false;
350+
}
351+
defaultValue = GetDefaultValue();
352+
return true;
353+
}
316354
}

managed/src/SwiftlyS2.Shared/Modules/Convars/IConVar.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,25 @@ public interface IConVar<T> {
6969
/// <param name="clientId"></param>
7070
/// <param name="callback">The action to execute with the value.</param>
7171
void QueryClient(int clientId, Action<string> callback);
72+
73+
/// <summary>
74+
/// Try to get the min value of the convar.
75+
/// </summary>
76+
/// <param name="minValue">The min value of the convar.</param>
77+
/// <returns>True if the min value is found, false otherwise.</returns>
78+
bool TryGetMinValue(out T minValue);
79+
80+
/// <summary>
81+
/// Try to get the max value of the convar.
82+
/// </summary>
83+
/// <param name="maxValue">The max value of the convar.</param>
84+
/// <returns>True if the max value is found, false otherwise.</returns>
85+
bool TryGetMaxValue(out T maxValue);
86+
87+
/// <summary>
88+
/// Try to get the default value of the convar.
89+
/// </summary>
90+
/// <param name="defaultValue">The default value of the convar.</param>
91+
/// <returns>True if the default value is found, false otherwise.</returns>
92+
bool TryGetDefaultValue(out T defaultValue);
7293
}

0 commit comments

Comments
 (0)