Skip to content

Commit 08b4afa

Browse files
add value parsing for custom commands
1 parent 0600258 commit 08b4afa

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

FlagSystem/Flags/CustomCommandFlag.cs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
using CommandSystem;
22
using JetBrains.Annotations;
33
using RemoteAdmin;
4+
using SER.Helpers;
45
using SER.Helpers.Exceptions;
56
using SER.Helpers.Extensions;
67
using SER.Helpers.ResultSystem;
78
using SER.ScriptSystem;
89
using SER.ScriptSystem.Structures;
910
using SER.TokenSystem;
11+
using SER.TokenSystem.Tokens.Interfaces;
1012
using SER.ValueSystem;
13+
using SER.VariableSystem.Bases;
1114
using SER.VariableSystem.Variables;
1215
using Console = GameCore.Console;
1316

@@ -177,7 +180,8 @@ public static Result RunAttachedScript(CustomCommand requestingCommand, ScriptEx
177180
return "The script that was supposed to handle this command was not found.";
178181
}
179182

180-
if (Tokenizer.SliceLine(args.JoinStrings(" ")).HasErrored(out var sliceError, out var outSlices))
183+
if (Tokenizer.SliceLine(args.JoinStrings(" "))
184+
.HasErrored(out var sliceError, out var outSlices))
181185
{
182186
return sliceError;
183187
}
@@ -203,11 +207,21 @@ public static Result RunAttachedScript(CustomCommand requestingCommand, ScriptEx
203207

204208
for (var index = 0; index < requestingCommand.Usage.Length; index++)
205209
{
210+
var slice = slices[index];
206211
var argVariable = requestingCommand.Usage[index];
207212
var name = argVariable[0].ToString().ToLower() + argVariable.Substring(1);
213+
214+
if (Tokenizer.GetTokenFromSlice(slice, null!, 0)
215+
.WasSuccessful(out var token))
216+
{
217+
if (token.TryGetLiteralValue<LiteralValue>().WasSuccessful(out var value))
218+
{
219+
script.AddVariable(Variable.CreateVariable(name, value));
220+
continue;
221+
}
222+
}
208223

209-
// todo: need to parse values from string too (probably using tokenizer)
210-
script.AddVariable(new LiteralVariable<TextValue>(name, slices[index].Value));
224+
script.AddVariable(new LiteralVariable<TextValue>(name, slice.Value));
211225
}
212226

213227
script.Run();

0 commit comments

Comments
 (0)