Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

schema-codegen: generate classes for interfaces on C#/Unity #68

Merged
merged 3 commits into from
Apr 20, 2020

Conversation

endel
Copy link
Member

@endel endel commented Apr 19, 2020

With Colyseus 0.13 coming out, and the new type-safe Send()/OnMessage() feature, it would be nice to avoid manually creating the same structures on both server-side and client-side in order for them to communicate.

The problem with generating classes for EVERY interface is that the schema-codegen may generate code for interfaces that aren't really related to message passing.

The ideal example of this feature is this:

interface SomeMessageType {
  bar: number;
}

//...

this.onMessage("foo", (client, message: SomeMessageType) => {
  // received `SomeMessageType`
});

And in the client-side (C#) you can use the generated class to send a message:

room.Send("foo", new SomeMessageType { bar = 10 })

@endel endel merged commit fef650b into master Apr 20, 2020
@endel endel deleted the codegen-interfaces branch April 20, 2020 17:48
@endel
Copy link
Member Author

endel commented Apr 20, 2020

Interfaces are going to be generated as classes in C#, only if the interface has Message on its name. (e.g. MyMessageType, SomeMessage, MessageSomething)

This may not be ideal, but at least it will work for now. If this causes problems later we can re-visit and have a different solution.

@mounop
Copy link

mounop commented Apr 21, 2020

Just tried this feature and it works perfecly !!
Thanks for that :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants