mirror of
https://github.com/smogon/pokemon-showdown.git
synced 2026-03-21 17:25:10 -05:00
Preload data when using Dex.mod (#10641)
Some checks are pending
Node.js CI / build (16.x) (push) Waiting to run
Some checks are pending
Node.js CI / build (16.x) (push) Waiting to run
* Preload data when using Dex.mod With the initial introduction fo TypeScript at3716f36, ``Dex.mod``, and ``Dex.format`` (nowadays ``Dex.forFormat``) no longer ensured that the data cache has been filled. Newer lazy-loading getter APIs were introduced, which were intended to be used as a replacement for direct access to the loaded data (``dataCache``). However, these APIs were either not effective or not properly used., as reflected by43ef4d9, which reverted ``Dex.forFormat`` to its full capabilities. Nevertheless, ``Dex.mod`` was left untouched, which results in a footgun where ``Dex.forFormat('gen1randbats').gen == 1``, but ``Dex.mod('gen1').gen == 9``. This commit brings back ``Dex.mod`` to its original behavior, so that gen information is always there when it's needed. * Add test for dex.mod(mod).gen * Swap around test instructions This is more reliable given the load order.
This commit is contained in:
parent
5bcbf82177
commit
36966fab3b
|
|
@ -165,7 +165,7 @@ export class ModdedDex {
|
|||
|
||||
mod(mod: string | undefined): ModdedDex {
|
||||
if (!dexes['base'].modsLoaded) dexes['base'].includeMods();
|
||||
return dexes[mod || 'base'];
|
||||
return dexes[mod || 'base'].includeData();
|
||||
}
|
||||
|
||||
forGen(gen: number) {
|
||||
|
|
|
|||
|
|
@ -3,6 +3,14 @@
|
|||
const assert = require('./../assert');
|
||||
|
||||
describe('Mod loader', function () {
|
||||
it('should always provide accurate gen information', function () {
|
||||
{
|
||||
const Dex = require('./../../dist/sim/dex').Dex;
|
||||
assert.equal(Dex.mod('gen2').gen, 2);
|
||||
assert.equal(Dex.forFormat('gen1randombattle').gen, 1);
|
||||
}
|
||||
});
|
||||
|
||||
it('should work fine in any order', function () {
|
||||
{
|
||||
const Dex = require('./../../dist/sim/dex').Dex;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user