Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions ArgumentSystem/Arguments/CollectionVariableArgument.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using JetBrains.Annotations;
using SER.ArgumentSystem.BaseArguments;
using SER.Helpers.ResultSystem;
using SER.TokenSystem.Tokens;
using SER.TokenSystem.Tokens.VariableTokens;
using SER.VariableSystem.Bases;
using SER.VariableSystem.Variables;

namespace SER.ArgumentSystem.Arguments;

/// <summary>
/// Represents any Variable argument used in a method.
/// </summary>
public class CollectionVariableArgument(string name) : Argument(name)
{
public override string InputDescription => "Any existing collection variable e.g. &texts or &playerIds";

[UsedImplicitly]
public DynamicTryGet<CollectionVariable> GetConvertSolution(BaseToken token)
{
if (token is not CollectionVariableToken variableToken)
{
return $"Value '{token.RawRep}' is not a collection variable.";
}

return new(() => variableToken.TryGetVariable());
}
}
6 changes: 6 additions & 0 deletions ArgumentSystem/ProvidedArguments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using SER.TokenSystem.Tokens.VariableTokens;
using SER.ValueSystem;
using SER.VariableSystem.Bases;
using SER.VariableSystem.Variables;
using UnityEngine;

namespace SER.ArgumentSystem;
Expand Down Expand Up @@ -179,6 +180,11 @@ public string GetOption(string argName)
return GetValue<string, OptionsArgument>(argName).ToLower();
}

public CollectionVariable GetCollectionVariable(string argName)
{
return GetValue<CollectionVariable, CollectionVariableArgument>(argName);
}

/// <summary>
/// Retrieves a list of remaining arguments based on the specified argument name.
/// The method resolves provided arguments into a typed list of values.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using SER.ArgumentSystem.Arguments;
using SER.ArgumentSystem.BaseArguments;
using SER.MethodSystem.BaseMethods;
using SER.MethodSystem.MethodDescriptors;
using SER.VariableSystem.Variables;

namespace SER.MethodSystem.Methods.CollectionVariableMethods;
public class CollectionInsertMethod : SynchronousMethod, IAdditionalDescription
{
public override string? Description => "Adds the value to the collection variable";

public string AdditionalDescription =>
"If value is a CollectionValue, it will nest the collection inside the collection variable. " +
"Use JoinCollections for combining collection values.";

public override Argument[] ExpectedArguments { get; } =
[
new CollectionVariableArgument("collection variable"),
new AnyValueArgument("value")
];

public override void Execute()
{
var collVar = Args.GetCollectionVariable("collection variable");
Script.AddVariable(new CollectionVariable(collVar.Name, collVar.Value.Insert(Args.GetAnyValue("value"))));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using SER.ArgumentSystem.Arguments;
using SER.ArgumentSystem.BaseArguments;
using SER.MethodSystem.BaseMethods;
using SER.VariableSystem.Variables;

namespace SER.MethodSystem.Methods.CollectionVariableMethods;
public class CollectionRemoveAtMethod : SynchronousMethod
{
public override string? Description => "Removes the value at the provided index from the collection variable";

public override Argument[] ExpectedArguments { get; } =
[
new CollectionVariableArgument("collection variable"),
new IntArgument("index", 1)
{
Description = "The place in the collection to remove the value from, starting from 1"
}
];

public override void Execute()
{
var collVar = Args.GetCollectionVariable("collection variable");
var index = Args.GetInt("index");

Script.AddVariable(new CollectionVariable(collVar.Name, collVar.Value.RemoveAt(index)));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using SER.ArgumentSystem.Arguments;
using SER.ArgumentSystem.BaseArguments;
using SER.MethodSystem.BaseMethods;
using SER.VariableSystem.Variables;

namespace SER.MethodSystem.Methods.CollectionVariableMethods;
public class CollectionRemoveMethod : SynchronousMethod
{
public override string? Description => "Removes the value from the collection variable";

public override Argument[] ExpectedArguments { get; } =
[
new CollectionVariableArgument("collection variable"),
new AnyValueArgument("value"),
new IntArgument("amount of matches to remove", -1)
{
Description = "Will delete every match if -1.",
DefaultValue = new(-1, null)
}
];

public override void Execute()
{
var collVar = Args.GetCollectionVariable("collection variable");
var i = Args.GetInt("amount of matches to remove");
var expectedVal = Args.GetAnyValue("value");

Script.AddVariable(new CollectionVariable(collVar.Name, collVar.Value.Remove(expectedVal, i)));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using SER.ArgumentSystem.Arguments;
using SER.ArgumentSystem.BaseArguments;
using SER.MethodSystem.BaseMethods;
using SER.ValueSystem;
using SER.Helpers.Exceptions;

namespace SER.MethodSystem.Methods.CollectionVariableMethods;
public class EmptyCollectionMethod : ReturningMethod<CollectionValue>
{
public override string? Description => "Returns an empty collection.";

public override Argument[] ExpectedArguments { get; } =
[
new OptionsArgument("collection type",
"bool",
"collection",
"duration",
"number",
"player",
"reference",
"text")
];

public override void Execute()
{
ReturnValue = Args.GetOption("collection type") switch
{
"bool" => new CollectionValue<BoolValue>([]),
"collection" => new CollectionValue<CollectionValue>([]),
"duration" => new CollectionValue<DurationValue>([]),
"number" => new CollectionValue<NumberValue>([]),
"player" => new CollectionValue<PlayerValue>([]),
"reference" => new CollectionValue<ReferenceValue>([]),
"text" => new CollectionValue<TextValue>([]),
_ => throw new TosoksFuckedUpException("out of range")
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using SER.ArgumentSystem.Arguments;
using SER.ArgumentSystem.BaseArguments;
using SER.MethodSystem.BaseMethods;
using SER.ValueSystem;

namespace SER.MethodSystem.Methods.CollectionVariableMethods;
public class JoinCollectionsMethod : ReturningMethod<CollectionValue>
{
public override string? Description => "Returns a collection that has the combined values of all the given collections";

public override Argument[] ExpectedArguments { get; } =
[
new CollectionArgument("collections")
{
ConsumesRemainingValues = true
}
];

public override void Execute()
{
ReturnValue = Args.GetRemainingArguments<CollectionValue, CollectionArgument>("collections").Aggregate((sum, cur) => sum + cur);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using SER.ArgumentSystem.Arguments;
using SER.ArgumentSystem.BaseArguments;
using SER.MethodSystem.BaseMethods;
using SER.ValueSystem;

namespace SER.MethodSystem.Methods.CollectionVariableMethods;
public class SubtractCollectionsMethod : ReturningMethod<CollectionValue>
{
public override string? Description => "Returns a collection that has the values of the first collection without the values of the latter";

public override Argument[] ExpectedArguments { get; } =
[
new CollectionArgument("original collection"),
new CollectionArgument("collections to remove values from")
{
ConsumesRemainingValues = true
}
];

public override void Execute()
{
ReturnValue = Args.GetRemainingArguments<CollectionValue, CollectionArgument>("collections to remove values from")
.Aggregate(Args.GetCollection("original collection"), (sum, cur) => sum - cur);
}
}
4 changes: 3 additions & 1 deletion MethodSystem/Methods/IntercomMethods/IntercomInfoMethod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ public class IntercomInfoMethod : ReturningMethod
"state",
"speaker",
"cooldown",
"speechTimeLeft")
"speechTimeLeft",
"textOverride")
];

public override Type[] ReturnTypes => [typeof(TextValue), typeof(PlayerValue), typeof(DurationValue)];
Expand All @@ -31,6 +32,7 @@ public override void Execute()
"speaker" => new PlayerValue(Player.ReadyList.ToList().Where(plr => plr.ReferenceHub == Intercom._singleton._curSpeaker)),
"cooldown" => new DurationValue(TimeSpan.FromSeconds(Intercom.State == IntercomState.Cooldown ? Intercom._singleton.RemainingTime : 0)),
"speechtimeleft" => new DurationValue(TimeSpan.FromSeconds(Intercom.State == IntercomState.InUse ? Intercom._singleton.RemainingTime : 0)),
"textoverride" => new TextValue(IntercomDisplay._singleton._overrideText),
_ => throw new TosoksFuckedUpException("out of range")
};
}
Expand Down
24 changes: 24 additions & 0 deletions MethodSystem/Methods/IntercomMethods/SetIntercomTextMethod.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using SER.MethodSystem.BaseMethods;
using SER.ArgumentSystem.BaseArguments;
using SER.ArgumentSystem.Arguments;
using PlayerRoles.Voice;
using SER.MethodSystem.MethodDescriptors;

namespace SER.MethodSystem.Methods.IntercomMethods;

public class SetIntercomTextMethod : SynchronousMethod, IAdditionalDescription
{
public override string? Description => "Sets the text on the Intercom.";

public string AdditionalDescription => "Resets the intercom text if given text is empty.";

public override Argument[] ExpectedArguments { get; } =
[
new TextArgument("text")
];

public override void Execute()
{
IntercomDisplay.TrySetDisplay(Args.GetText("text"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using SER.MethodSystem.BaseMethods;
using SER.ValueSystem;

namespace SER.MethodSystem.Methods.PlayerMethods;
namespace SER.MethodSystem.Methods.PlayerVariableMethods;

public class AmountOfMethod : ReturningMethod<NumberValue>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class JoinPlayersMethod : ReturningMethod<PlayerValue>
public override void Execute()
{
ReturnValue = new PlayerValue(Args
.GetRemainingArguments<List<Player>, PlayersArgument>("players")
.GetRemainingArguments<Player[], PlayersArgument>("players")
.Flatten()
.Distinct()
.ToArray()
Expand Down
Loading