|
1 | 1 | using System; |
| 2 | +using System.Collections; |
2 | 3 | using System.Collections.Generic; |
3 | 4 | using System.Linq; |
4 | 5 | using System.Linq.Expressions; |
|
12 | 13 | using SER.Helpers.ResultSystem; |
13 | 14 | using SER.ScriptSystem; |
14 | 15 | using SER.ScriptSystem.Structures; |
| 16 | +using SER.TokenSystem.Tokens.Variables; |
15 | 17 | using SER.ValueSystem; |
16 | 18 | using SER.VariableSystem.Bases; |
17 | 19 | using SER.VariableSystem.Variables; |
@@ -168,7 +170,7 @@ private static void OnArgumentedEvent<T>(string evName, T ev) where T : EventArg |
168 | 170 | return; |
169 | 171 | } |
170 | 172 |
|
171 | | - foreach (var scrName in scriptsConnected) |
| 173 | + foreach (var scrName in scriptsConnected.ToArray()) |
172 | 174 | { |
173 | 175 | Result rs = $"Failed to run script '{scrName}' connected to event '{evName}'"; |
174 | 176 | Log.Debug($"Running script '{scrName}' for event '{evName}'"); |
@@ -197,7 +199,7 @@ from prop in ev.GetType().GetProperties() |
197 | 199 | return InternalGetVariablesFromProperties(properties); |
198 | 200 | } |
199 | 201 |
|
200 | | - internal static List<Variable> GetMimicVariables(EventInfo ev) |
| 202 | + public static List<string> GetMimicVariables(EventInfo ev) |
201 | 203 | { |
202 | 204 | var genericType = ev.EventHandlerType.GetGenericArguments().FirstOrDefault(); |
203 | 205 | if (genericType is null) |
@@ -254,31 +256,47 @@ string GetName() |
254 | 256 | return variables.ToArray(); |
255 | 257 | } |
256 | 258 |
|
257 | | - private static List<Variable> GetMimicVariablesForEventHelp(List<(Type type, string name)> properties) |
| 259 | + private static List<string> GetMimicVariablesForEventHelp(List<(Type type, string name)> properties) |
258 | 260 | { |
259 | | - List<Variable> variables = []; |
| 261 | + List<string> variables = []; |
260 | 262 | foreach (var (type, name) in properties) |
261 | 263 | { |
262 | | - Variable var = type switch |
| 264 | + string var; |
| 265 | + if (type is null) continue; |
| 266 | + |
| 267 | + if (type == typeof(bool) || |
| 268 | + type == typeof(string) || |
| 269 | + type == typeof(int) || |
| 270 | + type == typeof(float) || |
| 271 | + type == typeof(double) || |
| 272 | + type == typeof(decimal) || |
| 273 | + type == typeof(byte) || |
| 274 | + type == typeof(sbyte) || |
| 275 | + type == typeof(short) || |
| 276 | + type == typeof(ushort) || |
| 277 | + type == typeof(uint) || |
| 278 | + type.IsEnum) |
| 279 | + { |
| 280 | + var = $"{new LiteralVariableToken().Prefix}{GetName()}"; |
| 281 | + } |
| 282 | + else if ( |
| 283 | + type == typeof(Player) || |
| 284 | + typeof(IEnumerable<Player>).IsAssignableFrom(type) |
| 285 | + ) |
263 | 286 | { |
264 | | - not null when type == typeof(bool) || type == typeof(string) || type == typeof(int) || |
265 | | - type == typeof(float) || type == typeof(double) || type == typeof(decimal) || |
266 | | - type == typeof(byte) || type == typeof(sbyte) || type == typeof(short) || |
267 | | - type == typeof(ushort) || |
268 | | - type == typeof(uint) => new LiteralVariable<TextValue>(GetName(), null!), |
269 | | - |
270 | | - not null when type.IsEnum => new LiteralVariable<TextValue>(GetName(), null!), |
271 | | - |
272 | | - not null when type == typeof(Player) => |
273 | | - new PlayerVariable(GetName(), null!), |
274 | | - |
275 | | - not null when typeof(IEnumerable<Player>).IsAssignableFrom(type) => |
276 | | - new PlayerVariable(GetName(), null!), |
277 | | - |
278 | | - _ => new ReferenceVariable(GetName(), null!) |
279 | | - }; |
| 287 | + var = $"{new PlayerVariableToken().Prefix}{GetName()}"; |
| 288 | + } |
| 289 | + else if (typeof(IEnumerable).IsAssignableFrom(type) && type != typeof(string)) |
| 290 | + { |
| 291 | + var = $"{new CollectionVariableToken().Prefix}{GetName()}"; |
| 292 | + } |
| 293 | + else |
| 294 | + { |
| 295 | + var = $"{new ReferenceVariableToken().Prefix}{GetName()}"; |
| 296 | + } |
280 | 297 |
|
281 | 298 | variables.Add(var); |
| 299 | + continue; |
282 | 300 |
|
283 | 301 | string GetName() |
284 | 302 | { |
|
0 commit comments