|
7 | 7 | using SER.Code.MethodSystem; |
8 | 8 | using SER.Code.MethodSystem.Structures; |
9 | 9 | using SER.Code.MethodSystem.Methods.CustomRoleMethods.Structures; |
| 10 | +using SER.Code.MethodSystem.Methods.CustomRoleMethods; |
10 | 11 | using SER.Code.ScriptSystem; |
11 | 12 | using SER.Code.ScriptSystem.Structures; |
12 | 13 | using SER.Code.TokenSystem; |
@@ -385,26 +386,49 @@ public static (string?, string[]) Verify(string? projectDirectory = null) |
385 | 386 | return null; |
386 | 387 | } |
387 | 388 |
|
388 | | - const string handlerId = "custom-role handler audit"; |
| 389 | + var roleAId = CRole_SetCallbacksMethod.GetHandlerId("roleA", ScriptName.CreateUnsafe("role_callback_audit")); |
| 390 | + var roleBId = CRole_SetCallbacksMethod.GetHandlerId("roleB", ScriptName.CreateUnsafe("role_callback_audit")); |
| 391 | + var otherScriptId = CRole_SetCallbacksMethod.GetHandlerId("roleA", ScriptName.CreateUnsafe("other_callback_audit")); |
| 392 | + var oldCalls = 0; |
| 393 | + var replacementCalls = 0; |
| 394 | + var roleBCalls = 0; |
| 395 | + var otherScriptCalls = 0; |
389 | 396 | var first = new CRole.Handler |
390 | 397 | { |
391 | | - Id = handlerId, |
392 | | - Action = (_, _) => { } |
| 398 | + Id = roleAId, |
| 399 | + ForRoles = ["roleA"], |
| 400 | + Action = (_, _) => oldCalls++ |
393 | 401 | }; |
394 | 402 | var replacement = new CRole.Handler |
395 | 403 | { |
396 | | - Id = handlerId, |
397 | | - Action = (_, _) => { } |
| 404 | + Id = roleAId, |
| 405 | + ForRoles = ["roleA"], |
| 406 | + Action = (_, _) => replacementCalls++ |
| 407 | + }; |
| 408 | + var roleB = new CRole.Handler |
| 409 | + { |
| 410 | + Id = roleBId, |
| 411 | + ForRoles = ["roleB"], |
| 412 | + Action = (_, _) => roleBCalls++ |
| 413 | + }; |
| 414 | + var otherScript = new CRole.Handler |
| 415 | + { |
| 416 | + Id = otherScriptId, |
| 417 | + ForRoles = ["roleA"], |
| 418 | + Action = (_, _) => otherScriptCalls++ |
398 | 419 | }; |
399 | 420 |
|
400 | 421 | try |
401 | 422 | { |
402 | 423 | CRole.AddOrReplaceHandler(CRole.CustomRoleEvent.Spawned, first); |
| 424 | + CRole.AddOrReplaceHandler(CRole.CustomRoleEvent.Spawned, roleB); |
| 425 | + CRole.AddOrReplaceHandler(CRole.CustomRoleEvent.Spawned, otherScript); |
403 | 426 | CRole.AddOrReplaceHandler(CRole.CustomRoleEvent.Spawned, replacement); |
404 | | - return CRole.EventHandlers[CRole.CustomRoleEvent.Spawned] is { Count: 1 } handlers |
405 | | - && ReferenceEquals(handlers.Single(), replacement) |
406 | | - ? null |
407 | | - : "Registering a custom-role callback twice left its stale handler active."; |
| 427 | + var handlers = CRole.EventHandlers[CRole.CustomRoleEvent.Spawned]; |
| 428 | + foreach (var handler in handlers) handler.Action(null!, null!); |
| 429 | + return handlers.Count == 3 && oldCalls == 0 && replacementCalls == 1 |
| 430 | + && roleBCalls == 1 && otherScriptCalls == 1 |
| 431 | + ? null : "Replacing a custom-role callback lost another role or script's callback, or kept the stale handler."; |
408 | 432 | } |
409 | 433 | finally |
410 | 434 | { |
|
0 commit comments