Skip to content

Commit f292cea

Browse files
make GateArgument for PryGate method
1 parent 2dd79c2 commit f292cea

3 files changed

Lines changed: 68 additions & 5 deletions

File tree

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
using JetBrains.Annotations;
2+
using LabApi.Features.Enums;
3+
using LabApi.Features.Wrappers;
4+
using SER.Code.ArgumentSystem.BaseArguments;
5+
using SER.Code.Extensions;
6+
using SER.Code.Helpers.ResultSystem;
7+
using SER.Code.TokenSystem.Tokens;
8+
using SER.Code.TokenSystem.Tokens.Interfaces;
9+
using SER.Code.ValueSystem;
10+
11+
namespace SER.Code.ArgumentSystem.Arguments;
12+
13+
public class GateArgument(string name) : EnumHandlingArgument(name)
14+
{
15+
public override string InputDescription => $"{nameof(DoorName)} enum (that is a gate) or reference to {nameof(Gate)}";
16+
17+
[UsedImplicitly]
18+
public DynamicTryGet<Gate> GetConvertSolution(BaseToken token)
19+
{
20+
return ResolveEnums<Gate>(
21+
token,
22+
new()
23+
{
24+
[typeof(DoorName)] = doorName =>
25+
{
26+
var door = Gate.List.Where(gate => gate.DoorName == (DoorName)doorName).GetRandomValue();
27+
if (door is null)
28+
{
29+
return $"Gate with name '{doorName}' does not exist.";
30+
}
31+
32+
return door;
33+
}
34+
},
35+
() =>
36+
{
37+
Result rs = $"Value '{token.RawRep}' cannot be interpreted as {InputDescription}.";
38+
39+
if (token is not IValueToken val || !val.CapableOf<ReferenceValue>(out var func))
40+
{
41+
return rs;
42+
}
43+
44+
return new(() =>
45+
{
46+
if (func().HasErrored(out var error, out var refVal))
47+
{
48+
return error;
49+
}
50+
51+
if (ReferenceArgument<Gate>.TryParse(refVal).WasSuccessful(out var gate))
52+
{
53+
return gate;
54+
}
55+
56+
return rs;
57+
});
58+
}
59+
);
60+
}
61+
}

Code/ArgumentSystem/ProvidedArguments.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,11 @@ public Door GetDoor(string argName)
160160
return GetValue<Door, DoorArgument>(argName);
161161
}
162162

163+
public Gate GetGate(string argName)
164+
{
165+
return GetValue<Gate, GateArgument>(argName);
166+
}
167+
163168
public TimeSpan? GetNullableDuration(string argName)
164169
{
165170
return GetValueNullableStruct<TimeSpan, DurationArgument>(argName);

Code/MethodSystem/Methods/DoorMethods/PryGateMethod.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using JetBrains.Annotations;
2-
using LabApi.Features.Wrappers;
32
using MapGeneration.Distributors;
43
using SER.Code.ArgumentSystem.Arguments;
54
using SER.Code.ArgumentSystem.BaseArguments;
@@ -14,7 +13,7 @@ public class PryGateMethod : SynchronousMethod
1413

1514
public override Argument[] ExpectedArguments =>
1615
[
17-
new DoorArgument("gate"),
16+
new GateArgument("gate"),
1817
new BoolArgument("should play effects")
1918
{
2019
DefaultValue = new(false, "does not play button effects"),
@@ -24,11 +23,9 @@ public class PryGateMethod : SynchronousMethod
2423

2524
public override void Execute()
2625
{
27-
var door = Args.GetDoor("gate");
26+
var gate = Args.GetGate("gate");
2827
var playEffects = Args.GetBool("should play effects");
2928

30-
if (door is not Gate gate) return;
31-
3229
if (gate.IsOpened || gate.ExactState != 0f || gate.Base.IsBeingPried) return;
3330

3431
if (playEffects)

0 commit comments

Comments
 (0)