Skip to content

Commit c5f7859

Browse files
name changes, other smaller additions
1 parent 3dbad03 commit c5f7859

File tree

54 files changed

+526
-338
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+526
-338
lines changed

ArgumentSystem/Arguments/BoolArgument.cs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,39 @@ public class BoolArgument(string name) : Argument(name)
1111
{
1212
public override string InputDescription => "boolean (true or false) value";
1313

14+
public bool IsFunction { get; init; } = false;
15+
16+
private static TryGet<bool> ParseAsLiteral(BaseToken token)
17+
{
18+
if (token.TryGetLiteralValue<BoolValue>().HasErrored(out var error, out var value))
19+
{
20+
return error;
21+
}
22+
23+
return value.ExactValue;
24+
}
25+
1426
[UsedImplicitly]
1527
public DynamicTryGet<bool> GetConvertSolution(BaseToken token)
1628
{
17-
if (token.TryGetLiteralValue<BoolValue>().WasSuccessful(out var boolValue))
29+
if (ParseAsLiteral(token).WasSuccessful(out var value))
1830
{
19-
return boolValue.Value;
31+
if (IsFunction) return new(() => ParseAsLiteral(token));
32+
return value;
2033
}
2134

2235
if (token is IValueCapableToken<LiteralValue> literalValueToken)
2336
{
2437
return new(() =>
2538
{
26-
if (literalValueToken.ExactValue.HasErrored(out var error, out var value))
39+
if (literalValueToken.ExactValue.HasErrored(out var error, out var valueTheGreat))
2740
{
2841
return error;
2942
}
3043

31-
if (value.Value is not bool @bool)
44+
if (valueTheGreat.BaseValue is not bool @bool)
3245
{
33-
return $"Value '{value}' retreived from {token.RawRep} is not a boolean.";
46+
return $"Value '{valueTheGreat}' retreived from {token.RawRep} is not a boolean.";
3447
}
3548

3649
return @bool;
@@ -39,4 +52,4 @@ public DynamicTryGet<bool> GetConvertSolution(BaseToken token)
3952

4053
return $"Value '{token.RawRep}' cannot be interpreted as a boolean value or condition.";
4154
}
42-
}
55+
}
Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
using System;
22
using JetBrains.Annotations;
33
using SER.ArgumentSystem.BaseArguments;
4-
using SER.Helpers.Exceptions;
54
using SER.Helpers.ResultSystem;
65
using SER.TokenSystem.Tokens;
6+
using SER.TokenSystem.Tokens.Interfaces;
77
using SER.ValueSystem;
8-
using Result = SER.Helpers.ResultSystem.Result;
98

109
namespace SER.ArgumentSystem.Arguments;
1110

@@ -16,21 +15,25 @@ public class DurationArgument(string name) : Argument(name)
1615
[UsedImplicitly]
1716
public DynamicTryGet<TimeSpan> GetConvertSolution(BaseToken token)
1817
{
19-
Result rs = $"Value '{token.RawRep}' is not a duration.";
2018
return token switch
2119
{
22-
DurationToken durToken => durToken.Value.Value,
23-
ExpressionToken { Type: MethodExpression methodExpr } => new(() =>
20+
DurationToken durToken => durToken.Value.ExactValue,
21+
IValueCapableToken<DurationValue> capable => new(() => capable.ExactValue.OnSuccess(v => v.ExactValue)),
22+
IValueCapableToken<LiteralValue> litCapable => new(() =>
2423
{
25-
methodExpr.Method.Execute();
26-
if (methodExpr.Method.ReturnValue is not DurationValue durValue)
24+
if (litCapable.ExactValue.HasErrored(out var litValError, out var literalValue))
2725
{
28-
throw new ScriptRuntimeError(rs);
26+
return litValError;
2927
}
3028

31-
return durValue.Value;
29+
if (literalValue.TryGetValue<DurationValue>().HasErrored(out var durValError, out var durationValue))
30+
{
31+
return durValError;
32+
}
33+
34+
return durationValue.ExactValue;
3235
}),
33-
_ => rs
36+
_ => $"Value '{token.RawRep}' is not a duration."
3437
};
3538
}
3639
}

ArgumentSystem/Arguments/EnumArgument.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Linq;
23
using JetBrains.Annotations;
34
using SER.ArgumentSystem.BaseArguments;
45
using SER.Helpers.Extensions;
@@ -26,7 +27,15 @@ public DynamicTryGet<object> GetConvertSolution(BaseToken token)
2627
return value;
2728
}
2829

29-
return new(() => InternalConvert(token));
30+
return new(() =>
31+
{
32+
if (InternalConvert(token).HasErrored(out var error, out value))
33+
{
34+
return error;
35+
}
36+
37+
return value;
38+
});
3039
}
3140

3241
public static TryGet<T> Convert<T>(BaseToken token, Script script) where T : struct, Enum
@@ -42,7 +51,9 @@ public static TryGet<T> Convert<T>(BaseToken token, Script script) where T : str
4251
public static TryGet<object> Convert(BaseToken token, Script script, Type enumType)
4352
{
4453
var stringRep = token.GetBestTextRepresentation(script);
45-
if (Enum.IsDefined(enumType, stringRep))
54+
55+
// only allow exact matches or matches with the first letter not capitalized
56+
if (Enum.GetNames(enumType).Any(n => n.LowerFirst() == stringRep))
4657
{
4758
return Enum.Parse(enumType, stringRep, true);
4859
}

ArgumentSystem/Arguments/FloatArgument.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public DynamicTryGet<float> GetConvertSolution(BaseToken token)
5757
{
5858
if (token is NumberToken number)
5959
{
60-
return VerifyRange((float)number.Value.Value);
60+
return VerifyRange((float)number.Value.ExactValue);
6161
}
6262

6363
if (token is not IValueCapableToken<LiteralValue>)
@@ -80,7 +80,7 @@ private TryGet<float> TryParse(BaseToken token)
8080
return error;
8181
}
8282

83-
return VerifyRange((float)value.Value);
83+
return VerifyRange((float)value.ExactValue);
8484
}
8585

8686
private TryGet<float> VerifyRange(float value)

ArgumentSystem/Arguments/IntArgument.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ private TryGet<int> TryParse(BaseToken token)
8484

8585
private TryGet<int> VerifyRange(NumberValue input)
8686
{
87-
var result = (int)input.Value;
87+
var result = (int)input.ExactValue;
8888

8989
if (result < _minValue)
9090
return $"Value '{result}' is lower than allowed minimum value {_minValue}.";

ArgumentSystem/Arguments/TextArgument.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@ public DynamicTryGet<string> GetConvertSolution(BaseToken token)
1717
{
1818
switch (token)
1919
{
20-
case TextToken { ContainsExpressions: false } textToken:
21-
return TryGet<string>.Success(textToken.Value);
2220
case TextToken textToken:
23-
return new(() => TryGet<string>.Success(textToken.ParsedValue()));
21+
return textToken.GetDynamicResolver();
2422
case IValueCapableToken<LiteralValue> capableToken:
2523
return new(() => capableToken.ExactValue.OnSuccess(v => v.ToString()));
2624
default:

ArgumentSystem/ProvidedArguments.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ public TEnum GetEnum<TEnum>(string argName) where TEnum : struct, Enum
251251
{
252252
var obj = GetValue<object, EnumArgument<TEnum>>(argName);
253253
if (obj is not TEnum value)
254-
throw new AndrzejFuckedUpException($"Cannot convert {obj.GetType().Name} to {typeof(TEnum).Name}");
254+
throw new AndrzejFuckedUpException($"Enum got {obj.GetType().AccurateName}, not {typeof(TEnum).AccurateName}");
255255

256256
return value;
257257
}

ContextSystem/Contexts/Control/Loops/RepeatLoopContext.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ public override TryAddTokenRes TryAddToken(BaseToken token)
5050
return $"Value '{value}' retreived from {token.RawRep} is not a number.";
5151
}
5252

53-
if (numberValue.Value < 0)
53+
if (numberValue.ExactValue < 0)
5454
{
5555
return $"Value '{value}' cannot be negative.";
5656
}
5757

58-
return (uint)numberValue.Value;
58+
return (uint)numberValue.ExactValue;
5959
};
6060
return TryAddTokenRes.End();
6161
}

EventSystem/EventHandler.cs

Lines changed: 39 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections;
23
using System.Collections.Generic;
34
using System.Linq;
45
using System.Linq.Expressions;
@@ -12,6 +13,7 @@
1213
using SER.Helpers.ResultSystem;
1314
using SER.ScriptSystem;
1415
using SER.ScriptSystem.Structures;
16+
using SER.TokenSystem.Tokens.Variables;
1517
using SER.ValueSystem;
1618
using SER.VariableSystem.Bases;
1719
using SER.VariableSystem.Variables;
@@ -168,7 +170,7 @@ private static void OnArgumentedEvent<T>(string evName, T ev) where T : EventArg
168170
return;
169171
}
170172

171-
foreach (var scrName in scriptsConnected)
173+
foreach (var scrName in scriptsConnected.ToArray())
172174
{
173175
Result rs = $"Failed to run script '{scrName}' connected to event '{evName}'";
174176
Log.Debug($"Running script '{scrName}' for event '{evName}'");
@@ -197,7 +199,7 @@ from prop in ev.GetType().GetProperties()
197199
return InternalGetVariablesFromProperties(properties);
198200
}
199201

200-
internal static List<Variable> GetMimicVariables(EventInfo ev)
202+
public static List<string> GetMimicVariables(EventInfo ev)
201203
{
202204
var genericType = ev.EventHandlerType.GetGenericArguments().FirstOrDefault();
203205
if (genericType is null)
@@ -254,31 +256,47 @@ string GetName()
254256
return variables.ToArray();
255257
}
256258

257-
private static List<Variable> GetMimicVariablesForEventHelp(List<(Type type, string name)> properties)
259+
private static List<string> GetMimicVariablesForEventHelp(List<(Type type, string name)> properties)
258260
{
259-
List<Variable> variables = [];
261+
List<string> variables = [];
260262
foreach (var (type, name) in properties)
261263
{
262-
Variable var = type switch
264+
string var;
265+
if (type is null) continue;
266+
267+
if (type == typeof(bool) ||
268+
type == typeof(string) ||
269+
type == typeof(int) ||
270+
type == typeof(float) ||
271+
type == typeof(double) ||
272+
type == typeof(decimal) ||
273+
type == typeof(byte) ||
274+
type == typeof(sbyte) ||
275+
type == typeof(short) ||
276+
type == typeof(ushort) ||
277+
type == typeof(uint) ||
278+
type.IsEnum)
279+
{
280+
var = $"{new LiteralVariableToken().Prefix}{GetName()}";
281+
}
282+
else if (
283+
type == typeof(Player) ||
284+
typeof(IEnumerable<Player>).IsAssignableFrom(type)
285+
)
263286
{
264-
not null when type == typeof(bool) || type == typeof(string) || type == typeof(int) ||
265-
type == typeof(float) || type == typeof(double) || type == typeof(decimal) ||
266-
type == typeof(byte) || type == typeof(sbyte) || type == typeof(short) ||
267-
type == typeof(ushort) ||
268-
type == typeof(uint) => new LiteralVariable<TextValue>(GetName(), null!),
269-
270-
not null when type.IsEnum => new LiteralVariable<TextValue>(GetName(), null!),
271-
272-
not null when type == typeof(Player) =>
273-
new PlayerVariable(GetName(), null!),
274-
275-
not null when typeof(IEnumerable<Player>).IsAssignableFrom(type) =>
276-
new PlayerVariable(GetName(), null!),
277-
278-
_ => new ReferenceVariable(GetName(), null!)
279-
};
287+
var = $"{new PlayerVariableToken().Prefix}{GetName()}";
288+
}
289+
else if (typeof(IEnumerable).IsAssignableFrom(type) && type != typeof(string))
290+
{
291+
var = $"{new CollectionVariableToken().Prefix}{GetName()}";
292+
}
293+
else
294+
{
295+
var = $"{new ReferenceVariableToken().Prefix}{GetName()}";
296+
}
280297

281298
variables.Add(var);
299+
continue;
282300

283301
string GetName()
284302
{

FlagSystem/Flags/CustomCommandFlag.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,17 @@ public override (string argName, string description)? InlineArgDescription =>
4545
AddDescription
4646
)
4747
};
48+
49+
[Flags]
50+
public enum ConsoleType
51+
{
52+
None = 0,
53+
Player = 1 << 0,
54+
RemoteAdmin = 1 << 1,
55+
Server = 1 << 2
56+
}
4857

49-
public override Result TryBind(string[] inlineArgs)
58+
public override Result TryInitialize(string[] inlineArgs)
5059
{
5160
switch (inlineArgs.Length)
5261
{
@@ -70,7 +79,7 @@ public override Result TryBind(string[] inlineArgs)
7079
return true;
7180
}
7281

73-
public override void Confirm()
82+
public override void FinalizeFlag()
7483
{
7584
if (ScriptCommands.ContainsKey(Command))
7685
{

0 commit comments

Comments
 (0)