Skip to content

Commit 926986c

Browse files
a proof of concept collection system, to be removed later
1 parent e2bc94a commit 926986c

File tree

20 files changed

+227
-35
lines changed

20 files changed

+227
-35
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using JetBrains.Annotations;
2+
using SER.ArgumentSystem.BaseArguments;
3+
using SER.Helpers.ResultSystem;
4+
using SER.TokenSystem.Structures;
5+
using SER.TokenSystem.Tokens;
6+
using SER.ValueSystem;
7+
using UnityEngine;
8+
9+
namespace SER.ArgumentSystem.Arguments;
10+
11+
public class CollectionArgument(string name) : Argument(name)
12+
{
13+
public override string InputDescription => "A literal variable with a collection";
14+
15+
[UsedImplicitly]
16+
public DynamicTryGet<CollectionValue> GetConvertSolution(BaseToken token)
17+
{
18+
if (token is not ILiteralValueToken litVarToken)
19+
{
20+
return $"Value '{token.RawRepresentation}' cannot represent a collection.";
21+
}
22+
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+
});
37+
}
38+
}

ArgumentSystem/ProvidedArguments.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using SER.MethodSystem.BaseMethods;
1212
using SER.ScriptSystem;
1313
using SER.TokenSystem.Tokens;
14+
using SER.ValueSystem;
1415
using SER.VariableSystem.Variables;
1516
using UnityEngine;
1617

@@ -19,6 +20,11 @@ namespace SER.ArgumentSystem;
1920
public class ProvidedArguments(Method method)
2021
{
2122
private Dictionary<(string name, Type type), List<DynamicTryGet>> Arguments { get; } = [];
23+
24+
public CollectionValue GetCollection(string argName)
25+
{
26+
return GetValue<CollectionValue, CollectionArgument>(argName);
27+
}
2228

2329
public Room GetRoom(string argName)
2430
{

EventSystem/EventHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ private static IVariable[] InternalGetVariablesFromProperties(List<(object value
238238
continue;
239239
default:
240240
{
241-
variables.Add(LiteralVariable.CreateVariable(GetName(), LiteralValue.GetValueFromObject(value)));
241+
variables.Add(LiteralVariable.CreateVariable(GetName(), LiteralValue.ParseFromObject(value)));
242242
continue;
243243
}
244244
}

ExampleScripts/ExampleScript.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,5 @@
33
public abstract class ExampleScript
44
{
55
public abstract string Name { get; }
6-
76
public abstract string Content { get; }
87
}

ExampleScripts/Scripts/InviteInfoScript.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
namespace SER.ExampleScripts.Scripts;
1+
using JetBrains.Annotations;
22

3+
namespace SER.ExampleScripts.Scripts;
4+
5+
[UsedImplicitly]
36
public class InviteInfoScript : ExampleScript
47
{
58
public override string Name => "InviteBroadcast";
6-
79
public override string Content =>
810
"""
911
# this script is connected to the 'Joined' event, which means that this script will run when a player joins
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System;
2+
using SER.ArgumentSystem.Arguments;
3+
using SER.ArgumentSystem.BaseArguments;
4+
using SER.Helpers.Exceptions;
5+
using SER.MethodSystem.BaseMethods;
6+
using SER.ValueSystem;
7+
8+
namespace SER.MethodSystem.Methods.LiteralVariableMethods;
9+
10+
public class CollectionFetchMethod : ReturningMethod
11+
{
12+
public override string Description => "Returns a value from a collection variable at a given position.";
13+
public override Type[]? ReturnTypes => null;
14+
15+
public override Argument[] ExpectedArguments =>
16+
[
17+
new CollectionArgument("collection"),
18+
new IntArgument("index", 1)
19+
{
20+
Description = "The place in the collection to fetch the value from, starting from 1"
21+
}
22+
];
23+
24+
public override void Execute()
25+
{
26+
var coll = Args.GetCollection("collection");
27+
var index = Args.GetInt("index");
28+
29+
if (coll.GetAt(index).HasErrored(out var error, out var value))
30+
{
31+
throw new ScriptErrorException(error);
32+
}
33+
34+
Value = LiteralValue.ParseFromObject(value);
35+
}
36+
}

MethodSystem/Methods/LiteralVariableMethods/EvalMethod.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ public override void Execute()
2727
throw new ScriptErrorException(error);
2828
}
2929

30-
Value = LiteralValue.GetValueFromObject(result);
30+
Value = LiteralValue.ParseFromObject(result);
3131
}
3232
}

Plugin/Commands/HelpSystem/HelpCommand.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -485,12 +485,20 @@ private static string GetMethodHelp(Method method)
485485
switch (method)
486486
{
487487
case ReturningMethod ret:
488-
if (ret.ReturnTypes is not { } types)
488+
string typeReturn;
489+
if (ret.ReturnTypes is { } types)
489490
{
490-
throw new AndrzejFuckedUpException();
491+
typeReturn = types
492+
.Select(LiteralValue.GetFriendlyName)
493+
.Select(name => $"a {name} value")
494+
.JoinStrings(" or ");
495+
}
496+
else
497+
{
498+
typeReturn = "a value depending on your input";
491499
}
492500

493-
sb.AppendLine($"This method returns {types.Select(LiteralValue.GetFriendlyName).Select(name => $"a {name} value").JoinStrings(" or ")}, which can be saved or used directly.");
501+
sb.AppendLine($"This method returns {typeReturn}, which can be saved or used directly.");
494502
break;
495503
case PlayerReturningMethod:
496504
sb.AppendLine("This method returns a player value, which can be saved or used directly.");

SER.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
</ItemGroup>
8383
<ItemGroup>
8484
<Compile Include="ArgumentSystem\Arguments\BoolArgument.cs" />
85+
<Compile Include="ArgumentSystem\Arguments\CollectionArgument.cs" />
8586
<Compile Include="ArgumentSystem\Arguments\ColorArgument.cs" />
8687
<Compile Include="ArgumentSystem\Arguments\DoorArgument.cs" />
8788
<Compile Include="ArgumentSystem\Arguments\DoorsArgument.cs" />
@@ -180,6 +181,7 @@
180181
<Compile Include="MethodSystem\Methods\EventMethods\IsAllowedMethod.cs" />
181182
<Compile Include="MethodSystem\Methods\HealthMethods\DamageInfoMethod.cs" />
182183
<Compile Include="MethodSystem\Methods\HealthMethods\HealMethod.cs" />
184+
<Compile Include="MethodSystem\Methods\LiteralVariableMethods\CollectionFetchMethod.cs" />
183185
<Compile Include="MethodSystem\Methods\OutputMethods\ErrorMethod.cs" />
184186
<Compile Include="MethodSystem\Methods\OutputMethods\PrintMethod.cs" />
185187
<Compile Include="MethodSystem\Methods\OutputMethods\ReplyMethod.cs" />
@@ -308,13 +310,15 @@
308310
<Compile Include="TokenSystem\Tokens\TextToken.cs" />
309311
<Compile Include="TokenSystem\Tokens\ValueToken.cs" />
310312
<Compile Include="ValueSystem\BoolValue.cs" />
313+
<Compile Include="ValueSystem\CollectionValue.cs" />
311314
<Compile Include="ValueSystem\DurationValue.cs" />
312315
<Compile Include="ValueSystem\LiteralValue.cs" />
313316
<Compile Include="ValueSystem\NumberValue.cs" />
314317
<Compile Include="ValueSystem\ReferenceValue.cs" />
315318
<Compile Include="ValueSystem\TextValue.cs" />
316319
<Compile Include="VariableSystem\LiteralVariableIndex.cs" />
317320
<Compile Include="VariableSystem\Variables\BoolVariable.cs" />
321+
<Compile Include="VariableSystem\Variables\CollectionVariable.cs" />
318322
<Compile Include="VariableSystem\Variables\DurationVariable.cs" />
319323
<Compile Include="VariableSystem\Variables\LiteralVariable.cs" />
320324
<Compile Include="VariableSystem\Variables\IVariable.cs" />

SER.sln.DotSettings.user

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@
158158
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AActivator_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E2_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F3789ee403a53437cbb6b5d9ab6311f51573620_003F56_003F27c54aae_003FActivator_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
159159
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AAmmoItem_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fc20488a5a42a492c931d89475bee91cb6ee00_003F25_003F5c5c0545_003FAmmoItem_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
160160
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AAmmoItem_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fbea7f403b90e4786abd99fa819db98538f400_003Fba_003Fd4e18631_003FAmmoItem_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
161+
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AArray_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E2_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F3789ee403a53437cbb6b5d9ab6311f51573620_003Fbc_003F3cbc99cf_003FArray_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
161162
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AAttackerDamageHandler_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F9b41e261b6f7438da74257a46de8480732e000_003F44_003F6fb9062c_003FAttackerDamageHandler_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
162163
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ABanPlayer_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F9b41e261b6f7438da74257a46de8480732e000_003F4c_003F78b2d04b_003FBanPlayer_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
163164
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ABoolean_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E2_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F3789ee403a53437cbb6b5d9ab6311f51573620_003Fa9_003F04d891d0_003FBoolean_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
@@ -365,6 +366,7 @@
365366
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ASrvCfgCommand_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F9b41e261b6f7438da74257a46de8480732e000_003F21_003F039b76a5_003FSrvCfgCommand_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
366367
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AStandardDamageHandler_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F9b41e261b6f7438da74257a46de8480732e000_003F26_003Fea67e7eb_003FStandardDamageHandler_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
367368
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AStatusEffectBase_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F9b41e261b6f7438da74257a46de8480732e000_003F4e_003Ff3e92868_003FStatusEffectBase_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
369+
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AStringBuilder_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E2_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F9b41e261b6f7438da74257a46de8480732e000_003F33_003F65076119_003FStringBuilder_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
368370
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AString_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F9c2967a135e648bdb993c5397a44991b573620_003F08_003F24dd2091_003FString_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
369371
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AString_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fb18a8b3398e74bca86895881dd02956c573648_003Fb6_003F225aff52_003FString_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
370372
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AString_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F3789ee403a53437cbb6b5d9ab6311f51573620_003F99_003F0ea27859_003FString_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
@@ -387,6 +389,7 @@
387389
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AUInt32_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E2_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F3789ee403a53437cbb6b5d9ab6311f51573620_003F32_003Fa4c3db5a_003FUInt32_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
388390
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AUIntPtr_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fb18a8b3398e74bca86895881dd02956c573648_003F2b_003F828fb481_003FUIntPtr_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
389391
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AUniversalDamageHandler_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F9b41e261b6f7438da74257a46de8480732e000_003F99_003Ff9522ed4_003FUniversalDamageHandler_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
392+
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AUsedImplicitlyAttribute_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E2_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F6869b1608d104370ab4484f8f699b3fc1b5cb8_003F19_003Fa3b5d9f4_003FUsedImplicitlyAttribute_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
390393
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AUserGroup_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F9b41e261b6f7438da74257a46de8480732e000_003F5c_003Fe0006810_003FUserGroup_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
391394
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AVector3Int_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F6869b1608d104370ab4484f8f699b3fc1b5cb8_003F5e_003Fa6e343b5_003FVector3Int_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
392395
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AWarheadEvents_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fc20488a5a42a492c931d89475bee91cb6ee00_003Fc1_003Fe1efce11_003FWarheadEvents_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>

0 commit comments

Comments
 (0)