Closed ghost closed 8 years ago
Sweet! I've been wondering the whole time if the methods on battle that are called because of Battle Messages should be named like start()
or if it should be clearer who's supposed to call it, like handleStart()
or onStart()
.
Eventually I decided not to special-case the methods called by handleBattleMessage, but they're not necessarily supposed to be user-facing either, so ???
Yeah, I feel like some of this logic should be moved to battle.js
Nah, I think that everything to do with the protocol should stay in the protocol code. If it gets split off, it should just be to a battleMessage.js
or something.
Also I like the argument destructuring you're doing in the handlers. I didn't actually know that that worked yet...
I didn't really know you could do it either. It's what I naturally do in Elixir and it just didn't crash lol
Yeah, I think I didn't know about it because it's not included in many ES6 tutorials yet, because it's VERY iffy on real browsers. Luckily we don't have to care.
@SpenceSellers
According to the docs, there are several battle messages that can have multiple representations:
For bandwidth reasons, five of the message types -
chat
,join
,leave
,name
, andbattle
- are sometimes abbreviated toc
,j
,l
,n
, andb
respectively. All other message types are written out in full so they should be easy to understand.Four of these can be uppercase:
J
,L
,N
, andB
, which are the equivalent of their lowercase versions, but are recommended not to be displayed inline because they happen too often. For instance, the main server gets around 5 joins/leaves a second, and showing that inline with chat would make it near-impossible to chat.
So we need to handle j
, J
, and join
when someone joins the room. Is there a better way to do this other than adding more entries to battleHandlers
?
We could do something like this at pokemonClient.js:173
:
const first = normalizeCommand(pieces[1]);
normalizeCommand
would be some new function that would take in something like j
or L
and transform it to the full verb join
or leave
.
It also looks like there is a Set
in javascript? I've never seen that before, but we should use that for spectators instead of the keys of an object.
I'm actually secretly using a Set down here!
The normalize thing sounds like a good idea. The the other alternative is to pull out the affected handlers into seperate functions, and have parts of the handler object look like {'j': handleJoin, 'join': handleJoin, ...
.
I think your solution is more appealing.
Normalizing chat commands handles here: 9ef8143
Handles the following battle messages:
j
,l
,gametype
,gen
,tier
,seed
,rule