Skip to content

Commit 361a7f2

Browse files
remake the whole value system again
1 parent 926986c commit 361a7f2

File tree

148 files changed

+1675
-1378
lines changed

Some content is hidden

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

148 files changed

+1675
-1378
lines changed

App.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
</dependentAssembly>
2020
<dependentAssembly>
2121
<assemblyIdentity name="LabApi" publicKeyToken="null" culture="neutral" />
22-
<bindingRedirect oldVersion="0.0.0.0-1.0.2.0" newVersion="1.0.2.0" />
22+
<bindingRedirect oldVersion="0.0.0.0-1.1.3.0" newVersion="1.1.3.0" />
2323
</dependentAssembly>
2424
<dependentAssembly>
2525
<assemblyIdentity name="NorthwoodLib" publicKeyToken="null" culture="neutral" />
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using JetBrains.Annotations;
2+
using SER.ArgumentSystem.BaseArguments;
3+
using SER.Helpers.ResultSystem;
4+
using SER.TokenSystem.Tokens;
5+
using SER.TokenSystem.Tokens.Interfaces;
6+
using SER.ValueSystem;
7+
8+
namespace SER.ArgumentSystem.Arguments;
9+
10+
public class AnyValueArgument(string name) : Argument(name)
11+
{
12+
public override string InputDescription => "Any value";
13+
14+
[UsedImplicitly]
15+
public DynamicTryGet<Value> GetConvertSolution(BaseToken token)
16+
{
17+
if (token is IValueToken valToken)
18+
{
19+
return new(() => valToken.BaseValue);
20+
}
21+
22+
return $"Value '{token.RawRep}' does not represent any kind of value";
23+
}
24+
}
Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
using JetBrains.Annotations;
22
using SER.ArgumentSystem.BaseArguments;
3-
using SER.Helpers;
43
using SER.Helpers.ResultSystem;
5-
using SER.TokenSystem.Structures;
64
using SER.TokenSystem.Tokens;
5+
using SER.TokenSystem.Tokens.Interfaces;
76
using SER.ValueSystem;
87

98
namespace SER.ArgumentSystem.Arguments;
@@ -15,31 +14,29 @@ public class BoolArgument(string name) : Argument(name)
1514
[UsedImplicitly]
1615
public DynamicTryGet<bool> GetConvertSolution(BaseToken token)
1716
{
18-
if (token.TryGetValue<BoolValue>().WasSuccessful(out var boolValue))
17+
if (token.TryGetLiteralValue<BoolValue>().WasSuccessful(out var boolValue))
1918
{
20-
Log.D(11.ToString());
2119
return boolValue.Value;
2220
}
2321

24-
if (token is ILiteralValueToken literalValueToken)
22+
if (token is IValueCapableToken<LiteralValue> literalValueToken)
2523
{
26-
Log.D(21.ToString());
2724
return new(() =>
2825
{
29-
if (literalValueToken.GetLiteralValue(Script).HasErrored(out var error, out var value))
26+
if (literalValueToken.ExactValue.HasErrored(out var error, out var value))
3027
{
3128
return error;
3229
}
3330

3431
if (value.Value is not bool @bool)
3532
{
36-
return $"Value '{value}' retreived from {token.RawRepresentation} is not a boolean.";
33+
return $"Value '{value}' retreived from {token.RawRep} is not a boolean.";
3734
}
3835

3936
return @bool;
4037
});
4138
}
4239

43-
return $"Value '{token.RawRepresentation}' cannot be interpreted as a boolean value or condition.";
40+
return $"Value '{token.RawRep}' cannot be interpreted as a boolean value or condition.";
4441
}
4542
}
Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,25 @@
11
using JetBrains.Annotations;
22
using SER.ArgumentSystem.BaseArguments;
33
using SER.Helpers.ResultSystem;
4-
using SER.TokenSystem.Structures;
54
using SER.TokenSystem.Tokens;
5+
using SER.TokenSystem.Tokens.Interfaces;
6+
using SER.TokenSystem.Tokens.Variables;
67
using SER.ValueSystem;
7-
using UnityEngine;
88

99
namespace SER.ArgumentSystem.Arguments;
1010

1111
public class CollectionArgument(string name) : Argument(name)
1212
{
13-
public override string InputDescription => "A literal variable with a collection";
13+
public override string InputDescription => $"A collection variable e.g. {CollectionVariableToken.Example}";
1414

1515
[UsedImplicitly]
1616
public DynamicTryGet<CollectionValue> GetConvertSolution(BaseToken token)
1717
{
18-
if (token is not ILiteralValueToken litVarToken)
18+
if (token is not IValueCapableToken<CollectionValue> valueCapableToken)
1919
{
20-
return $"Value '{token.RawRepresentation}' cannot represent a collection.";
20+
return $"Value '{token.RawRep}' does not represent a collection";
2121
}
2222

23-
return new(() =>
24-
{
25-
if (litVarToken.GetLiteralValue(Script).HasErrored(out var error, out var value))
26-
{
27-
return error;
28-
}
29-
30-
if (value is not CollectionValue collection)
31-
{
32-
return $"Value '{value}' fetched from '{token.RawRepresentation}' is not a collection.";
33-
}
34-
35-
return collection;
36-
});
23+
return new(() => valueCapableToken.ExactValue);
3724
}
3825
}

ArgumentSystem/Arguments/ColorArgument.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ public DynamicTryGet<Color> GetConvertSolution(BaseToken token)
2424

2525
public static TryGet<Color> TryParseColor(string value)
2626
{
27+
var initValue = value;
28+
if (value.StartsWith("#"))
29+
{
30+
value = value.Substring(1);
31+
}
32+
2733
switch (value.Length)
2834
{
2935
// RRGGBB
@@ -45,7 +51,7 @@ public static TryGet<Color> TryParseColor(string value)
4551
return new Color(r, g, b, a);
4652
}
4753
default:
48-
return $"Invalid color format. Expected RRGGBB or RRGGBBAA, got {value.Length}.";
54+
return $"Invalid color format. Expected RRGGBB (6) or RRGGBBAA (8), got '{initValue}' ({value.Length}).";
4955
}
5056
}
5157
}

ArgumentSystem/Arguments/DoorArgument.cs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
using SER.Helpers.Extensions;
88
using SER.Helpers.ResultSystem;
99
using SER.TokenSystem.Tokens;
10+
using SER.TokenSystem.Tokens.Interfaces;
11+
using SER.ValueSystem;
1012

1113
namespace SER.ArgumentSystem.Arguments;
1214

@@ -46,12 +48,22 @@ public DynamicTryGet<Door> GetConvertSolution(BaseToken token)
4648
},
4749
() =>
4850
{
49-
if (ReferenceArgument<Door>.TryParse(token, Script).WasSuccessful(out var door))
51+
Result rs = $"Value '{token.RawRep}' cannot be interpreted as {InputDescription}.";
52+
53+
if (token is not IValueCapableToken<ReferenceValue> refToken)
5054
{
51-
return door;
55+
return rs;
5256
}
5357

54-
return $"Value '{token.RawRepresentation}' cannot be interpreted as a door.";
58+
return new(() =>
59+
{
60+
if (ReferenceArgument<Door>.TryParse(refToken).WasSuccessful(out var door))
61+
{
62+
return door;
63+
}
64+
65+
return rs;
66+
});
5567
}
5668
);
5769
}

ArgumentSystem/Arguments/DoorsArgument.cs

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66
using SER.ArgumentSystem.BaseArguments;
77
using SER.Helpers.ResultSystem;
88
using SER.TokenSystem.Tokens;
9+
using SER.TokenSystem.Tokens.Interfaces;
10+
using SER.ValueSystem;
911

1012
namespace SER.ArgumentSystem.Arguments;
1113

1214
public class DoorsArgument(string name) : EnumHandlingArgument(name)
1315
{
14-
public override string InputDescription => $"{nameof(DoorName)} enum, {nameof(FacilityZone)} enum, {nameof(RoomName)} enum, reference to {nameof(Door)}, or * for every door";
16+
public override string InputDescription => $"{nameof(DoorName)} enum, {nameof(FacilityZone)} enum, {nameof(RoomName)} enum, reference to {nameof(Door)}, reference to {nameof(Room)} or * for every door";
1517

1618
[UsedImplicitly]
1719
public DynamicTryGet<Door[]> GetConvertSolution(BaseToken token)
@@ -32,17 +34,32 @@ public DynamicTryGet<Door[]> GetConvertSolution(BaseToken token)
3234
},
3335
() =>
3436
{
35-
if (token.RawRepresentation == "*")
37+
Result rs =
38+
$"Value '{token.RawRep}' cannot be interpreted as a door or collection of doors.";
39+
if (token.RawRep == "*")
3640
{
3741
return Door.List.Where(d => d is not ElevatorDoor).ToArray();
3842
}
3943

40-
if (ReferenceArgument<Door>.TryParse(token, Script).WasSuccessful(out var door))
44+
if (token is not IValueCapableToken<ReferenceValue> refToken)
4145
{
42-
return new[] { door };
46+
return rs;
4347
}
4448

45-
return $"Value '{token.RawRepresentation}' cannot be interpreted as a door or collection of doors.";
49+
return new(() =>
50+
{
51+
if (ReferenceArgument<Door>.TryParse(refToken).WasSuccessful(out var door))
52+
{
53+
return new[] { door };
54+
}
55+
56+
if (ReferenceArgument<Room>.TryParse(refToken).WasSuccessful(out var room))
57+
{
58+
return room.Doors.ToArray();
59+
}
60+
61+
return rs;
62+
});
4663
}
4764
);
4865
}

ArgumentSystem/Arguments/DurationArgument.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@ public class DurationArgument(string name) : Argument(name)
1616
[UsedImplicitly]
1717
public DynamicTryGet<TimeSpan> GetConvertSolution(BaseToken token)
1818
{
19-
Result rs = $"Value '{token.RawRepresentation}' is not a duration.";
19+
Result rs = $"Value '{token.RawRep}' is not a duration.";
2020
return token switch
2121
{
2222
DurationToken durToken => durToken.Value.Value,
23-
LiteralExpressionToken { Type: MethodExpression methodExpr } => new(() =>
23+
ExpressionToken { Type: MethodExpression methodExpr } => new(() =>
2424
{
2525
methodExpr.Method.Execute();
26-
if (methodExpr.Method.Value is not DurationValue durValue)
26+
if (methodExpr.Method.ReturnValue is not DurationValue durValue)
2727
{
28-
throw new ScriptErrorException(rs);
28+
throw new ScriptRuntimeError(rs);
2929
}
3030

3131
return durValue.Value;

ArgumentSystem/Arguments/ElevatorsArgument.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public DynamicTryGet<Elevator[]> GetConvertSolution(BaseToken token)
3030
}
3131

3232
return
33-
$"Value '{token.RawRepresentation}' cannot be interpreted as an elevator or collection of elevators.";
33+
$"Value '{token.RawRep}' cannot be interpreted as an elevator or collection of elevators.";
3434
}
3535
);
3636
}

ArgumentSystem/Arguments/EnumArgument.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ public static TryGet<T> Convert<T>(BaseToken token, Script script) where T : str
4242
public static TryGet<object> Convert(BaseToken token, Script script, Type enumType)
4343
{
4444
var stringRep = token.GetBestTextRepresentation(script);
45-
if (Enum.TryParse(stringRep, true, out TEnum result))
45+
if (Enum.IsDefined(enumType, stringRep))
4646
{
47-
return result;
47+
return Enum.Parse(enumType, stringRep, true);
4848
}
4949

50-
return $"Value '{token.RawRepresentation}' does not represent a valid {enumType.GetAccurateName()} " +
50+
return $"Value '{stringRep}' does not represent a valid {enumType.GetAccurateName()} " +
5151
$"enum value.";
5252
}
5353

0 commit comments

Comments
 (0)