From 8a1560bfa74d0630a37e1b39953518a4bb250ce9 Mon Sep 17 00:00:00 2001 From: Matthew Date: Sun, 16 Jun 2024 00:48:09 -0400 Subject: [PATCH] fix egg skip console error (#2284) --- src/egg-hatch-phase.ts | 3 +++ src/ui/egg-counter-container.ts | 5 +++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/egg-hatch-phase.ts b/src/egg-hatch-phase.ts index 3fce35e4f88..6e44b832181 100644 --- a/src/egg-hatch-phase.ts +++ b/src/egg-hatch-phase.ts @@ -262,6 +262,9 @@ export class EggHatchPhase extends Phase { if (!this.canSkip || this.skipped) { return false; } + if (this.eggCounterContainer.eggCountText?.data === undefined) { + return false; + } this.skipped = true; if (!this.hatched) { this.doHatch(); diff --git a/src/ui/egg-counter-container.ts b/src/ui/egg-counter-container.ts index 1c5779ef777..a688b8b7efc 100644 --- a/src/ui/egg-counter-container.ts +++ b/src/ui/egg-counter-container.ts @@ -17,7 +17,7 @@ export default class EggCounterContainer extends Phaser.GameObjects.Container { private battleScene: BattleScene; private eggCount: integer; private eggCountWindow: Phaser.GameObjects.NineSlice; - private eggCountText: Phaser.GameObjects.Text; + public eggCountText: Phaser.GameObjects.Text; /** * @param {BattleScene} scene - The scene to which this container belongs. @@ -49,6 +49,7 @@ export default class EggCounterContainer extends Phaser.GameObjects.Container { eggSprite.setScale(0.32); this.eggCountText = addTextObject(this.battleScene, 28, 13, `${this.eggCount}`, TextStyle.MESSAGE, { fontSize: "66px" }); + this.eggCountText.setName("text-egg-count"); this.add(eggSprite); this.add(this.eggCountText); @@ -69,7 +70,7 @@ export default class EggCounterContainer extends Phaser.GameObjects.Container { */ private onEggCountChanged(event: Event): void { const eggCountChangedEvent = event as EggCountChangedEvent; - if (!eggCountChangedEvent) { + if (!eggCountChangedEvent || !this.eggCountText?.data) { return; }