Skip to content

Commit

Permalink
Add ability to clear a variable
Browse files Browse the repository at this point in the history
  • Loading branch information
Somfic committed May 29, 2024
1 parent dd3a70f commit cc4b84a
Showing 1 changed file with 101 additions and 0 deletions.
101 changes: 101 additions & 0 deletions src-plugin/EliteVA/Proxy/Variables/VoiceAttackVariables.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ internal VoiceAttackVariables(dynamic vaProxy)

public void ClearStartingWith(string name)
{
// TODO: Clear all variables
// foreach (var variable in variablesToClear)
// {
// Clear(variable.category, variable.name, variable.value);
// }

_setVariables = _setVariables.Where(x => !x.name.Split(':')[1].StartsWith(name)).ToList();
}

Expand Down Expand Up @@ -171,6 +177,45 @@ public void Set(string category, string name, object value, JTokenType code)
return value;
}

public void Clear(string category, string name, TypeCode code)
{
switch (code)
{
case TypeCode.Boolean:
ClearBoolean(category, name);
break;

case TypeCode.DateTime:
ClearDate(category, name);
break;

case TypeCode.Single:
case TypeCode.Decimal:
case TypeCode.Double:
ClearDecimal(category, name);
break;

case TypeCode.Char:
case TypeCode.String:
ClearText(category, name);
break;

case TypeCode.Byte:
case TypeCode.Int16:
case TypeCode.UInt16:
case TypeCode.SByte:
ClearShort(category, name);
break;

case TypeCode.Int32:
case TypeCode.UInt32:
case TypeCode.Int64:
case TypeCode.UInt64:
ClearInt(category, name);
break;
}
}

private short? GetShort(string name)
{
return _proxy.GetSmallInt(name);
Expand Down Expand Up @@ -208,6 +253,14 @@ private void SetShort(string category, string name, short? value)

_proxy.SetSmallInt(name, value);
}

private void ClearShort(string category, string name)
{
var variable = $"{{SHORT:{name}}}";
ClearVariable(category, variable);

_proxy.SetSmallInt(name, null);
}

private void SetInt(string category, string name, int? value)
{
Expand All @@ -216,6 +269,14 @@ private void SetInt(string category, string name, int? value)

_proxy.SetInt(name, value);
}

private void ClearInt(string category, string name)
{
var variable = $"{{INT:{name}}}";
ClearVariable(category, variable);

_proxy.SetInt(name, null);
}

private void SetText(string category, string name, string value)
{
Expand All @@ -224,6 +285,14 @@ private void SetText(string category, string name, string value)

_proxy.SetText(name, value);
}

private void ClearText(string category, string name)
{
var variable = $"{{TXT:{name}}}";
ClearVariable(category, variable);

_proxy.SetText(name, null);
}

private void SetDecimal(string category, string name, decimal? value)
{
Expand All @@ -232,6 +301,14 @@ private void SetDecimal(string category, string name, decimal? value)

_proxy.SetDecimal(name, value);
}

private void ClearDecimal(string category, string name)
{
var variable = $"{{DEC:{name}}}";
ClearVariable(category, variable);

_proxy.SetDecimal(name, null);
}

private void SetBoolean(string category, string name, bool? value)
{
Expand All @@ -240,6 +317,14 @@ private void SetBoolean(string category, string name, bool? value)

_proxy.SetBoolean(name, value);
}

private void ClearBoolean(string category, string name)
{
var variable = $"{{BOOL:{name}}}";
ClearVariable(category, variable);

_proxy.SetBoolean(name, null);
}

private void SetDate(string category, string name, DateTime? value)
{
Expand All @@ -248,15 +333,31 @@ private void SetDate(string category, string name, DateTime? value)

_proxy.SetDate(name, value);
}

private void ClearDate(string category, string name)
{
var variable = $"{{DATE:{name}}}";
ClearVariable(category, variable);

_proxy.SetDate(name, null);
}

private void SetVariable(string category, string name, string value)
{
var index = _setVariables.FindIndex(x => x.name == name);

if (index >= 0)
_setVariables[index] = (category, name, value);
else
_setVariables.Insert(0, (category, name, value));

OnVariablesSet?.Invoke(this, EventArgs.Empty);
}

private void ClearVariable(string category, string name)
{
_setVariables.RemoveAll(x => x.name == name);

OnVariablesSet?.Invoke(this, EventArgs.Empty);
}
}

0 comments on commit cc4b84a

Please sign in to comment.