Commit Graph

27 Commits

Author SHA1 Message Date
Guangcong Luo
edf5f61eff Support "both players lose"
Now, passing a p1score of -1 to ladders.js means that both players
lose.
2017-07-27 17:08:28 -04:00
Guangcong Luo
6dd58b40d3 Refactor simulator into new sim/ directory
This is a surprisingly minor refactor considering how many files it
touches, but most of this is only renames.

In terms of file renames:
- `tools.js` is now `sim/dex.js`
- `battle-engine.js` is now `sim/index.js` and its three classes are
  in `sim/battle.js`, `sim/side.js`, and `sim/pokemon.js`
- `prng.js` is now `sim/prng.js`

In terms of variable renames:
- `Tools` is now `Dex`
- `BattleEngine` is now `Sim`
- `BattleEngine.Battle` is now `Sim.Battle`
- `BattleEngine.BattleSide` is now `Sim.Side`
- `BattleEngine.BattlePokemon` is now `Sim.Pokemon`
2017-05-05 16:48:38 -05:00
Guangcong Luo
d6f5404e7e Rename CommandParser to Chat
We had a lot of discussion in Dev and a somewhat-close poll, but in
the end "Chat" was a better name than "Messages", and also has the
advantage of being shorter (which is nice for Chat.html and
Chat.plural which should be short).
2016-09-30 18:31:15 -07:00
Guangcong Luo
da1b318707 Move text processing from Tools to CommandParser
The following functions have been renamed:

- Tools.html to CommandParser.html
- Tools.plural to CommandParser.plural
- Tools.escapeHTML to CommandParser.escapeHTML
- Tools.toDurationString to CommandParser.toDurationString
- Tools.toTimeStamp to CommandParser.toTimestamp
  (notice the lowercase 's')

This is in preparation for a rename of Tools to Dex (by removing the
non-dex-related functions) and a rename of CommandParser to either
Messages or Chat.
2016-09-30 18:04:13 -07:00
Guangcong Luo
54b672fe4e Start refactoring for template strings
This commit introduces Tools.html and Tools.plural, helper functions
for string construction.

Tools.html is a template tag function that escapes HTML inside the
template string.

Tools.plural is a helper function that takes a passed Number, Array,
Set, or Map and returns a string representing whether or not it's
plural.

It also starts doing some refactors of some files to make it clear how
I expect code style for template strings to look.

Previously, we used ' for IDs, " for English text, and ' for code.

We should now be using ' for IDs, ` for English text, and ` for code.
2016-08-28 04:35:43 -05:00
Guangcong Luo
29721da081 Fix crash in getRating 2016-08-19 23:42:55 -04:00
Bär Halberkamp
8da2cf61fe Convert ladders-remote to the ES6 class syntax 2016-03-14 11:57:08 +01:00
Guangcong Luo
3c888c6517 Fix crash in /rank 2016-03-08 23:09:18 -05:00
Bär Halberkamp
5b584cdc35 Implement /rank for other servers 2016-03-02 06:03:33 +01:00
Guangcong Luo
b665660608 Refactor for more ES6 features
Now that nodejs/node#3072 is mostly fixed, we can finally start using
Node 4+ features.

This refactor:

- uses arrow functions where appropriate

  Note that arrow functions still aren't used in Mocha, where `this`
  is sometimes meaningful.

  This also removes the need for .bind() nearly everywhere, as well
  as the `self = this` trick.

- refactors Validator and Connection into ES6 classes

- no longer uses Array#forEach for iterating arrays

  We strongly prefer for (let i = 0; i < arr.length; i++) because of
  performance reasons. Most forEaches have been replaced with for..of,
  though, which is 5x slower than the long-form loop but 2x faster
  than forEach, which is good enough outside of most inner loops.

  The only exception is tournaments, which is due for a more invasive
  refactor soon anyway.
2016-02-10 17:40:21 -06:00
Guangcong Luo
9d245a1652 Revert "Revert "Remove explicit decimal radix from parseInt""
This reverts commit 55df20be60.
2016-01-07 18:45:50 -06:00
Slayer95
55df20be60 Revert "Remove explicit decimal radix from parseInt" 2016-01-05 12:56:32 -05:00
Bär Halberkamp
c254c663d3 Remove explicit decimal radix from parseInt 2016-01-05 17:35:12 +01:00
Konrad Borowski
81f602b8d8 Always use trailing comma for multiline objects 2016-01-01 00:20:07 +01:00
Guangcong Luo
66381f1317 Improve commenting 2015-12-02 22:14:23 -06:00
Guangcong Luo
d8f53897a4 Ladder refactor
For the server, the only relevant thing was that elo is now stored in
.elo instead of .acre
2015-11-25 17:30:53 -05:00
Ivo Julca
a5f4c85d56 Fix ladders
- TDZ violation in remote ladders.
- Lack of `get` method in local ladders.
2015-11-08 15:52:00 -05:00
Ivo Julca
8619ba2022 Turn on strict mode globally for real 2015-11-08 15:38:15 -05:00
Ivo Julca
7dddb66253 Migrate build system to ESLint
JSHint's ES6 support is shaky, and its development has stalled as of late.
Since ESLint can do by itself both JSHint and JSCS' jobs, this commit replaces them.
Gulp and its related dependencies are also hereby removed.
2015-11-07 21:36:49 -05:00
Ivo Julca
90973d5c0c Style fixes
- Cut down excessive spacing
- Add braces to missing conditionals
2015-11-07 17:08:09 -05:00
Juanma Serrano
c4ac8d6e2f Use strict mode and let and const instead of var
This commit also fixes some duplicated variable declarations.
2015-11-06 21:56:52 -05:00
Guangcong Luo
674a55a405 Fix double logging in new ladder code 2015-09-22 04:58:46 -05:00
Ivo Julca
2946adeaea Make sure to send valid JSON in query responses 2015-09-20 19:42:22 -05:00
Guangcong Luo
2da21aff25 Minor refactor to ladders-remote 2015-09-19 15:26:22 -05:00
Guangcong Luo
68b3754e7d Support new ladder protcol
See 0b3b09e987

This commit doesn't introduce the local ladder yet, it's just some
final changes to support the new protocol.
2015-09-19 15:21:48 -05:00
Ivo Julca
d267b3ae64 Promise rejection reasons should be errors 2015-08-21 10:42:39 -05:00
Guangcong Luo
3c8bf6700a Refactor ladder code
Ladder code is now its own file, ladders-remote.js, in preparation
for a separate file ladders.js to be used for local ladder
support.
2015-08-17 20:24:37 -05:00