Skip to content

No way to load a ModdedDex into battle simulator #21

@B0sh

Description

@B0sh

Hey, I'm trying to use this library to do showdown battle simulations that included modded data, and as far as I can tell there's no way to actually start a simulator battle from a modded dex. After a lot of code searching, I believe I've narrowed it down to this difference in @pkmn/dex vs @pkmn/sim (bottom of issue). In the sim version of the Dex.mod function, it does not commit the new dex into the dexes constant, so when a new Battle() is created, it cannot find the newly made dex, and I get various errors. I do have a workaround that seems to work that involves just overwriting everything after the battle is made, but I feel like it should be enough to just added new mods to the list, or maybe passing in a ModdedDex somewhere on creation.

export const MyModDex = Dex.mod('modded' as ID, MyModData as ModData);
const formatid = 'moddedformatid';

const newBattle = new BattleStreams.BattleStream();
this.streams = BattleStreams.getPlayerStreams(newBattle);

const battleSpec = {
    format: MyModDex.formats.get(formatid as ID),
    formatid: formatid as ID
};
this.streams.omniscient.write(`>start ${JSON.stringify(battleSpec)}`);
this.battle = newBattle.battle;
//@ts-ignore
this.battle.format = MyModDex.formats.get(formatid as ID);
this.battle.dex = MyModDex;

this.streams.omniscient.write(`>player p1 ${JSON.stringify(p1)}`);
this.streams.omniscient.write(`>player p2 ${JSON.stringify(p2)}`);

I'd submit a PR to fix but I'm pretty scared about the whole way this system is designed with the whole automatic code merging and all, so I'm hoping I just overlooked something and there's already a way to do this that I missed. Thank you for making this repo!

@pkmn/dex - Overwrites the dexes constant

ps/dex/index.ts

Lines 1243 to 1246 in ab700ad

mod(modid: GenID | T.ID, modData?: ModData) {
if (modid in dexes) return modData ? new ModdedDex(modid, modData) : dexes[modid];
return (dexes[modid] = new ModdedDex(modid as T.ID, modData));
}

@pkmn/sim - Does not overwrite the dexes constant

ps/sim/sim/dex.ts

Lines 219 to 227 in ab700ad

mod(mod: string | undefined, modData?: DeepPartial<ModdedDex['data']>): ModdedDex {
if (!mod) return dexes['base'];
const modid = toID(mod);
if (modData?.Types && !modData.TypeChart) modData.TypeChart = modData.Types;
if (modData?.Species && !modData.Pokedex) modData.Pokedex = modData.Species;
const dex = (modid in dexes) && !modData ? dexes[modid] : new ModdedDex(modid);
dex.loadData(modData);
return dex;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions