Skip to content

Commit 2f809d2

Browse files
committed
new argument, 7 new methods, 1 method change, 2 fixes
1 parent 42f59a8 commit 2f809d2

17 files changed

+388
-57
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using JetBrains.Annotations;
2+
using SER.ArgumentSystem.BaseArguments;
3+
using SER.Helpers.ResultSystem;
4+
using SER.TokenSystem.Tokens;
5+
using SER.TokenSystem.Tokens.VariableTokens;
6+
using SER.VariableSystem.Bases;
7+
using SER.VariableSystem.Variables;
8+
9+
namespace SER.ArgumentSystem.Arguments;
10+
11+
/// <summary>
12+
/// Represents any Variable argument used in a method.
13+
/// </summary>
14+
public class CollectionVariableArgument(string name) : Argument(name)
15+
{
16+
public override string InputDescription => "Any existing collection variable e.g. &texts or &playerIds";
17+
18+
[UsedImplicitly]
19+
public DynamicTryGet<CollectionVariable> GetConvertSolution(BaseToken token)
20+
{
21+
if (token is not CollectionVariableToken variableToken)
22+
{
23+
return $"Value '{token.RawRep}' is not a collection variable.";
24+
}
25+
26+
return new(() => variableToken.TryGetVariable());
27+
}
28+
}

ArgumentSystem/ProvidedArguments.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
using SER.TokenSystem.Tokens.VariableTokens;
1414
using SER.ValueSystem;
1515
using SER.VariableSystem.Bases;
16+
using SER.VariableSystem.Variables;
1617
using UnityEngine;
1718

1819
namespace SER.ArgumentSystem;
@@ -179,6 +180,11 @@ public string GetOption(string argName)
179180
return GetValue<string, OptionsArgument>(argName).ToLower();
180181
}
181182

183+
public CollectionVariable GetCollectionVariable(string argName)
184+
{
185+
return GetValue<CollectionVariable, CollectionVariableArgument>(argName);
186+
}
187+
182188
/// <summary>
183189
/// Retrieves a list of remaining arguments based on the specified argument name.
184190
/// The method resolves provided arguments into a typed list of values.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using SER.ArgumentSystem.Arguments;
2+
using SER.ArgumentSystem.BaseArguments;
3+
using SER.MethodSystem.BaseMethods;
4+
using SER.MethodSystem.MethodDescriptors;
5+
using SER.VariableSystem.Variables;
6+
7+
namespace SER.MethodSystem.Methods.CollectionVariableMethods;
8+
public class CollectionInsertMethod : SynchronousMethod, IAdditionalDescription
9+
{
10+
public override string? Description => "Adds the value to the collection variable";
11+
12+
public string AdditionalDescription =>
13+
"If value is a CollectionValue, it will nest the collection inside the collection variable. " +
14+
"Use JoinCollections for combining collection values.";
15+
16+
public override Argument[] ExpectedArguments { get; } =
17+
[
18+
new CollectionVariableArgument("collection variable"),
19+
new AnyValueArgument("value")
20+
];
21+
22+
public override void Execute()
23+
{
24+
var collVar = Args.GetCollectionVariable("collection variable");
25+
Script.AddVariable(new CollectionVariable(collVar.Name, collVar.Value.Insert(Args.GetAnyValue("value"))));
26+
}
27+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using SER.ArgumentSystem.Arguments;
2+
using SER.ArgumentSystem.BaseArguments;
3+
using SER.MethodSystem.BaseMethods;
4+
using SER.VariableSystem.Variables;
5+
6+
namespace SER.MethodSystem.Methods.CollectionVariableMethods;
7+
public class CollectionRemoveAtMethod : SynchronousMethod
8+
{
9+
public override string? Description => "Removes the value at the provided index from the collection variable";
10+
11+
public override Argument[] ExpectedArguments { get; } =
12+
[
13+
new CollectionVariableArgument("collection variable"),
14+
new IntArgument("index", 1)
15+
{
16+
Description = "The place in the collection to remove the value from, starting from 1"
17+
}
18+
];
19+
20+
public override void Execute()
21+
{
22+
var collVar = Args.GetCollectionVariable("collection variable");
23+
var index = Args.GetInt("index");
24+
25+
Script.AddVariable(new CollectionVariable(collVar.Name, collVar.Value.RemoveAt(index)));
26+
}
27+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using SER.ArgumentSystem.Arguments;
2+
using SER.ArgumentSystem.BaseArguments;
3+
using SER.MethodSystem.BaseMethods;
4+
using SER.VariableSystem.Variables;
5+
6+
namespace SER.MethodSystem.Methods.CollectionVariableMethods;
7+
public class CollectionRemoveMethod : SynchronousMethod
8+
{
9+
public override string? Description => "Removes the value from the collection variable";
10+
11+
public override Argument[] ExpectedArguments { get; } =
12+
[
13+
new CollectionVariableArgument("collection variable"),
14+
new AnyValueArgument("value"),
15+
new IntArgument("amount of matches to remove", -1)
16+
{
17+
Description = "Will delete every match if -1.",
18+
DefaultValue = new(-1, null)
19+
}
20+
];
21+
22+
public override void Execute()
23+
{
24+
var collVar = Args.GetCollectionVariable("collection variable");
25+
var i = Args.GetInt("amount of matches to remove");
26+
var expectedVal = Args.GetAnyValue("value");
27+
28+
Script.AddVariable(new CollectionVariable(collVar.Name, collVar.Value.Remove(expectedVal, i)));
29+
}
30+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using SER.ArgumentSystem.Arguments;
2+
using SER.ArgumentSystem.BaseArguments;
3+
using SER.MethodSystem.BaseMethods;
4+
using SER.ValueSystem;
5+
using SER.Helpers.Exceptions;
6+
7+
namespace SER.MethodSystem.Methods.CollectionVariableMethods;
8+
public class EmptyCollectionMethod : ReturningMethod<CollectionValue>
9+
{
10+
public override string? Description => "Returns an empty collection.";
11+
12+
public override Argument[] ExpectedArguments { get; } =
13+
[
14+
new OptionsArgument("collection type",
15+
"bool",
16+
"collection",
17+
"duration",
18+
"number",
19+
"player",
20+
"reference",
21+
"text")
22+
];
23+
24+
public override void Execute()
25+
{
26+
ReturnValue = Args.GetOption("collection type") switch
27+
{
28+
"bool" => new CollectionValue<BoolValue>([]),
29+
"collection" => new CollectionValue<CollectionValue>([]),
30+
"duration" => new CollectionValue<DurationValue>([]),
31+
"number" => new CollectionValue<NumberValue>([]),
32+
"player" => new CollectionValue<PlayerValue>([]),
33+
"reference" => new CollectionValue<ReferenceValue>([]),
34+
"text" => new CollectionValue<TextValue>([]),
35+
_ => throw new TosoksFuckedUpException("out of range")
36+
};
37+
}
38+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using SER.ArgumentSystem.Arguments;
2+
using SER.ArgumentSystem.BaseArguments;
3+
using SER.MethodSystem.BaseMethods;
4+
using SER.ValueSystem;
5+
6+
namespace SER.MethodSystem.Methods.CollectionVariableMethods;
7+
public class JoinCollectionsMethod : ReturningMethod<CollectionValue>
8+
{
9+
public override string? Description => "Returns a collection that has the combined values of all the given collections";
10+
11+
public override Argument[] ExpectedArguments { get; } =
12+
[
13+
new CollectionArgument("collections")
14+
{
15+
ConsumesRemainingValues = true
16+
}
17+
];
18+
19+
public override void Execute()
20+
{
21+
ReturnValue = Args.GetRemainingArguments<CollectionValue, CollectionArgument>("collections").Aggregate((sum, cur) => sum + cur);
22+
}
23+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using SER.ArgumentSystem.Arguments;
2+
using SER.ArgumentSystem.BaseArguments;
3+
using SER.MethodSystem.BaseMethods;
4+
using SER.ValueSystem;
5+
6+
namespace SER.MethodSystem.Methods.CollectionVariableMethods;
7+
public class SubtractCollectionsMethod : ReturningMethod<CollectionValue>
8+
{
9+
public override string? Description => "Returns a collection that has the values of the first collection without the values of the latter";
10+
11+
public override Argument[] ExpectedArguments { get; } =
12+
[
13+
new CollectionArgument("original collection"),
14+
new CollectionArgument("collections to remove values from")
15+
{
16+
ConsumesRemainingValues = true
17+
}
18+
];
19+
20+
public override void Execute()
21+
{
22+
ReturnValue = Args.GetRemainingArguments<CollectionValue, CollectionArgument>("collections to remove values from")
23+
.Aggregate(Args.GetCollection("original collection"), (sum, cur) => sum - cur);
24+
}
25+
}

MethodSystem/Methods/IntercomMethods/IntercomInfoMethod.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ public class IntercomInfoMethod : ReturningMethod
1818
"state",
1919
"speaker",
2020
"cooldown",
21-
"speechTimeLeft")
21+
"speechTimeLeft",
22+
"textOverride")
2223
];
2324

2425
public override Type[] ReturnTypes => [typeof(TextValue), typeof(PlayerValue), typeof(DurationValue)];
@@ -31,6 +32,7 @@ public override void Execute()
3132
"speaker" => new PlayerValue(Player.ReadyList.ToList().Where(plr => plr.ReferenceHub == Intercom._singleton._curSpeaker)),
3233
"cooldown" => new DurationValue(TimeSpan.FromSeconds(Intercom.State == IntercomState.Cooldown ? Intercom._singleton.RemainingTime : 0)),
3334
"speechtimeleft" => new DurationValue(TimeSpan.FromSeconds(Intercom.State == IntercomState.InUse ? Intercom._singleton.RemainingTime : 0)),
35+
"textoverride" => new TextValue(IntercomDisplay._singleton._overrideText),
3436
_ => throw new TosoksFuckedUpException("out of range")
3537
};
3638
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using SER.MethodSystem.BaseMethods;
2+
using SER.ArgumentSystem.BaseArguments;
3+
using SER.ArgumentSystem.Arguments;
4+
using PlayerRoles.Voice;
5+
using SER.MethodSystem.MethodDescriptors;
6+
7+
namespace SER.MethodSystem.Methods.IntercomMethods;
8+
9+
public class SetIntercomTextMethod : SynchronousMethod, IAdditionalDescription
10+
{
11+
public override string? Description => "Sets the text on the Intercom.";
12+
13+
public string AdditionalDescription => "Resets the intercom text if given text is empty.";
14+
15+
public override Argument[] ExpectedArguments { get; } =
16+
[
17+
new TextArgument("text")
18+
];
19+
20+
public override void Execute()
21+
{
22+
IntercomDisplay.TrySetDisplay(Args.GetText("text"));
23+
}
24+
}

0 commit comments

Comments
 (0)