Skip to content

Commit

Permalink
feat: Sync Events no longer need Event prefix (#2087)
Browse files Browse the repository at this point in the history
Instead of doing
```cs
[SyncEvent]
public event MySyncEventDelegate EventOnly;
```

You can now do
```cs
[SyncEvent]
public event MySyncEventDelegate Only;
```

We actually tried to remove them a while ago. The way the weaver worked
back then caused an infinite recursion.

Since the Command rewrite that allows virtuals, this is no longer
a problem.  So we can drop this requirement.

Co-authored-by: Paul Pacheco <paul.pacheco@aa.com>
  • Loading branch information
paulpach and paulpach committed Jul 12, 2020
1 parent eb93c34 commit ed40c2d
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 29 deletions.
6 changes: 0 additions & 6 deletions Assets/Mirror/Editor/Weaver/Processors/SyncEventProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,6 @@ public static void ProcessEvents(TypeDefinition td, List<EventDefinition> events

if (syncEventAttr != null)
{
if (!ed.Name.StartsWith("Event"))
{
Weaver.Error($"{ed.Name} must start with Event. Consider renaming it to Event{ed.Name}", ed);
return;
}

if (ed.EventType.Resolve().HasGenericParameters)
{
Weaver.Error($"{ed.Name} must not have generic parameters. Consider creating a new class that inherits from {ed.EventType} instead", ed);
Expand Down
6 changes: 3 additions & 3 deletions Assets/Mirror/Tests/Editor/SyncEventTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ namespace Mirror.Tests.RemoteAttrributeTest
class SyncEventBehaviour : NetworkBehaviour
{
[SyncEvent]
public event MySyncEventDelegate EventOnly;
public event MySyncEventDelegate Only;

public void CallEvent(int i)
{
EventOnly.Invoke(i);
Only.Invoke(i);
}
}

Expand Down Expand Up @@ -51,7 +51,7 @@ public void FirstEventIsCalled()
const int someInt = 20;

int callCount = 0;
clientBehaviour.EventOnly += incomingInt =>
clientBehaviour.Only += incomingInt =>
{
callCount++;
Assert.That(incomingInt, Is.EqualTo(someInt));
Expand Down
8 changes: 0 additions & 8 deletions Assets/Mirror/Tests/Editor/Weaver/WeaverSyncEventTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,6 @@ public void MultipleSyncEvent()
Assert.That(weaverErrors, Is.Empty);
}

[Test]
public void ErrorWhenSyncEventDoesntStartWithEvent()
{
Assert.That(weaverErrors, Contains.Item("DoCoolThingsWithExcitingPeople must start with Event. " +
"Consider renaming it to EventDoCoolThingsWithExcitingPeople " +
"(at WeaverSyncEventTests.ErrorWhenSyncEventDoesntStartWithEvent.ErrorWhenSyncEventDoesntStartWithEvent/MySyncEventDelegate WeaverSyncEventTests.ErrorWhenSyncEventDoesntStartWithEvent.ErrorWhenSyncEventDoesntStartWithEvent::DoCoolThingsWithExcitingPeople)"));
}

[Test]
public void ErrorWhenSyncEventUsesGenericParameter()
{
Expand Down

This file was deleted.

0 comments on commit ed40c2d

Please sign in to comment.