Commit Graph

48 Commits

Author SHA1 Message Date
CheeseMuffin
fbb916ff5f Add Chat to TypeScript globals (#4287) 2018-02-26 15:15:44 +09:00
Guangcong Luo
4c0699abc6 Implement inputLog
A battle's inputLog is now stored separately from the output log. It's
not an exact log of inputs, but rather just a collection of the inputs
that resulted in the battle: a default choice expands to the choice
that was actually used, and the starting seed is logged whether or not
it was explicitly passed into the battle stream.

Fixes #4348

Fixes #3201
2018-01-28 21:23:06 -06:00
Guangcong Luo
1531b662c6 Refactor battle stream system
This contains a lot of minor refactors, but the main thing that's going
on here is that battle stream writes have been streamlined to be a lot
easier for others to use.

We even support:

    ./pokemon-showdown simulate-battle

which provides a stdio interface for anyone using any programming
language to simulate a battle.
2018-01-28 21:06:49 -06:00
Guangcong Luo
9c037b17fe Refactor Battle constructor
`Sim.construct` no longer exists. Battles are now constructed directly
with `new Battle()`. Parameters other than formatid are now passed as
`options`.
2018-01-28 21:06:49 -06:00
Guangcong Luo
e8163824ff Remove validate-conditionals eslint rule
As far as I can tell, `curly, multi-line, consistent` does everything I
want; there's no reason to keep around a validate-conditionals rule.

Which is probably good, since eslint is deprecating the API for this,
anyway. The nice thing about not relying on deprecated APIs is that now
you can lint PS with `eslint` rather than needing to memorize
command-line switches.
2018-01-19 13:25:10 -06:00
Guangcong Luo
ab1f995daa Rewrite Process Manager
Process Manager is now lib/process-manager.js

It's been entirely rewritten to reflect what I think a process manager
API should look like.

In particular, there are now two Process Managers, QueryProcessManager
and StreamProcessManager.

Pass QueryProcessManager a pure-ish query function (sync or async) that
takes a JSON value and returns a JSON value, and PM.query() will
execute that function in a subprocess, and return a Promise for its
return value.

StreamProcessManager is the same idea: Pass it a function to create an
ObjectReadWriteStream, and PM.createStream() will create a stream in a
subprocess and return a stream connected to it.
2018-01-18 03:34:16 -06:00
Guangcong Luo
df4aeebcd5 Use new Streams for FS streams 2018-01-13 03:59:09 -06:00
CheeseMuffin
636b8d79ea Finish typescripting punishments.js (#4284) 2017-12-27 15:10:45 -06:00
Guangcong Luo
27070c589f Fix TypeScripting for users.js 2017-12-26 12:40:45 -06:00
CheeseMuffin
f27f0e21dd Typescript users.js (#4279) 2017-12-26 00:24:38 -06:00
Guangcong Luo
5094631fcf Implement Roomlog library
Rooms now have their logging abstracted into their own file, which also
allows the rest of rooms.js to be simplified by a decent margin.

This is in preparation for using Redis as a backing for scrollback log
storage, which will give us a lot more RAM to work with.

My newest newest plan is actually to locally cache room scrollback, and
only read battle logs from Redis. This will make chatroom-joining
faster.
2017-12-16 15:40:45 -06:00
Guangcong Luo
7e02b57016 Refactor Matchmaker to subclass Ladder
As expected, this resulted in zero API changes. (Aside from a minor
test change.)
2017-12-09 15:45:10 -06:00
Guangcong Luo
799a6a1e44 Improve Matchmaker API
Ladder is now a subclass of Matchmaker, and all the APIs previously
attached to Matchmaker are now directly available in Ladder.

In addition, all functions that take a formatid are now of the form
`Ladders(formatid).function(other arguments)`

TODO: Reverse polarity; it makes more sense for Matchmaker to be
a subclass of Ladder. Fortunately, this wouldn't involve API changes.
2017-12-09 15:04:29 -06:00
Guangcong Luo
56190af620 Fix up TypeScript errors
Also suppress TypeScript validation of various files we don't want
validated right now.
2017-11-08 01:23:04 -06:00
Guangcong Luo
844f461dbb TypeScript rooms.js 2017-11-06 21:56:33 -06:00
Guangcong Luo
7466edf24e Remove unused globals.js file 2017-11-06 21:19:54 -06:00
Guangcong Luo
2d9fc18280 TypeScript sim/team-validator.js 2017-11-02 00:15:04 -05:00
Guangcong Luo
0e728281e6 Move team-validator to sim/team-validator 2017-11-01 05:22:37 -05:00
Guangcong Luo
a47077bbe9 Split TeamValidator and TeamValidatorAsync
I'm not really sold on "TeamValidatorAsync" as a class name or file
name, so I'm open to suggestions.

The long-term plan is to put TeamValidator in sim/ but this is in three
commits because I really want the right file to retain blame history.
2017-10-31 15:49:09 -05:00
Quinton Lee
a0b8228592 TypeScript: Improve Sim typing (#4069)
Also improves intellisense for Visual Studio and Visual Studio Code.
2017-10-20 07:53:26 -05:00
Guangcong Luo
88159c41bc Refactor BattleRoom -> GameRoom
BattleRoom is now GameRoom, a slightly more abstract room type capable
of holding any of a number of possible roomgames. Currently, battles
are the only such roomgame, but any future roomgame could possibly use
it.

Differences between ChatRoom and GameRoom:

- GameRooms start at the left, ChatRooms start at the right
- GameRooms have chat on the right, and a game area on the left, with a
  view area at the top left and a controls area at the bottom left
- GameRooms retain all their logs, ChatRooms only retain the latest 100
  lines
- GameRooms expire after 40 minutes of inactivity or 10 minutes of zero
  online users (configurable in the future)
- GameRooms are guaranteed to have an associated game, while ChatRooms
  may or may not
2017-10-18 05:41:03 -05:00
Ben Davies
a5bc1e0045 Typescript: ladders-matchmaker.js (#3942) 2017-09-01 19:18:59 -04:00
Ben Davies
67b25950de Typescript: Declare all globals, refactor monitor.js (#3748) 2017-07-13 12:20:03 +09:00
Ben Davies
74131dbf58 Typescript: crashlogger.js (#3605)
Depended on by numerous other modules to be moved over to Typescript
before they can.
2017-06-11 11:16:21 -05:00
Guangcong Luo
149ca3759c Add classes for data
Having classes for data will make it better for documenting and make
for overall nicer code that's easier to statically analyze.
2017-05-17 04:10:01 -05:00
Guangcong Luo
e34c77930a Start creating classes for getEffect data
Currently, getEffect/getTemplate/getMove/etc return bare objects.
Refactoring their returns into classes will allow TypeScript to type
check them.
2017-05-09 16:00:11 -05:00
Ben Davies
8de4bdfecb Sockets: refactor to use maps (#3474) 2017-04-23 16:39:38 -07:00
Ben Davies
5031794f97 Sockets: fix unit tests (#3281)
* Sockets: fix Sockets.killWorker not disconnecting connections

* Sockets: fix unit tests

- Fix crash when constructing mock sockets in certain cases
- Properly prevent workers from writing to stdout
- Fix race conditions in workers-related tests that were causing false
  positives

* Tests: mock workers now more closely imitate sockets' workers

This helps catch cases where messages are being sent in the wrong order
to the workers, e.g. messages sent to sockets that no longer exist.
2017-02-24 05:38:37 -06:00
Ben Davies
5c4834f3fd Tests: tweak user mocks, add Connection tests, fix Trivia tests (#2682)
Worker mocks now have proper ids. Trivia tests now dispose of user objects
rather than letting them stay in memory for the rest of the tests.
2016-08-09 04:02:27 -05:00
Guangcong Luo
095652c9ee Exit process when child process exits
If a child process dies in a way that it can't recover from, the main
process now exits, to prevent loops of 'Error: channel closed'
thousands of times a second, filling up the error log and making it
hard to track down the real error.
2016-02-03 22:40:51 -06:00
Konrad Borowski
81f602b8d8 Always use trailing comma for multiline objects 2016-01-01 00:20:07 +01:00
Konrad Borowski
79a5b23f25 Modify data and mods files to follow style rules 2016-01-01 00:18:00 +01:00
Konrad Borowski
156e193bed Only enable certain ES6 features during ESLint test
Currently, only those features are allowed: let/const, classes, and
octal literals. More can be added when needed, as long main Showdown
server has a supporting Node.js's version.

This also accidentally fixes a bug which caused data files to not
be checked for `let`/`const` keyword existence, which would cause
a problem in a web browser.
2015-12-10 23:07:32 +01:00
Guangcong Luo
332a65f9c0 Convert some Users tables to ES6 Maps
Specifically, Users.users, Users.connections, and Users.pastUsers
are now ES6 Maps. In theory, this should be a minor performance
upgrade, but we still need to profile to make sure.
2015-12-10 11:52:26 -05:00
Ivo Julca
648cd538ff Disallow var variable declarations except in data/ 2015-12-03 19:46:11 -05:00
Ivo Julca
44adce3f78 Turn on strict mode globally for real 2015-11-08 15:43:47 -05:00
Ivo Julca
8619ba2022 Turn on strict mode globally for real 2015-11-08 15:38:15 -05:00
Ivo Julca
793b4977b9 Eslint: loosen new-cap rule
Some of our globals are functions -yet not constructors.
2015-11-08 15:18:21 -05:00
Guangcong Luo
ded9f1cd5d Fix duplicate cases in random set generators 2015-11-07 23:12:19 -06: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
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
Ivo Julca
e9b09d1096 Test: fix suite in Node.js prior to 2.2.0 2015-09-11 01:04:52 -05:00
Ivo Julca
85379ff12e Test: don't listen for connections 2015-09-11 00:38:49 -05:00
Ivo Julca
cd36fbfde2 Gulpfile: add more JSCS rules
- Disallow spaces between function names and round brackets.
- Disallow spaces inside array/object literal brackets.
- Disallow spaces before semicolons.
- Disallow yoda conditions for equality.
2015-07-28 19:38:53 -05:00
Ivo Julca
b441375b5a Test: move utility functions to dev-tools/ 2015-07-07 03:08:18 -05:00
Ivo Julca
8329e6f532 JSCS: fix crash in validateConditionals rule for empty blocks 2015-06-18 19:35:41 -05:00
Ivo Julca
c08aba185b Implement JSCS rule to enforce switch cases not to be indented 2015-06-12 03:41:04 -05:00
Ivo Julca
b740197244 Implement JSCS rule to enforce PS conditionals' style 2015-06-12 03:36:36 -05:00