pkmn / ps

Modular Pokémon Showdown
MIT License
107 stars 15 forks source link

provide event based battle handling for /client #11

Closed castdrian closed 3 years ago

castdrian commented 3 years ago

Is your feature request related to a problem? Please describe: Sort of yes. Working with streams is to be blunt a real pain in the ass. It's hard to parse out whatever is going on and to figure out what response it wants.

A clear and concise description of what the problem is. Accessibility. Working with streams just really is very displeasing. Describe the solution you'd like:

An eventemitter based way of handling battles with structures being emitted that allow manipulation of the battle.

client.on('request', data => {
  if (data.request === "format") data.send(format);
  if (data.request === "players") data.send(players);
  if (data.request === "move") data.send(move);
}

client.on('log', data => {
  console.log(data.spectator);
  console.log(data.p1);
  console.log(data.p2);
}

A clear and concise description of what you want to happen.

A user friendly way of simulating a showdown battle and receiving the battle log irt.

Describe alternatives you've considered: A clear and concise description of any alternative solutions or features you've considered.

Open to anything that provides a simple interface to simulate a battle, eventemitters where the first thing that came to mind

scheibo commented 3 years ago

Hi Adrian - I could be misunderstanding, but streams and events are relatively interchangeable (though streams actually tend to be more conducive to writing code with Promises). Regardless, I would suggest that the @pkmn/client package actually does already contain logic for transforming the Pokémon Showdown BattleStream into something 'evented': see https://github.com/pkmn/ps/blob/master/integration/src/ui/index.ts#L191-L216 for example, where theres a Handler that process as |turn| or |teampreview| event etc.

The example you provide above of the kind of 'event's you want do not mesh with the @pkmn/client architecture/purpose - you are meant to feed the client the BattleStream from @pkmn/sim (or feed it the data that comes in over a websocket) and then query the Battle after it updates based on this stream (optionally you can also hook in your own handlers/read the past context etc).

It is infeasible and undesirable to completely rewrite @pkmn/client to provide the API you suggest above, but if you provide some more pointers to actual places in your codebase where you're having trouble using @pkmn/client ergonomically perhaps I can see if you are actually using it in the intended way?

scheibo commented 3 years ago

Closing due to no response from the reporter. Please reopen or reach out on Discord with more specific information :)