Skip to content

Commit 6ae6973

Browse files
update the default value system for methiods
1 parent 33cbc39 commit 6ae6973

File tree

32 files changed

+68
-86
lines changed

32 files changed

+68
-86
lines changed

ArgumentSystem/Arguments/PlayersArgument.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using System.Collections.Generic;
2-
using System.Linq;
1+
using System.Linq;
32
using JetBrains.Annotations;
43
using LabApi.Features.Wrappers;
54
using SER.ArgumentSystem.BaseArguments;
@@ -17,19 +16,19 @@ public class PlayersArgument(string name) : Argument(name)
1716
public override string InputDescription => $"Player variable e.g. {PlayerVariableToken.Example} or * for every player";
1817

1918
[UsedImplicitly]
20-
public DynamicTryGet<List<Player>> GetConvertSolution(BaseToken token)
19+
public DynamicTryGet<Player[]> GetConvertSolution(BaseToken token)
2120
{
2221
if (token is SymbolToken { IsJoker: true })
2322
{
24-
return new(() => Player.ReadyList.ToList());
23+
return new(() => Player.ReadyList.ToArray());
2524
}
2625

2726
if (token is not IValueToken valToken || !valToken.CanReturn<PlayerValue>(out var get))
2827
{
2928
return $"Value '{token.RawRep}' does not represent a valid player variable.";
3029
}
3130

32-
return new(() => get().OnSuccess(v => v.Players.ToList()));
31+
return new(() => get().OnSuccess(v => v.Players));
3332
}
3433
}
3534

ArgumentSystem/BaseArguments/Argument.cs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,14 @@ public abstract class Argument(string name)
1717
/// The short description of the argument. Use IAdditionalDescription to add more if needed.
1818
/// </summary>
1919
public string? Description { get; init; } = null;
20-
21-
public bool IsOptional { get; private set; } = false;
20+
21+
public record Default(object? Value, string? StringRep);
2222

2323
/// <summary>
2424
/// Sets the default value for this argument, allowing it to be skipped by the user.
2525
/// Null values are allowed, the method must handle it accordingly.
2626
/// </summary>
27-
public object? DefaultValue
28-
{
29-
get;
30-
init
31-
{
32-
IsOptional = true;
33-
field = value;
34-
}
35-
}
27+
public Default? DefaultValue;
3628

3729
public abstract string InputDescription { get; }
3830

ContextSystem/Contexts/MethodContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public override TryAddTokenRes TryAddToken(BaseToken token)
3636

3737
public override Result VerifyCurrentState()
3838
{
39-
return Result.Assert(_providedArguments >= Method.ExpectedArguments.Count(arg => !arg.IsOptional),
39+
return Result.Assert(_providedArguments >= Method.ExpectedArguments.Count(arg => arg.DefaultValue is not null),
4040
$"Method '{Method.Name}' is missing required arguments: " +
4141
$"{", ".Join(Method.ExpectedArguments.Skip(_providedArguments).Select(arg => arg.Name))}");
4242
}

MethodSystem/Methods/CASSIEMethods/CassieMethod.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ public class CassieMethod : SynchronousMethod
2121
new TextArgument("message"),
2222
new TextArgument("translation")
2323
{
24-
DefaultValue = "",
24+
DefaultValue = new("", "empty"),
2525
},
2626
new BoolArgument("should glitch")
2727
{
2828
Description = "If true, SER will add random glitch effects to the announcement.",
29-
DefaultValue = false,
29+
DefaultValue = new(false, null),
3030
}
3131
];
3232

MethodSystem/Methods/DoorMethods/BreakDoorMethod.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ internal class BreakDoorMethod : SynchronousMethod
1919
},
2020
new EnumArgument<DoorDamageType>("damage type")
2121
{
22-
DefaultValue = DoorDamageType.ServerCommand,
22+
DefaultValue = new(DoorDamageType.ServerCommand, null),
2323
Description = "Type of damage to be applied on doors"
2424
}
2525
];

MethodSystem/Methods/DoorMethods/LockDoorMethod.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class LockDoorMethod : SynchronousMethod
1414
new DoorsArgument("doors"),
1515
new EnumArgument<DoorLockReason>("lock")
1616
{
17-
DefaultValue = DoorLockReason.AdminCommand
17+
DefaultValue = new(DoorLockReason.AdminCommand, null)
1818
}
1919
];
2020

MethodSystem/Methods/HealthMethods/DamageMethod.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class DamageMethod : SynchronousMethod
1414
new FloatArgument("amount", 0),
1515
new TextArgument("reason")
1616
{
17-
DefaultValue = string.Empty
17+
DefaultValue = new(string.Empty, "empty")
1818
}
1919
];
2020

MethodSystem/Methods/HealthMethods/HealMethod.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class HealMethod : SynchronousMethod
1313
new PlayersArgument("players to heal"),
1414
new FloatArgument("amount", 0)
1515
{
16-
DefaultValue = float.MaxValue,
16+
DefaultValue = new(float.MaxValue, "max amount"),
1717
Description = "If this argument is not provided, all players will be fully healed."
1818
}
1919
];

MethodSystem/Methods/HealthMethods/KillMethod.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class KillMethod : SynchronousMethod
1313
new PlayersArgument("players"),
1414
new TextArgument("reason")
1515
{
16-
DefaultValue = string.Empty,
16+
DefaultValue = new(string.Empty, "empty"),
1717
}
1818
];
1919

MethodSystem/Methods/HealthMethods/SetAHPMethod.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,27 @@ public class SetAHPMethod : SynchronousMethod
2020
},
2121
new FloatArgument("limit", 0)
2222
{
23-
DefaultValue = 75,
23+
DefaultValue = new(75, null),
2424
Description = "The upper limit of AHP."
2525
},
2626
new FloatArgument("decay", 0)
2727
{
28-
DefaultValue = 1.2,
28+
DefaultValue = new(1.2, null),
2929
Description = "How much AHP is lost per second."
3030
},
3131
new FloatArgument("efficacy", 0, 1)
3232
{
33-
DefaultValue = 0.7,
33+
DefaultValue = new(0.7, "70%"),
3434
Description = "The percent of incoming damage absorbed by AHP."
3535
},
3636
new DurationArgument("sustain")
3737
{
38-
DefaultValue = TimeSpan.Zero,
38+
DefaultValue = new(TimeSpan.Zero, "instant (0 seconds)"),
3939
Description = "The amount of time before the AHP begins to decay."
4040
},
4141
new BoolArgument("isPersistent")
4242
{
43-
DefaultValue = false,
43+
DefaultValue = new(false, null),
4444
Description = "Whether or not the AHP process stays after AHP reaches 0."
4545
}
4646
];

0 commit comments

Comments
 (0)