Preload data when using Dex.mod (#10641)
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 at 3716f36,
``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 by 43ef4d9, 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:
Slayer95 2024-10-30 23:27:31 -05:00 committed by GitHub
parent 5bcbf82177
commit 36966fab3b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 1 deletions

View File

@ -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) {

View File

@ -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;