diff --git a/src/ui/starter-select-ui-handler.ts b/src/ui/starter-select-ui-handler.ts index 7396608bfc4..a29a65aca80 100644 --- a/src/ui/starter-select-ui-handler.ts +++ b/src/ui/starter-select-ui-handler.ts @@ -1828,9 +1828,9 @@ export class StarterSelectUiHandler extends MessageUiHandler { // The persistent starter data to apply e.g. candy upgrades const persistentStarterData = globalScene.gameData.starterData[this.lastSpecies.speciesId]; // The sanitized starter preferences - let starterAttributes = this.starterPreferences[this.lastSpecies.speciesId] ?? {}; + let starterAttributes = this.starterPreferences[this.lastSpecies.speciesId]; // The original starter preferences - const originalStarterAttributes = this.originalStarterPreferences[this.lastSpecies.speciesId] ?? {}; + const originalStarterAttributes = this.originalStarterPreferences[this.lastSpecies.speciesId]; // this gets the correct pokemon cursor depending on whether you're in the starter screen or the party icons if (!this.starterIconsCursorObj.visible) { @@ -3408,9 +3408,8 @@ export class StarterSelectUiHandler extends MessageUiHandler { if (species) { const defaultDexAttr = this.getCurrentDexProps(species.speciesId); const defaultProps = globalScene.gameData.getSpeciesDexAttrProps(species, defaultDexAttr); - // Bang is correct due to the `?` before variant const variant = this.starterPreferences[species.speciesId]?.variant - ? (this.starterPreferences[species.speciesId]!.variant as Variant) + ? (this.starterPreferences[species.speciesId].variant as Variant) : defaultProps.variant; const tint = getVariantTint(variant); this.pokemonShinyIcon.setFrame(getVariantIcon(variant)).setTint(tint); diff --git a/src/utils/data.ts b/src/utils/data.ts index 337aac1110b..6580ecf2ee9 100644 --- a/src/utils/data.ts +++ b/src/utils/data.ts @@ -64,7 +64,7 @@ const StarterPrefers_DEFAULT: string = "{}"; let StarterPrefers_private_latest: string = StarterPrefers_DEFAULT; export interface StarterPreferences { - [key: number]: StarterAttributes | undefined; + [key: number]: StarterAttributes; } // called on starter selection show once @@ -74,27 +74,10 @@ export function loadStarterPreferences(): StarterPreferences { localStorage.getItem(`starterPrefs_${loggedInUser?.username}`) || StarterPrefers_DEFAULT), ); } - -/** - * Check if an object has no properties of its own (its shape is `{}`) - * @param obj - Object to check - * @returns - Whether the object is bare - */ -export function isBareObject(obj: object): boolean { - for (const _ in obj) { - return false; - } - return true; -} +// called on starter selection clear, always export function saveStarterPreferences(prefs: StarterPreferences): void { - // Fastest way to check if an object has any properties (does no allocation) - if (isBareObject(prefs)) { - console.warn("Refusing to save empty starter preferences"); - return; - } - // no reason to store `{}` (for starters not customized) - const pStr: string = JSON.stringify(prefs, (_, value) => (isBareObject(value) ? undefined : value)); + const pStr: string = JSON.stringify(prefs); if (pStr !== StarterPrefers_private_latest) { // something changed, store the update localStorage.setItem(`starterPrefs_${loggedInUser?.username}`, pStr);