From fcdd7c421ea99aeae27e84e19a7cca3988d6855f Mon Sep 17 00:00:00 2001 From: Flashfyre Date: Tue, 18 Apr 2023 01:32:26 -0400 Subject: [PATCH] Add persistent data for catches --- public/images/ui/icon_owned.png | Bin 0 -> 4265 bytes src/battle-info.ts | 20 +++++++ src/battle-phases.ts | 50 ++++++++-------- src/battle-scene.ts | 20 ++++++- src/{data.ts => game-data.ts} | 90 ++++++++++++++++++++++------ src/pokemon-evolutions.ts | 20 +++---- src/pokemon.ts | 6 +- src/ui/starter-select-ui-handler.ts | 75 +++++++++++++++-------- 8 files changed, 196 insertions(+), 85 deletions(-) create mode 100644 public/images/ui/icon_owned.png rename src/{data.ts => game-data.ts} (75%) diff --git a/public/images/ui/icon_owned.png b/public/images/ui/icon_owned.png new file mode 100644 index 0000000000000000000000000000000000000000..21e03afec606681c13805f780e2ee441b34dede5 GIT binary patch literal 4265 zcmeHKeQ*TF<8(&< zYi5$&_xbp}&+~hp=bgOG{>u52bEoGb2r}7Q;i-bpZ2g;=0e@}3U(g31T@8U{S{0W> zV~QMB>-4XxqrW`?YzPnOz@A{l2#jTP1_x|?F{e)Ptf z|GjkK)(0}0Z$DneoNg~dm#kWq!%XjfvjEh(L>3Z;F3-+6~L|*-I|1)2{fVIBVQr6+`&V7yDw&H4*Z~7Aj zQ|BMv*VlK9|LkyAO?7tlyu52jygpu~wdD^yT~K>875n_L&+xF@#%ch!C>z=j!{S8yk*YsZa{+5gdhs8%0-QG%_>1eVy zh3xncV_*gtq}(p-^26n4w`7;@ zFB#b0vwZE0mv1cD`flxerYTd_HRpppYY%kp>D=FV;>~ZrH63VDj_&jLCc(x_NU*_{ z`4+N*95HjE%mZ^O5`&$GAjNZ2F-}+wG?WJ+DeA&5b^ZlICDDadTYaQ2<_0UJiUtKN zZm0|h4XXvGh|QgoTbyDcKm=$Unu>&@Dw}d)1}+QVbuodVhKaV?g)Q^>QMarBlrb}A z5-&?h2^yP|ixw+lkgf8R4?)0{3tOpaF_s{b$)q`HG0RGbpqx%8LDB?G;Fo-}?74Axn*>b+u z=O6LVDF{iCnBfJ<9%HFV!BMit#HMSEbkYNX?jyKktcPj!$9iO;UJuXfabf!Y ztSAeT$QrLslDE@A(u!MY+JQ5qmBJl@mBwk>M%#dsBPp9b4ayr;H7+Uu9SVY*C5S@- zG3XF&0`BB_5oai;h&vcjzy(3H^EQgHiF7)|B1M8-$%WIS(xF5MWpxH^B*~MwVBzf$ zigMsihOyxeKmi+N=Shp5H=+>*wp>;s94x04;X;6jMMH){C!C$<_qs6JOpZ$YVNMG| z2RH*#RFsqIs45^uz+#Ql`J`+P%I>6W7ORaW;rpo3QlO}?7j;yMG+P)$qZfvS=|E~Z zy;C88A&1$pZUu0ftOR5^?85Y*P~CGx?Slg)avJC1Gyp+K+QO0yOF050$batReGK?5Xme5a(;cSbEAMjCZ7^EFB&~H!% zk1lu;5+g_95MTPC^9z24>hKHh0HG%~85h43bWPATE(XSBJkebfbd8IFaT!l^*Uv^* z?&xI-MBzW6B)lpex;niDUbCk87Y53>7_y+Wc3@!O$`-YEb?t@?kDmJIAXHx6v+*o^ zn6#?O#Yo9N{|c}Dh>5>%z6WW_y0ro>u8&pJs0cFUi2gMllV1^`FkAEb%CawH=4TcZ zxx3!l2Su~Io_T?s(?VTdL0w&4AR*S}*%CL^ { diff --git a/src/battle-phases.ts b/src/battle-phases.ts index c6140ce49..2f1540ce8 100644 --- a/src/battle-phases.ts +++ b/src/battle-phases.ts @@ -72,6 +72,8 @@ export class EncounterPhase extends BattlePhase { const enemyPokemon = this.scene.getEnemyPokemon(); enemyPokemon.resetSummonData(); + this.scene.gameData.setPokemonSeen(enemyPokemon); + console.log(enemyPokemon.species.name, enemyPokemon.species.speciesId, enemyPokemon.stats); enemyPokemon.loadAssets().then(() => { @@ -1258,8 +1260,7 @@ export class LevelUpPhase extends PartyMemberPokemonPhase { const prevStats = pokemon.stats.slice(0); pokemon.calculateStats(); pokemon.updateInfo(); - this.scene.pauseBgm(); - this.scene.sound.play('level_up_fanfare'); + this.scene.playSoundWithoutBgm('level_up_fanfare', 1500); this.scene.ui.showText(`${this.getPokemon().name} grew to\nLV. ${this.level}!`, null, () => this.scene.ui.getMessageHandler().promptLevelUpStats(prevStats, false, () => this.end()), null, true); const levelMoves = this.getPokemon().getLevelMoves(this.lastLevel + 1); for (let lm of levelMoves) @@ -1267,7 +1268,6 @@ export class LevelUpPhase extends PartyMemberPokemonPhase { const evolution = pokemon.getEvolution(); if (evolution) this.scene.unshiftPhase(new EvolutionPhase(this.scene, this.partyMemberIndex, evolution, this.lastLevel)); - this.scene.time.delayedCall(1500, () => this.scene.resumeBgm()); } } @@ -1307,10 +1307,8 @@ export class LearnMovePhase extends PartyMemberPokemonPhase { loadMoveAnimAssets(this.scene, [ this.moveId ], true) .then(() => { this.scene.ui.setMode(messageMode).then(() => { - this.scene.pauseBgm(); - this.scene.sound.play('level_up_fanfare'); + this.scene.playSoundWithoutBgm('level_up_fanfare', 1500); this.scene.ui.showText(`${pokemon.name} learned\n${Utils.toPokemonUpperCase(move.name)}!`, null, () => this.end(), messageMode === Mode.EVOLUTION_SCENE ? 1000 : null, true); - this.scene.time.delayedCall(1500, () => this.scene.resumeBgm()); }); }); }); @@ -1548,28 +1546,30 @@ export class AttemptCapturePhase extends BattlePhase { else end(); }; - if (this.scene.getParty().length === 6) { - const promptRelease = () => { - this.scene.ui.showText(`Your party is full.\nRelease a POKéMON to make room for ${pokemon.name}?`, null, () => { - this.scene.ui.setMode(Mode.CONFIRM, () => { - this.scene.ui.setMode(Mode.PARTY, PartyUiMode.RELEASE, (slotIndex: integer, _option: PartyOption) => { - this.scene.ui.setMode(Mode.MESSAGE).then(() => { - if (slotIndex < 6) - addToParty(); - else - promptRelease(); + this.scene.gameData.setPokemonCaught(pokemon).then(() => { + if (this.scene.getParty().length === 6) { + const promptRelease = () => { + this.scene.ui.showText(`Your party is full.\nRelease a POKéMON to make room for ${pokemon.name}?`, null, () => { + this.scene.ui.setMode(Mode.CONFIRM, () => { + this.scene.ui.setMode(Mode.PARTY, PartyUiMode.RELEASE, (slotIndex: integer, _option: PartyOption) => { + this.scene.ui.setMode(Mode.MESSAGE).then(() => { + if (slotIndex < 6) + addToParty(); + else + promptRelease(); + }); }); + }, () => { + this.scene.ui.setMode(Mode.MESSAGE); + pokemon.hp = 0; + end(); }); - }, () => { - this.scene.ui.setMode(Mode.MESSAGE); - pokemon.hp = 0; - end(); }); - }); - }; - promptRelease(); - } else - addToParty(); + }; + promptRelease(); + } else + addToParty(); + }); }, 0, true); } diff --git a/src/battle-scene.ts b/src/battle-scene.ts index af718bfa7..69ba29a8a 100644 --- a/src/battle-scene.ts +++ b/src/battle-scene.ts @@ -14,7 +14,7 @@ import { initCommonAnims, loadCommonAnimAssets, populateAnims } from './battle-a import { BattlePhase } from './battle-phase'; import { initGameSpeed } from './game-speed'; import { Arena } from './arena'; -import { SaveData } from './data'; +import { GameData } from './game-data'; import StarterSelectUiHandler from './ui/starter-select-ui-handler'; const enableAuto = true; @@ -41,7 +41,7 @@ export default class BattleScene extends Phaser.Scene { public gameSpeed: integer = 1; public quickStart: boolean; - public saveData: SaveData; + public gameData: GameData; private phaseQueue: BattlePhase[]; private phaseQueuePrepend: BattlePhase[]; @@ -68,6 +68,7 @@ export default class BattleScene extends Phaser.Scene { //public spritePipeline: SpritePipeline; private bgm: Phaser.Sound.BaseSound; + private bgmResumeTimer: Phaser.Time.TimerEvent; private buttonKeys: Phaser.Input.Keyboard.Key[][]; @@ -76,7 +77,7 @@ export default class BattleScene extends Phaser.Scene { constructor() { super('battle'); - this.saveData = new SaveData(this); + this.gameData = new GameData(this); this.phaseQueue = []; this.phaseQueuePrepend = []; @@ -135,6 +136,7 @@ export default class BattleScene extends Phaser.Scene { this.loadAtlas('numbers', 'ui'); this.loadAtlas('overlay_hp', 'ui'); this.loadImage('overlay_exp', 'ui'); + this.loadImage('icon_owned', 'ui'); this.loadImage('level_up_stats', 'ui'); this.loadImage('ball_window', 'ui'); this.loadImage('boolean_window', 'ui'); @@ -521,6 +523,18 @@ export default class BattleScene extends Phaser.Scene { this.arena.fadeOutBgm(500, destroy); } + playSoundWithoutBgm(soundName: string, pauseDuration?: integer): void { + this.pauseBgm(); + this.sound.play(soundName); + const sound = this.sound.get(soundName); + if (this.bgmResumeTimer) + this.bgmResumeTimer.destroy(); + this.bgmResumeTimer = this.time.delayedCall((pauseDuration || (sound.totalDuration * 1000)), () => { + this.resumeBgm(); + this.bgmResumeTimer = null; + }); + } + getCurrentPhase(): BattlePhase { return this.currentPhase; } diff --git a/src/data.ts b/src/game-data.ts similarity index 75% rename from src/data.ts rename to src/game-data.ts index 25a761f8c..fbf2472d5 100644 --- a/src/data.ts +++ b/src/game-data.ts @@ -1,9 +1,16 @@ import BattleScene from "./battle-scene"; import { Gender } from "./gender"; +import Pokemon from "./pokemon"; import PokemonSpecies, { allSpecies } from "./pokemon-species"; import { Species } from "./species"; import * as Utils from "./utils"; +interface SaveData { + trainerId: integer; + secretId: integer; + dexData: DexData; +} + export interface DexData { [key: integer]: DexData | DexEntry } @@ -13,7 +20,7 @@ export interface DexEntry { caught: boolean; } -export interface StarterDexEntry { +export interface DexEntryDetails { shiny: boolean; formIndex: integer; female: boolean; @@ -28,7 +35,7 @@ export interface StarterDexUnlockTree { entry: DexEntry } -export class SaveData { +export class GameData { private scene: BattleScene; public trainerId: integer; @@ -39,19 +46,38 @@ export class SaveData { constructor(scene: BattleScene) { this.scene = scene; this.trainerId = Utils.randInt(65536); - this.secretId = Utils.randInt(65536) - this.initDexData(); + this.secretId = Utils.randInt(65536); + if (!this.load()) + this.initDexData(); } - save() { + private save(): boolean { + const data: SaveData = { + trainerId: this.trainerId, + secretId: this.secretId, + dexData: this.dexData + }; + localStorage.setItem('data', btoa(JSON.stringify(data))); + + return true; } - load() { + private load(): boolean { + if (!localStorage.getItem('data')) + return false; + const data = JSON.parse(atob(localStorage.getItem('data'))) as SaveData; + console.log(data); + + this.trainerId = data.trainerId; + this.secretId = data.secretId; + this.dexData = data.dexData; + + return true; } - initDexData() { + private initDexData() { const data: DexData = {}; const initDexSubData = (dexData: DexData, count: integer): DexData[] => { @@ -68,7 +94,7 @@ export class SaveData { const initDexEntries = (dexData: DexData, count: integer): DexEntry[] => { const ret: DexEntry[] = []; for (let i = 0; i < count; i++) { - const entry: DexEntry = { seen: true, caught: true }; + const entry: DexEntry = { seen: false, caught: false }; dexData[i] = entry; ret.push(entry); } @@ -98,20 +124,46 @@ export class SaveData { let entry = data[ds][0][Gender.MALE] as DexEntry; entry.seen = true; entry.caught = true; - - entry = data[ds][0][Gender.FEMALE] as DexEntry; - entry.seen = true; - entry.caught = true; - - entry = data[ds][1][Gender.FEMALE] as DexEntry; - entry.seen = true; - entry.caught = true; } + data[Species.SHAYMIN][1][1].caught = true; + this.dexData = data; } - getDexEntry(species: PokemonSpecies, shiny: boolean, formIndex: integer, female: boolean) : DexEntry { + setPokemonSeen(pokemon: Pokemon): void { + const dexEntry = this.getPokemonDexEntry(pokemon); + if (!dexEntry.seen) { + dexEntry.seen = true; + this.save(); + } + } + + setPokemonCaught(pokemon: Pokemon): Promise { + return new Promise(resolve => { + const dexEntry = this.getPokemonDexEntry(pokemon); + if (!dexEntry.caught) { + const newCatch = !this.getDefaultDexEntry(pokemon.species); + + dexEntry.caught = true; + this.save(); + + if (newCatch && !pokemon.species.getPrevolutionLevels(true).length) { + this.scene.playSoundWithoutBgm('level_up_fanfare', 1500); + this.scene.ui.showText(`${pokemon.name} has been\nadded as a starter!`, null, () => resolve(), null, true); + return; + } + } + + resolve(); + }); + } + + getPokemonDexEntry(pokemon: Pokemon) { + return this.getDexEntry(pokemon.species, pokemon.shiny, pokemon.formIndex, pokemon.gender === Gender.FEMALE); + } + + getDexEntry(species: PokemonSpecies, shiny: boolean, formIndex: integer, female: boolean): DexEntry { const shinyIndex = !shiny ? 0 : 1; const genderIndex = !female ? 0 : 1; const data = this.dexData[species.speciesId]; @@ -124,7 +176,7 @@ export class SaveData { return data[shinyIndex] as DexEntry; } - getDefaultStarterDexEntry(species: PokemonSpecies, forceShiny?: boolean, forceFormIndex?: integer, forceFemale?: boolean): StarterDexEntry { + getDefaultDexEntry(species: PokemonSpecies, forceShiny?: boolean, forceFormIndex?: integer, forceFemale?: boolean): DexEntryDetails { const hasForms = !!species.forms?.length; let shiny = false; let formIndex = 0; @@ -166,7 +218,7 @@ export class SaveData { traverseData(this.dexData[species.speciesId] as DexData, 0); if (entry) { - return { + return { shiny: shiny, formIndex: formIndex, female: female, diff --git a/src/pokemon-evolutions.ts b/src/pokemon-evolutions.ts index 6ab5ae950..dd91c9882 100644 --- a/src/pokemon-evolutions.ts +++ b/src/pokemon-evolutions.ts @@ -525,9 +525,9 @@ export const pokemonEvolutions: PokemonEvolutions = { ], [Species.BURMY]: [ new SpeciesEvolution(Species.MOTHIM, 20, null, new SpeciesEvolutionCondition((p: Pokemon) => p.gender, true)), - new SpeciesEvolution(Species.WORMADAM, 20, null, new SpeciesEvolutionCondition((p: Pokemon) => !p.gender && p.scene.arena.biomeType === Biome.FOREST, true)), - new SpeciesEvolution(Species.WORMADAM, 20, null, new SpeciesEvolutionCondition((p: Pokemon) => !p.gender && p.scene.arena.biomeType === Biome.CAVE, true)), - new SpeciesEvolution(Species.WORMADAM, 20, null, new SpeciesEvolutionCondition((p: Pokemon) => !p.gender && p.scene.arena.biomeType === Biome.CITY, true)) + new SpeciesEvolution(Species.WORMADAM, 20, null, new SpeciesEvolutionCondition((p: Pokemon) => !p.gender && p.scene.arena?.biomeType === Biome.FOREST, true)), + new SpeciesEvolution(Species.WORMADAM, 20, null, new SpeciesEvolutionCondition((p: Pokemon) => !p.gender && p.scene.arena?.biomeType === Biome.CAVE, true)), + new SpeciesEvolution(Species.WORMADAM, 20, null, new SpeciesEvolutionCondition((p: Pokemon) => !p.gender && p.scene.arena?.biomeType === Biome.CITY, true)) ], [Species.COMBEE]: [ new SpeciesEvolution(Species.VESPIQUEN, 21, null, new SpeciesEvolutionCondition((p: Pokemon) => !p.gender, true)) @@ -802,8 +802,8 @@ export const pokemonEvolutions: PokemonEvolutions = { new SpeciesEvolution(Species.STARMIE, 1, EvolutionItem.WATER_STONE, null, SpeciesWildEvolutionDelay.MEDIUM) ], [Species.EEVEE]: [ - new SpeciesEvolution(Species.ESPEON, 1, null, new SpeciesEvolutionCondition((p: Pokemon) => p.winCount >= 10 && p.scene.arena.isDaytime()), SpeciesWildEvolutionDelay.MEDIUM), - new SpeciesEvolution(Species.UMBREON, 1, null, new SpeciesEvolutionCondition((p: Pokemon) => p.winCount >= 10 && !p.scene.arena.isDaytime()), SpeciesWildEvolutionDelay.MEDIUM), + new SpeciesEvolution(Species.ESPEON, 1, null, new SpeciesEvolutionCondition((p: Pokemon) => p.winCount >= 10 && p.scene.arena?.isDaytime()), SpeciesWildEvolutionDelay.MEDIUM), + new SpeciesEvolution(Species.UMBREON, 1, null, new SpeciesEvolutionCondition((p: Pokemon) => p.winCount >= 10 && !p.scene.arena?.isDaytime()), SpeciesWildEvolutionDelay.MEDIUM), new SpeciesEvolution(Species.VAPOREON, 1, EvolutionItem.WATER_STONE, null, SpeciesWildEvolutionDelay.MEDIUM), new SpeciesEvolution(Species.JOLTEON, 1, EvolutionItem.THUNDER_STONE, null, SpeciesWildEvolutionDelay.MEDIUM), new SpeciesEvolution(Species.FLAREON, 1, EvolutionItem.FIRE_STONE, null, SpeciesWildEvolutionDelay.MEDIUM), @@ -829,10 +829,10 @@ export const pokemonEvolutions: PokemonEvolutions = { new SpeciesEvolution(Species.MISMAGIUS, 1, EvolutionItem.DUSK_STONE, null, SpeciesWildEvolutionDelay.VERY_LONG) ], [Species.GLIGAR]: [ - new SpeciesEvolution(Species.GLISCOR, 1, null, new SpeciesEvolutionCondition((p: Pokemon) => !p.scene.arena.isDaytime() /* Razor fang at night*/), SpeciesWildEvolutionDelay.LONG) + new SpeciesEvolution(Species.GLISCOR, 1, null, new SpeciesEvolutionCondition((p: Pokemon) => !p.scene.arena?.isDaytime() /* Razor fang at night*/), SpeciesWildEvolutionDelay.LONG) ], [Species.SNEASEL]: [ - new SpeciesEvolution(Species.WEAVILE, 1, null, new SpeciesEvolutionCondition((p: Pokemon) => !p.scene.arena.isDaytime() /* Razor claw at night*/), SpeciesWildEvolutionDelay.LONG) + new SpeciesEvolution(Species.WEAVILE, 1, null, new SpeciesEvolutionCondition((p: Pokemon) => !p.scene.arena?.isDaytime() /* Razor claw at night*/), SpeciesWildEvolutionDelay.LONG) ], [Species.PILOSWINE]: [ new SpeciesEvolution(Species.MAMOSWINE, 1, null, new SpeciesEvolutionCondition((p: Pokemon) => p.moveset.filter(m => m.moveId === Moves.ANCIENT_POWER).length), SpeciesWildEvolutionDelay.VERY_LONG) @@ -975,16 +975,16 @@ export const pokemonEvolutions: PokemonEvolutions = { new SpeciesEvolution(Species.MARILL, 1, null, new SpeciesEvolutionCondition((p: Pokemon) => p.winCount >= 10), SpeciesWildEvolutionDelay.SHORT) ], [Species.BUDEW]: [ - new SpeciesEvolution(Species.ROSELIA, 1, null, new SpeciesEvolutionCondition((p: Pokemon) => p.winCount > 10 && p.scene.arena.isDaytime()), SpeciesWildEvolutionDelay.SHORT) + new SpeciesEvolution(Species.ROSELIA, 1, null, new SpeciesEvolutionCondition((p: Pokemon) => p.winCount > 10 && p.scene.arena?.isDaytime()), SpeciesWildEvolutionDelay.SHORT) ], [Species.CHINGLING]: [ - new SpeciesEvolution(Species.CHIMECHO, 1, null, new SpeciesEvolutionCondition((p: Pokemon) => p.winCount >= 10 && !p.scene.arena.isDaytime()), SpeciesWildEvolutionDelay.MEDIUM) + new SpeciesEvolution(Species.CHIMECHO, 1, null, new SpeciesEvolutionCondition((p: Pokemon) => p.winCount >= 10 && !p.scene.arena?.isDaytime()), SpeciesWildEvolutionDelay.MEDIUM) ], [Species.BUNEARY]: [ new SpeciesEvolution(Species.LOPUNNY, 1, null, new SpeciesEvolutionCondition((p: Pokemon) => p.winCount >= 10), SpeciesWildEvolutionDelay.MEDIUM) ], [Species.RIOLU]: [ - new SpeciesEvolution(Species.LUCARIO, 1, null, new SpeciesEvolutionCondition((p: Pokemon) => p.winCount >= 10 && p.scene.arena.isDaytime()), SpeciesWildEvolutionDelay.MEDIUM) + new SpeciesEvolution(Species.LUCARIO, 1, null, new SpeciesEvolutionCondition((p: Pokemon) => p.winCount >= 10 && p.scene.arena?.isDaytime()), SpeciesWildEvolutionDelay.MEDIUM) ], [Species.WOOBAT]: [ new SpeciesEvolution(Species.SWOOBAT, 1, null, new SpeciesEvolutionCondition((p: Pokemon) => p.winCount >= 10), SpeciesWildEvolutionDelay.MEDIUM) diff --git a/src/pokemon.ts b/src/pokemon.ts index dbed7fc89..dc0bb1f1e 100644 --- a/src/pokemon.ts +++ b/src/pokemon.ts @@ -103,7 +103,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { const rand1 = Utils.binToDec(Utils.decToBin(this.id).substring(0, 16)); const rand2 = Utils.binToDec(Utils.decToBin(this.id).substring(16, 32)); - const E = this.scene.saveData.trainerId ^ this.scene.saveData.secretId; + const E = this.scene.gameData.trainerId ^ this.scene.gameData.secretId; const F = rand1 ^ rand2; if (this.shiny === undefined) { @@ -777,7 +777,7 @@ export default interface Pokemon { export class PlayerPokemon extends Pokemon { public compatibleTms: Moves[]; - constructor(scene: BattleScene, species: PokemonSpecies, level: integer, formIndex: integer, gender: Gender, shiny: boolean, dataSource?: Pokemon) { + constructor(scene: BattleScene, species: PokemonSpecies, level: integer, formIndex: integer, gender?: Gender, shiny?: boolean, dataSource?: Pokemon) { super(scene, 106, 148, species, level, formIndex, gender, shiny, dataSource); this.getSpeciesForm().generateIconAnim(scene, this.gender === Gender.FEMALE, formIndex); @@ -816,6 +816,8 @@ export class PlayerPokemon extends Pokemon { this.getSpeciesForm().generateIconAnim(this.scene, this.gender === Gender.FEMALE, this.formIndex); this.compatibleTms.splice(0, this.compatibleTms.length); this.generateCompatibleTms(); + this.scene.gameData.setPokemonSeen(this); + this.scene.gameData.setPokemonCaught(this); this.loadAssets().then(() => { this.calculateStats(); this.updateInfo().then(() => resolve()); diff --git a/src/ui/starter-select-ui-handler.ts b/src/ui/starter-select-ui-handler.ts index ad4192d45..84350df49 100644 --- a/src/ui/starter-select-ui-handler.ts +++ b/src/ui/starter-select-ui-handler.ts @@ -5,7 +5,8 @@ import { TextStyle, addTextObject } from "../text"; import { Mode } from "./ui"; import * as Utils from "../utils"; import MessageUiHandler from "./message-ui-handler"; -import { StarterDexEntry, StarterDexUnlockTree } from "../data"; +import { DexEntryDetails, StarterDexUnlockTree } from "../game-data"; +import { Gender, getGenderColor, getGenderSymbol } from "../gender"; export type StarterSelectCallback = (starters: Starter[]) => void; @@ -22,6 +23,7 @@ export default class StarterSelectUiHandler extends MessageUiHandler { private pokemonNumberText: Phaser.GameObjects.Text; private pokemonSprite: Phaser.GameObjects.Sprite; private pokemonNameText: Phaser.GameObjects.Text; + private pokemonGenderText: Phaser.GameObjects.Text; private instructionsText: Phaser.GameObjects.Text; private starterSelectMessageBoxContainer: Phaser.GameObjects.Container; @@ -37,7 +39,7 @@ export default class StarterSelectUiHandler extends MessageUiHandler { private starterGens: integer[] = []; private starterCursors: integer[] = []; private starterDetails: [boolean, integer, boolean][] = []; - private speciesStarterDexEntry: StarterDexEntry; + private speciesStarterDexEntry: DexEntryDetails; private speciesStarterDexTree: StarterDexUnlockTree; private canCycleShiny: boolean; private canCycleForm: boolean; @@ -79,6 +81,10 @@ export default class StarterSelectUiHandler extends MessageUiHandler { this.pokemonNameText.setOrigin(0, 0); this.starterSelectContainer.add(this.pokemonNameText); + this.pokemonGenderText = addTextObject(this.scene, 96, 112, '', TextStyle.SUMMARY); + this.pokemonGenderText.setOrigin(0, 0); + this.starterSelectContainer.add(this.pokemonGenderText); + const genText = addTextObject(this.scene, 115, 6, 'I\nII\nIII\nIV\nV', TextStyle.WINDOW); genText.setLineSpacing(16); this.starterSelectContainer.add(genText); @@ -121,7 +127,7 @@ export default class StarterSelectUiHandler extends MessageUiHandler { continue; this.speciesLoaded.set(species.speciesId, false); this.genSpecies[g].push(species); - const dexEntry = this.scene.saveData.getDefaultStarterDexEntry(species); + const dexEntry = this.scene.gameData.getDefaultDexEntry(species); species.generateIconAnim(this.scene, dexEntry?.female, dexEntry?.formIndex); const x = (s % 9) * 18; const y = Math.floor(s / 9) * 18; @@ -259,6 +265,7 @@ export default class StarterSelectUiHandler extends MessageUiHandler { }); } success = true; + this.updateInstructions(); } else ui.playError(); } @@ -266,6 +273,7 @@ export default class StarterSelectUiHandler extends MessageUiHandler { if (this.starterCursors.length) { this.popStarter(); success = true; + this.updateInstructions(); } else ui.playError(); } else { @@ -275,16 +283,24 @@ export default class StarterSelectUiHandler extends MessageUiHandler { switch (button) { case Button.CYCLE_SHINY: if (this.canCycleShiny) { - this.setSpeciesDetails(this.lastSpecies, !this.shinyCursor, this.formCursor, !!this.genderCursor); + this.setSpeciesDetails(this.lastSpecies, !this.shinyCursor, undefined, undefined); + if (this.shinyCursor) + this.scene.sound.play('sparkle'); + else + success = true; } break; case Button.CYCLE_FORM: - if (this.canCycleForm) - this.setSpeciesDetails(this.lastSpecies, !!this.shinyCursor, (this.formCursor + 1) % this.lastSpecies.forms.length, !!this.genderCursor); + if (this.canCycleForm) { + this.setSpeciesDetails(this.lastSpecies, undefined, (this.formCursor + 1) % this.lastSpecies.forms.length, undefined); + success = true; + } break; case Button.CYCLE_GENDER: - if (this.canCycleGender) - this.setSpeciesDetails(this.lastSpecies, !!this.shinyCursor, this.formCursor, !this.genderCursor); + if (this.canCycleGender) { + this.setSpeciesDetails(this.lastSpecies, undefined, undefined, !this.genderCursor); + success = true; + } break; case Button.UP: if (row) @@ -382,11 +398,11 @@ export default class StarterSelectUiHandler extends MessageUiHandler { } setSpecies(species: PokemonSpecies) { - this.speciesStarterDexEntry = species ? this.scene.saveData.getDefaultStarterDexEntry(species) : null; - this.speciesStarterDexTree = this.speciesStarterDexEntry ? this.scene.saveData.getStarterDexUnlockTree(species) : null; + this.speciesStarterDexEntry = species ? this.scene.gameData.getDefaultDexEntry(species) : null; + this.speciesStarterDexTree = this.speciesStarterDexEntry ? this.scene.gameData.getStarterDexUnlockTree(species) : null; if (this.lastSpecies) { - const defaultStarterDexEntry = this.scene.saveData.getDefaultStarterDexEntry(this.lastSpecies); + const defaultStarterDexEntry = this.scene.gameData.getDefaultDexEntry(this.lastSpecies); const lastSpeciesIcon = (this.starterSelectGenIconContainers[this.lastSpecies.generation - 1].getAt(this.genSpecies[this.lastSpecies.generation - 1].indexOf(this.lastSpecies)) as Phaser.GameObjects.Sprite); lastSpeciesIcon.play(this.lastSpecies.getIconKey(!!defaultStarterDexEntry?.female, defaultStarterDexEntry?.formIndex)).stop(); } @@ -416,16 +432,21 @@ export default class StarterSelectUiHandler extends MessageUiHandler { this.pokemonSprite.setVisible(false); + if (this.assetLoadCancelled) { + this.assetLoadCancelled.value = true; + this.assetLoadCancelled = null; + } + if (species) { - const defaultDexEntry = this.scene.saveData.getDefaultStarterDexEntry(species, shiny, formIndex, female); - const dexEntry = this.scene.saveData.getDexEntry(species, !!this.shinyCursor, this.formCursor, !!this.genderCursor); + const defaultDexEntry = this.scene.gameData.getDefaultDexEntry(species, shiny, formIndex, female) || this.scene.gameData.getDefaultDexEntry(species); + const dexEntry = this.scene.gameData.getDexEntry(species, !!this.shinyCursor, this.formCursor, !!this.genderCursor); if (!dexEntry.caught) { - if (shiny === undefined) + if (shiny === undefined || (defaultDexEntry && shiny !== defaultDexEntry.shiny)) shiny = defaultDexEntry.shiny; - if (formIndex === undefined) - formIndex = defaultDexEntry.formIndex; - if (female === undefined) + if (formIndex === undefined || (defaultDexEntry && formIndex !== defaultDexEntry.formIndex)) + formIndex = defaultDexEntry.formIndex || 0; + if (female === undefined || (defaultDexEntry && female !== defaultDexEntry.female)) female = defaultDexEntry.female; } else { shiny = !!this.shinyCursor; @@ -433,11 +454,6 @@ export default class StarterSelectUiHandler extends MessageUiHandler { female = !!this.genderCursor; } - if (this.assetLoadCancelled) { - this.assetLoadCancelled.value = true; - this.assetLoadCancelled = null; - } - if (this.speciesStarterDexTree) { const assetLoadCancelled = new Utils.BooleanHolder(false); this.assetLoadCancelled = assetLoadCancelled; @@ -451,7 +467,7 @@ export default class StarterSelectUiHandler extends MessageUiHandler { this.pokemonSprite.setVisible(true); }); - species.generateIconAnim(this.scene, this.speciesStarterDexEntry.female, this.speciesStarterDexEntry.formIndex); + species.generateIconAnim(this.scene, female, formIndex); (this.starterSelectGenIconContainers[this.genCursor].getAt(this.cursor) as Phaser.GameObjects.Sprite).play(species.getIconKey(female, formIndex)); let count: integer; @@ -484,9 +500,16 @@ export default class StarterSelectUiHandler extends MessageUiHandler { } else this.canCycleGender = false; } - } else { - - } + + if (species.malePercent !== null) { + const gender = !female ? Gender.MALE : Gender.FEMALE; + this.pokemonGenderText.setText(getGenderSymbol(gender)); + this.pokemonGenderText.setColor(getGenderColor(gender)); + this.pokemonGenderText.setShadowColor(getGenderColor(gender, true)); + } else + this.pokemonGenderText.setText(''); + } else + this.pokemonGenderText.setText(''); this.updateInstructions(); }