Commit Graph

32 Commits

Author SHA1 Message Date
Mia
7811795344
Handle new TypeScript version (#8449)
Co-authored-by: Guangcong Luo <guangcongluo@gmail.com>
2021-08-30 20:11:44 -07:00
Guangcong Luo
13189fdb02
Update Dex API (#8181)
This is the change that renames:

- `Dex.getMove` -> `Dex.moves.get`
- `Dex.getAbility` -> `Dex.abilities.get`
- `Dex.getItem` -> `Dex.items.get`
- `Dex.getSpecies` -> `Dex.species.get`
- `Dex.getEffect` -> `Dex.conditions.get`
- `Dex.getNature` -> `Dex.natures.get`
- `Dex.getType` -> `Dex.types.get`
- `Dex.getFormat` -> `Dex.formats.get`

In addition, some other APIs have been updated:

- `getByID` methods have also been added to every other table.
- `Dex.moves.all()` now gets an array of all moves
  - Plus equivalent methods for `abilities`, `items`, `species`, `formats`, `natures`, `types`
  - Note: there's no `Dex.conditions.all()`
- new API: `Dex.stats` for naming/iterating stats
- `Dex.getEffectByID` -> `Dex.conditions.getByID`
- `Dex.getType` -> `Dex.types.get`
- `Dex.data.Formats` -> `Dex.data.Rulesets`
- `Dex.formats` -> now an array `Dex.formats.all()`
- `Dex.getRuleTable` -> `Dex.formats.getRuleTable`
- `Dex.validateFormat` -> `Dex.formats.validate`

Team functions have been split off into a new `sim/teams` package:

- `Dex.packTeam` -> `Teams.pack`
- `Dex.fastUnpackTeam` -> `Teams.unpack`
- `Dex.generateTeam` -> `Teams.generate`
- `Dex.stringifyTeam` -> `Teams.export`

`Teams.export` has also been rewritten to better match how it works in client.

This implements #8178
2021-04-08 03:00:37 -07:00
Guangcong Luo
86df524adc Support forfeiting in free-for-all battles
I honestly don't understand HOW it works, but it definitely works.
2021-04-01 04:44:16 -07:00
Guangcong Luo
3835c3cfeb Add a comment warning about eval inputlogs 2021-02-02 15:27:14 -08:00
Guangcong Luo
782f316dd9
Merge BattleStream and RoomBattleStream commands (#7988)
RoomBattleStream originally overrode `_writeLine` in #5428 because
`>eval` had a dependency on `Chat.stringify`, and we were trying to
separate sim and server.

`Chat.stringify` is now `Utils.visualize`, so there's no more reason
for the separation. In addition, the separation is actively bad,
because it makes it impossible to import certain inputlogs outside
of the simulator.
2021-02-02 15:03:03 -08:00
Guangcong Luo
796be8da60 Implement /ebat reseed
Fixes #7963
2021-02-02 13:45:34 -08:00
Mia
76c10841ea
Lib: Add an index file for all exports (#7972) 2021-01-31 18:00:19 -08:00
Guangcong Luo
8b68cdd736 Fix Streams bug
It turns out 001f98b4f2 was wrong.

When urkerab asked why it `peek` wasn't awaited:

e91c4c5260 (commitcomment-41364837)

The answer was because clearing the buffer after peeking needed to
happen synchronous: if the buffer is written to after peeking but
before the buffer is cleared, that write is lost forever.

This just goes to show, if you do something subtle enough to require
type assertions, you should probably add a comment about what's going
on.

Fixes #7605

This also removes `BattleStream#start()` which is completely useless
API complication. A better implementation would properly forward
crashes between streams (maybe `pipeTo` should do this) but as it
stands, it's not doing anything.
2020-11-01 02:06:24 +00:00
Guangcong Luo
958d22fc7f Improve error propagation in debuggers
Running `./pokemon-showdown simulate-battle` no longer catches/rethrows
errors. This should make debugging with something like VS Code's
built-in debugger much easier.
2020-10-19 18:09:22 +01:00
Guangcong Luo
9d87616176
Add more style linting rules (#7537)
* Lint arrow-body-style

* Lint prefer-object-spread

Object spread is faster _and_ more readable.

This also fixes a few unnecessary object clones.

* Enable no-parameter-properties

This isn't currently used, but this makes clear that it shouldn't be.

* Refactor more Promises to async/await

* Remove unnecessary code from getDataMoveHTML etc

* Lint prefer-string-starts-ends-with

* Stop using no-undef

According to the typescript-eslint FAQ, this is redundant with
TypeScript, and they're not wrong. This will save us from needing to
specify globals in two different places which will be nice.
2020-10-19 02:42:28 -07:00
Guangcong Luo
2bcea34447 Support ./pokemon-showdown simulate-battle -S
simulate-battle now has a new option: --spectate.

As a recap:

-D --debug: simulate in debug mode

-R --replay: output only the omniscient (debug) replay, rather than the
  full stream

-S --spectate: output only the spectator replay, rather than the full
  stream
2020-09-29 15:28:07 -07:00
Guangcong Luo
18948c8c2c Refactor ObjectReadStreams to use for-await
Regular ReadStreams still can't; I now believe they shouldn't have a
"default" read method, and you should explicitly choose whether you
want to read "by chunks as they become available", "by chunks of a
specific line" or "by a delimiter".

So you would specifically use `stream.byLine()` or
`stream.byChunk([size])`, which would return an
`ObjectReadStream<string>`.

Inspired by #7195
2020-08-15 15:11:53 -07:00
Guangcong Luo
dffd9dbff8 Fix stream destroying
`SubprocessStream` wasn't getting properly destroyed.
2020-06-18 21:47:03 -07:00
Guangcong Luo
1e5b5ab465 Update Streams API with pushEnd/writeEnd
Previously, ending a read stream was `stream.push(null)`, and ending a
write stream was `stream.end()`. This was often confusing, and so now,
these are consistently `stream.pushEnd()` and `stream.writeEnd()`.

This refactor already found a bug in which `stream.end()` was used
where `stream.push(null)` should have been.

Also in this refactor: By default, `pushError` ends the stream. You can
pass `true` as the second parameter if the error is recoverable (the
stream shouldn't end).
2020-06-10 16:07:24 -07:00
Mia
6839a1f4db
Add a library for utility functions (#6817) 2020-06-09 22:06:43 -07:00
Guangcong Luo
b21c9047e2
Migrate to typescript-eslint (#6342) 2020-03-05 08:33:06 -08:00
Guangcong Luo
2c95b17e98 Improve debugging support
We have a new command:

`./pokemon-showdown simulate-battle --replay`

which will extract the omniscient log from an input log.

Remember: debugging is as easy as running `simulate-battle` and pasting
an input log. `--replay` will just make the output easier to read.
2019-12-01 19:38:51 +13:00
Kirk Scheibelhut
7e4929a39f Change protocol for '|split' message type (#5331) (#5332) 2019-04-22 09:20:47 +09:30
Kirk Scheibelhut
f9164d4d59 Pull out non-sim code into RoomBattleStream (#5428) 2019-04-09 17:58:07 +08:00
Kirk Scheibelhut
b2777f9bf6 Remove |callback| in favor of |error| (#5418) 2019-04-09 03:33:32 +08:00
Kirk Scheibelhut
0f8241045b Test 'noCancel' behavior to prevent #5344 (#5348)
Renames currentRequest -> requestState to avoid confusion.
2019-04-03 11:58:53 +08:00
Kirk Scheibelhut
915dd3f4a0 Stop returning default from RandomPlayerAI (#5394)
`default` papers over AI logic errors. This change fixes those
errors instead:

  - handle maybeDisabled/maybeTrapped properly
  - use 0 PP and ally-less 'adjacentAlly' moves if necessary.
2019-04-03 11:53:02 +08:00
Kirk Scheibelhut
1c147644e9 Make sure BattleStream only calls _destroy once (#5382) 2019-03-31 00:29:20 +08:00
Kirk Scheibelhut
e61965eaf5 Pull out RandomPlayerAI from example and enhance 2019-03-22 02:42:05 -05:00
Kirk Scheibelhut
2b1c278c42 Fix 'floating' promises and enable lint errors going forward (#5297) 2019-03-22 02:21:17 +09:00
Kirk Scheibelhut
cab87325e9 Push 'update' to p3 & p4 in BattleStream (#5317) 2019-03-19 09:40:31 +09:00
MacChaeger
6ac8266696 Support 4 player battles (#5266) 2019-03-18 13:37:27 +09:00
Guangcong Luo
efa0af0ef1 Propagate errors through streams 2019-03-17 07:48:02 +09:00
Guangcong Luo
9073a5a8bf Improve Streams typing
When I originally wrote the Streams library, TypeScript-in-JS didn't
support generics. But now the library can have significantly nicer
typing, and so it now does.
2019-03-16 17:12:21 +09:00
Kirk Scheibelhut
9e7ba68fc4 Properly terminate BattleStream (#5283)
Fixes regression caused by #5210
2019-03-09 10:16:41 -06:00
Kirk Scheibelhut
91993df916 Continue cleaning up sim/ after .ts refactor (#5267) 2019-03-08 07:29:04 -06:00
Kirk Scheibelhut
b09fd63377 Refactor sim/ to be native Typescript (#5210) 2019-02-26 11:03:30 -06:00