s2protocol icon indicating copy to clipboard operation
s2protocol copied to clipboard

Code Examples

Open mahousenshi opened this issue 6 years ago • 6 comments

Can you give us some examples how this library works on the documentation the programmatic way. Like

  • How to see the players actions.
  • How to see the players and see the winner.
  • How to get the chat log.
  • How to get the JSON of something above.

Can be a fake example one. But a snippet of code helps a lot when you don't know nothing about a library. I know this can change by protocol changes, but it's give us a idea how this library should work.

mahousenshi avatar Apr 15 '18 04:04 mahousenshi

Just to let you guys know, I´m working on some small examples in order to add them to the documentation. I´m not an expert with this lib but I got a few things up and running during my experiments and I think I can save someone else some trouble.

FMorsbach avatar May 10 '18 15:05 FMorsbach

Would it be helpful If I wrote up some examples on how I use it in php ? I export the data from s2protocol as json and than do all the logic I want in php.

amartin916 avatar May 10 '18 15:05 amartin916

This is a common question that comes up. The API of the library itself is not complicated but the structure of the data in the replay is fairly obtuse. I think a doc that describes the data in more detail would really help people a lot. We could also provide some small examples of consuming the data from different languages. There is Python, PHP, C# and Java users to my knowledge

jrepp avatar May 10 '18 17:05 jrepp

Threw together some quick documentation https://github.com/Blizzard/s2protocol/pull/78 I will continue to add to it as I have time but should be a good starting point.

@mahousenshi

  • How to see the players actions -- Is a little more complicated but they come from the --gameevents flag and the events you are looking for are [_event] => NNet.Game.SCmdEvent.
  • How to see the players and see the winner. -- Check the pull request under the details flag, m_playerList->m_result will give you a good starting point.
  • How to get the chat log. -- Check out the pull request in the section messageevents thats how you get chat messages.
  • How to get the JSON of something above. -- python "./s2protocol/s2_cli.py" --messageevents --ndjson "REPLAY FILE"

amartin916 avatar May 11 '18 21:05 amartin916

@jrepp I just prototyped some documentation on how to use the API inside python. What do you think? (Look on my fork please, since this is just some prototyped stuff I dont want to open an PR.) I added two .rst in the /doc: tutorial_API.rst and events.rst.

The latter could be used to describe the data a bit more. What do you guys think about the format? Is this the right way to go ?

FMorsbach avatar May 13 '18 15:05 FMorsbach

@FMorsbach Yes, this is great.

  • I love the idea of the examples in an interactive shell so people can explore. This is how I play with it as well.
  • Encouraging people to help fill in the event structures is a good approach. If I go through my email and the issues log I can fill in some additional details as well.

I'm ok with this going in in a partial state. Feel free to open a PR with the documentation changes.

Sorry for the slow reply, just getting back from vacation and trying to recover today

jrepp avatar May 14 '18 20:05 jrepp