Skip to content

Commit

Permalink
[Bug] Save data migrator to fix starters with no selectable forms (#5425
Browse files Browse the repository at this point in the history
)

Co-authored-by: Madmadness65 <[email protected]>
  • Loading branch information
Wlowscha and Madmadness65 authored Feb 27, 2025
1 parent 3124aeb commit 922a170
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions src/system/version_migration/versions/v1_7_0.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,29 @@
import { getPokemonSpeciesForm } from "#app/data/pokemon-species";
import type { SessionSaveData } from "#app/system/game-data";
import { getPokemonSpecies, getPokemonSpeciesForm } from "#app/data/pokemon-species";
import { globalScene } from "#app/global-scene";
import { DexAttr, type SessionSaveData, type SystemSaveData } from "#app/system/game-data";
import * as Utils from "#app/utils";

export const systemMigrators = [] as const;
export const systemMigrators = [
/**
* If a starter is caught, but the only forms registered as caught are not starterSelectable,
* unlock the default form.
* @param data {@linkcode SystemSaveData}
*/
function migrateUnselectableForms(data: SystemSaveData) {
if (data.starterData && data.dexData) {
Object.keys(data.starterData).forEach(sd => {
const caughtAttr = data.dexData[sd]?.caughtAttr;
const species = getPokemonSpecies(Number(sd));
if (caughtAttr && species.forms?.length > 1) {
const selectableForms = species.forms.filter((form, formIndex) => form.isStarterSelectable && (caughtAttr & globalScene.gameData.getFormAttr(formIndex)));
if (selectableForms.length === 0) {
data.dexData[sd].caughtAttr += DexAttr.DEFAULT_FORM;
}
}
});
}
},
] as const;

export const settingsMigrators = [] as const;

Expand Down

0 comments on commit 922a170

Please sign in to comment.