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`
PS's choice system has now been majorly rewritten!
Battle#parseChoice has been eliminated, and Battle#choose is now a
very lightweight wrapper around the BattleSide#choose* functions, which
now handle validation.
Partial decisions have been mostly removed. You can manually construct
decisions partially with the side.choose* functions, but there's no
other support for them. Partial undo has been removed completely.
Choice tracking has been renamed from side.choiceData to side.choice.
side.choices has been removed and is now autogenerated from side.choice
when needed.
side.choiceData.decisions has been renamed side.choice.actions. In the
future, "decision" is a deprecated term and should be called "action"
wherever it shows up.
side.choiceData.waiting and side.getDecisionsFinished() have been
merged into side.isChoiceDone().
Other values in side.choiceData have either been rendered unnecessary
or renamed to something clearer.
The "skip" and "pass" choices have been merged together. Passes can
still be filled in automatically (so you can just use `/move 1` in
doubles when you have only one Pokémon left).
This enables battles in tests to reset their RNG to what it originally
was when they were created. A number of tests do this already by
breaking encapsulating and modifying the prng variable directly. This
should fix that.
We also remove createBattleWithPRNG and min/maxSeed properties.
Firstly, the tests that were still using the maxSeed property were
setting it to Battle.seed which has no effect since the PRNG class does
not look at this property any more - so these were no-ops.
After removing this property from tests, maxRollSeed was never used, so
I removed it and renamed minRollSeed to DEFAULT_ROLL_SEED (since it's
constant).
The places that were still using minRollSeed also were no-ops or were
using createBattleWithPRNG. Since every single instance was actually
just using the same code, I removed createBattleWithPRNG and made
createBattle default to giving you a seed with DEFAULT_ROLL_SEED and
removed the minRollSeed property too.
This makes tests much simpler and reduces the usage surface of
TestTools; now, you must define your *own* seed if you're making a PRNG
for a test, or you use one that TestTools gives you; you may not use a
public property that TestTools gives you.
We also remove the code that removes a listener in the Battle Engine.
This was rendered obsolete by f6a7c4b (see more info [in the discussion
on github][disc]
[disc]:
https://github.com/Zarel/Pokemon-Showdown/pull/3272#discussion_r102414795
This removes the 'deterministic test' tools by preventing action at a
distance (namely, preventing the modification of the `init` method in
`Battle` during tests). This action at a distance is incredibly
confusing.
All this action at a distance did was discard any parameters that were
passed to `Battle` that weren't the first three (which was probably a
mistake by the original author) and also hard code `this.seed` and
`this.startingSeed` in `Battle`.
This functionality has now been moved to the `PRNG` class, so instead
users should pass a `PRNG` to `Battle` as the 5th constructor argument.
Users can also pass one as the third argument to `common.createBattle`
or use `common.createBattleWithPRNG` with the PRNG as the first
argument.
The PRNG is just an encapsulation of the pseudo-random algorithm in a
class. It is stateful, so make sure to take a `clone()` of the PRNG if
you want to re-use it.
This makes gen 7 the default mod, updates the tests to match, and fixes
the corresponding build error.
Note that this only changes the default Tools mod, the default Formats
mod is now gen6. gen7 must be specified by name in a format, for that
format to be a gen 7 format.
Battle is now an ES6 class... mostly... it's complicated.
Battle's inheritance system has always been a mess. I tried to redo it
in a sensible way but it caused nondeterministic test failures. Not
even kidding; different things would fail each time I ran tests, even
without code changes. I'll investigate closer later, but this refactor
makes it use ES6 classes with only a small amount of hacking, which is
good enough. It is, at the very least, simpler than the previous mess.
BattleEngine.Battle.construct has been renamed BattleEngine.construct.
Tools will be renamed to Dex soon, which is why the code inside Tools
is calling itself "Dex" now, but right now we're just refactoring its
internal code and not officially renaming it yet.
In the meantime, Tools is now an ES6 Class.
A long-standing bug in learnset loading order (the one
test/chat-plugins/datasearch.js tests for) has finally been fixed, so
Tools.includeMods() is no longer necessary to accurately access modded
data.
Tools.mod has been split into Tools.mod(modid) and
Tools.format(format). The issue of Tools.mod being ambiguous about
whether it's passed a mod or a format hasn't been a _bug_ for a while,
but this is still more readable.
Other renames include:
Tools#isLoaded -> Tools#dataLoaded
Tools.includeMods() -> Tools.includeModData()
Tools.preloadMods() -> Tools.includeMods()
Tools.preloadedMods -> Tools.modsLoaded
Tools.moddedTools -> Tools.dexes
Do not just rename your calls of Tools.includeMods() to
Tools.includeModData(). With the learnset loading bug fixed, there's
no reason to use it unless you need direct access to
Tools.dexes[...].data for some reason (you don't, just use
Tools.mod(...).data)