Commit Graph

456 Commits

Author SHA1 Message Date
Guangcong Luo
87ef0cd5c4 TypeScript: export default
I'm currently pretty annoyed at TypeScript and TC39 for default exports
being a mess.

The goal here is to be able to type

    import Dex from './dex';

instead of any of

    import Dex = require('./dex');
    import {Dex} from './dex';
    import * as Dex from './dex';

This part involves a significant amount of struggle.

First, you can't automatically package up all your exports as your
default export. This leads to extremely un-DRY code, like in sim/index:

    export {
        Pokemon,
        Side,
        Battle,
        PRNG,
        Dex,
        TeamValidator,

        BattleStream,
    };

    export const Sim = {
        Pokemon,
        Side,
        Battle,
        PRNG,
        Dex,
        TeamValidator,

        BattleStream,
    };

(Both of these exports would be entirely unnecessary if you could just
automatically declare the file's exports as a default namespace.)

Second, a default export can't easily be a namespace. And TypeScript
doesn't allow types to exist in objects. Take the example from earlier:

    export const Sim = {
        Pokemon,
    };

If we were to try to use it:

    import Sim from './sim';
    let pokemon: Sim.Pokemon;

you'll get this error:

    Cannot find namespace 'Sim'. ts(2503)

You can, of course, fix this by making Sim a namespace:

    const PokemonT = Pokemon;
    type PokemonT = Pokemon;
    export namespace Sim {
        export const Pokemon = PokemonT;
        type Pokemon = PokemonT;
    }

But this quickly gets ridiculous the more classes you try to export.

You'd think there'd be a better way to do this. But I, at least,
haven't found one.
2019-05-14 20:33:33 +10:00
Konrad Borowski
f2ef0b62ab Remove TODO from flatMap implementation
Closes #5369
2019-05-13 19:58:20 +02:00
Kirk Scheibelhut
3d24166cdf toId -> toID
Closes #5479
2019-05-12 17:53:01 -07:00
Jacob McLemore
a1f18f0290 Chat-Plugins: Fix regression in weakness command (#5484) 2019-05-07 18:42:53 +09:30
Kirk Scheibelhut
3f1fa344b9 Change EBC cast to use 'as' 2019-05-06 19:48:23 -07:00
Guangcong Luo
2cd150d1da
Merge EBC and ID changes 2019-05-07 12:07:41 +09:30
Kirk Scheibelhut
a0734bde6f Redo Endless Battle Clause with a new specification (#5472) 2019-05-07 11:18:06 +09:30
Kirk Scheibelhut
49403556d1 getEffectByID (#5475) 2019-05-06 13:05:12 +09:30
Kirk Scheibelhut
10c744f733 Introduce an ID type to sim (#5468) 2019-05-04 13:13:12 +12:00
urkerab
508e58575e Other Metagames of the Month May 2019 (#5470) 2019-05-01 18:24:56 +04:00
Kirk Scheibelhut
df3d9b91ef Battle toJSON/fromJSON (#5427) 2019-04-30 14:48:27 +12:00
Kirk Scheibelhut
7e4929a39f Change protocol for '|split' message type (#5331) (#5332) 2019-04-22 09:20:47 +09:30
Marty-D
9428d274cc Gen III: Improve Truant implementation 2019-04-17 16:36:25 -04:00
Kirk Scheibelhut
6fea91ee56 Split dev-tools/globals* into sim and server (#5450) 2019-04-18 04:17:54 +09:30
Kirk Scheibelhut
4975f1902b Move simulator harness to sim/tools (#5451) 2019-04-18 04:17:07 +09:30
Marty-D
9b28525f4e Gen III: Correct Truant mechanics 2019-04-15 17:15:51 -04:00
urkerab
0133ba9bd6 Make Pokemon.moves a read only array (#5433) 2019-04-14 23:57:42 +09:30
Guangcong Luo
a33fc11d26 Refactor Actions, RandomTeamsTypes to namespace
They were previously some weird interface where their actual types
were properties. I guess whoever wrote this was unaware that TypeScript
namespaces were designed for this exact use-case.
2019-04-10 19:58:56 +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
Guangcong Luo
df4d16cc20
Update RQID documentation 2019-04-08 01:51:52 +08:00
Kirk Scheibelhut
32a457c808
Add a smoke test runner to dev-tools (#5405) 2019-04-07 08:34:43 -07:00
Guangcong Luo
e459fce4c6 Fix crit calculation 2019-04-07 16:44:20 +08:00
Guangcong Luo
4c47af28aa Refactor moveHitData
This is actually three refactors:

- swap around thing:slot for slot:thing in MoveHitData
- add Pokemon#getSlot
- remove the ActiveMove class; it's back to being an interface
2019-04-06 19:10:45 +08:00
Kirk Scheibelhut
0efd71dfef Move Data.ActiveMove methods to Pokemon (#5416)
See #5415 for context - having these methods is unsafe and leads
to crashes because not all ActiveMoves are created through the
Data.ActiveMove constructor. Instead of Pokemon, these could
alternatively be static methods on ActiveMove (or the ActiveMove
class could be completely abolished and reverted back to an
interface), but #5415 will deal with ActiveMove long term, this just
fixes the crashes.
2019-04-06 13:14:50 +08:00
Kirk Scheibelhut
812e4efb57 Document |-sethp| 2019-04-05 20:09:44 -07:00
MacChaeger
fe1613797f Fix Z Moves breaking Protect (#5413) 2019-04-06 01:06:22 +08:00
Kirk Scheibelhut
3bdd4b95c6
Make RandomPlayerAI capable of playing VGC (#5410) 2019-04-05 08:21:57 -07:00
MacChaeger
d3f1161b62 Fix Weakness Policy and Clangorous Soulblaze in doubles (#5389) 2019-04-04 18:51:27 +08:00
Ivo Julca
121c4a3b24 Sim: Abort parsing choices if any is invalid
Fixes #5399
2019-04-03 02:08:59 -05: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
Ivo Julca
b369b0f680 Sim: Fix crash in Team Preview
Regression from the deletion of parseChoice() @698fb2a
2019-03-30 19:39:24 -05:00
Kirk Scheibelhut
1c147644e9 Make sure BattleStream only calls _destroy once (#5382) 2019-03-31 00:29:20 +08:00
Slayer95
694cd47e7b Fix target resolution (#5363) 2019-03-30 22:34:44 +08:00
Slayer95
628f32e8fb Stricter type definitions for dex data (#5375)
BattleStatuses switched to PureEffectData
2019-03-30 22:31:04 +08:00
Kirk Scheibelhut
b7d9d6c611 Handle targetting adjacentFoe and adjacentAllyOrSelf in RandomPlayerAI (#5381) 2019-03-30 14:00:25 +08:00
Konrad Borowski
347e8a5181 Replace for-in pokemon.moveSlots iteration with for-of 2019-03-29 17:08:23 +01:00
MacChaeger
a729cb577f Fix duration of slot conditions (#5372) 2019-03-29 23:03:10 +08:00
MacChaeger
2edd8a354f Fix Leech Seed vs. Magic Guard (#5374) 2019-03-29 23:01:50 +08:00
Marty-D
1f8eeae108 Revert "Battle#residualEvent: Check fainted status earlier"
This reverts commit d499a019f0.
2019-03-28 14:55:13 -04:00
Konrad Borowski
d71a5c90a4 Temporarily mark flatMap as non-enumerable
This should deal with the issues with code using for-in
for arrays. This is a hack and should be removed.
2019-03-28 19:43:07 +01:00
Alexander B
57701a5f04 Refactor OMs to use "m" property of Pokemon (#4957) 2019-03-28 22:28:35 +08:00
Ivo Julca
ac4b94876b Sim: Refactor to use Battle#getAllPokemon() and Battle#getAllActive() 2019-03-26 23:18:19 -05:00
Ivo Julca
0ae0405f46 Sim: Implement Battle#getAllPokemon() and Battle#getAllActive() 2019-03-26 23:18:19 -05:00
Ivo Julca
2747ce61fb Sim: Split Pokemon#nearby(Allies|Foes) feature out of Pokemon#(allies|foes) 2019-03-26 23:18:19 -05:00
MacChaeger
9a7ce3dedf Put side conditions on p1 and p2 in multi battles (#5341) 2019-03-27 11:00:36 +08:00
Slayer95
d499a019f0
Battle#residualEvent: Check fainted status earlier 2019-03-26 18:15:18 -05:00
MacChaeger
860900ac57 Fix AfterDamage event running on secondary effects (#5350) 2019-03-26 15:29:46 +09:00
Kirk Scheibelhut
134fb8b852 Return from nextTurn if Endless Battle Clause is activated (#5347) 2019-03-26 03:07:09 +09:00