Skip to content

Commit cdba73a

Browse files
fixed EnumArgument.cs error, other smaller changes
1 parent 93a1e61 commit cdba73a

File tree

15 files changed

+38
-23
lines changed

15 files changed

+38
-23
lines changed

ArgumentSystem/Arguments/EnumArgument.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,18 @@ public static TryGet<T> Convert<T>(BaseToken token, Script script) where T : str
3333
{
3434
if (Convert(token, script, typeof(T)).HasErrored(out var error, out var value))
3535
{
36-
return (T)value;
36+
return error;
3737
}
3838

39-
return error;
39+
return (T)value;
4040
}
4141

4242
public static TryGet<object> Convert(BaseToken token, Script script, Type enumType)
4343
{
4444
var stringRep = token.GetBestTextRepresentation(script);
45-
if (!Enum.IsDefined(enumType, stringRep))
45+
if (Enum.TryParse(stringRep, true, out TEnum result))
4646
{
47-
return Enum.Parse(enumType, stringRep);
47+
return result;
4848
}
4949

5050
return $"Value '{token.RawRepresentation}' does not represent a valid {enumType.GetAccurateName()} " +

ArgumentSystem/Arguments/FloatArgument.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,22 @@ public override string InputDescription
3232
{
3333
if (_minValue.HasValue && _maxValue.HasValue)
3434
{
35-
return $"Value must be at least {_minValue} and most {_maxValue} e.g. " +
35+
return $"A number which is at least {_minValue} and most {_maxValue} e.g. " +
3636
$"{Math.Round(Random.Range(_minValue.Value, _maxValue.Value), 2)}";
3737
}
3838

3939
if (_minValue.HasValue)
4040
{
41-
return $"Value must be at least {_minValue} e.g. {_minValue + 2f}";
41+
return $"A number which is at least {_minValue} e.g. {_minValue + 2f}";
4242
}
4343

4444
// ReSharper disable once ConvertIfStatementToReturnStatement
4545
if (_maxValue.HasValue)
4646
{
47-
return $"Value must be at most {_maxValue} e.g. {_maxValue - 2f}";
47+
return $"A number which is at most {_maxValue} e.g. {_maxValue - 2f}";
4848
}
4949

50-
throw new AndrzejFuckedUpException();
50+
return "Any number e.g. 2.5";
5151
}
5252
}
5353

ArgumentSystem/MethodArgumentDispatcher.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ public DynamicTryGet Invoke(BaseToken token, Argument arg)
2525
{
2626
return (DynamicTryGet)Method.Invoke(arg, [token]);
2727
}
28-
catch (TargetInvocationException)
28+
catch (TargetInvocationException ex)
2929
{
30-
return DynamicTryGet.Error($"Evaluation system of {arg.Name} has failed. Report this to the plugin developer.");
30+
return DynamicTryGet.Error($"This error is not an expected one, report it to the developers. {ex.InnerException?.Message} {ex.InnerException?.StackTrace}");
3131
}
3232
}
3333
}

ContextSystem/Contexts/Control/ElifStatementContext.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,9 @@ public override Result VerifyCurrentState()
4040

4141
protected override IEnumerator<float> Execute()
4242
{
43-
if (ExpressionReslover.EvalCondition(_condition.ToArray(), Script).HasErrored(out var error, out var result))
43+
if (NumericExpressionReslover.EvalCondition(_condition.ToArray(), Script).HasErrored(out var error, out var result))
4444
{
4545
throw new ScriptErrorException($"'elif' statement condition error: {error}");
46-
yield break;
4746
}
4847

4948
if (!result)

ContextSystem/Contexts/Control/IfStatementContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public override Result VerifyCurrentState()
3636

3737
protected override IEnumerator<float> Execute()
3838
{
39-
if (ExpressionReslover.EvalCondition(_condition.ToArray(), Script).HasErrored(out var error, out var result))
39+
if (NumericExpressionReslover.EvalCondition(_condition.ToArray(), Script).HasErrored(out var error, out var result))
4040
{
4141
throw new ScriptErrorException($"'if' statement condition error: {error}");
4242
}

ContextSystem/Contexts/Control/Loops/WhileLoopContext.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public override Result VerifyCurrentState()
4242

4343
protected override IEnumerator<float> Execute()
4444
{
45-
if (ExpressionReslover.EvalCondition(_condition.ToArray(), Script).HasErrored(out var error, out var condition))
45+
if (NumericExpressionReslover.EvalCondition(_condition.ToArray(), Script).HasErrored(out var error, out var condition))
4646
{
4747
throw new ScriptErrorException(error);
4848
}
@@ -64,7 +64,7 @@ protected override IEnumerator<float> Execute()
6464
break;
6565
}
6666

67-
if (ExpressionReslover.EvalCondition(_condition.ToArray(), Script).HasErrored(out var error2, out condition))
67+
if (NumericExpressionReslover.EvalCondition(_condition.ToArray(), Script).HasErrored(out var error2, out condition))
6868
{
6969
throw new ScriptErrorException(error2);
7070
}

ContextSystem/Contexts/VariableDefinition/LiteralVariableDefinitionContext.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,6 @@ protected override void Execute()
143143
if (_variableFunc().HasErrored(out var error, out var variableToCopy))
144144
{
145145
throw new ScriptErrorException(error);
146-
return;
147146
}
148147

149148
variable = variableToCopy;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
namespace SER.Helpers;
1616

17-
public static class ExpressionReslover
17+
public static class NumericExpressionReslover
1818
{
1919
public static TryGet<object> EvalString(string expression, Script scr)
2020
{

MethodSystem/Methods/LiteralVariableMethods/EvalMethod.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class EvalMethod : ReturningMethod
2222
public override void Execute()
2323
{
2424
var value = Args.GetText("value");
25-
if (ExpressionReslover.EvalString(value, Script).HasErrored(out var error, out var result))
25+
if (NumericExpressionReslover.EvalString(value, Script).HasErrored(out var error, out var result))
2626
{
2727
throw new ScriptErrorException(error);
2828
}

MethodSystem/Methods/MathMethods/RandomNumMethod.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ public class RandomNumMethod : ReturningMethod, IAdditionalDescription
2323
[
2424
new FloatArgument("startingNum"),
2525
new FloatArgument("endingNum"),
26-
new OptionsArgument("numberType", "int", "real")
26+
new OptionsArgument(
27+
"numberType",
28+
new("int", "Returns an integer number"),
29+
new("real", "Returns a real number")
30+
)
2731
{
2832
DefaultValue = "real"
2933
}

0 commit comments

Comments
 (0)