From c182ddbd7fa41f36798da543aebdfd86e2550fd9 Mon Sep 17 00:00:00 2001 From: Guangcong Luo Date: Sun, 13 Nov 2016 22:59:51 -0500 Subject: [PATCH] Battles: Fix bug in team preview Previously, a race condition would make the team preview selector appear before we knew how many pokemon needed to be selected (e.g. 4 in VGC). This new UI patches over that problem, although the real fix (mentioned in the TODO comment) is to send that information in the request object. --- js/client-battle.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/js/client-battle.js b/js/client-battle.js index 6733f8b7e..3f387f5b1 100644 --- a/js/client-battle.js +++ b/js/client-battle.js @@ -29,10 +29,11 @@ this.$options = this.battle.optionsElem.html('
'); - this.battle.customCallback = _.bind(this.updateControls, this); - this.battle.endCallback = _.bind(this.updateControls, this); - this.battle.startCallback = _.bind(this.updateControls, this); - this.battle.stagnateCallback = _.bind(this.updateControls, this); + var self = this; + this.battle.customCallback = function () { self.updateControls(); }; + this.battle.endCallback = function () { self.updateControls(); }; + this.battle.startCallback = function () { self.updateControls(); }; + this.battle.stagnateCallback = function () { self.updateControls(); }; this.battle.play(); }, @@ -255,7 +256,7 @@ // player this.controlsShown = true; - if (force || !controlsShown || typeof this.choice === 'undefined' || this.choice && this.choice.waiting) { + if (force || !controlsShown || this.choice === undefined || this.choice && this.choice.waiting) { // don't update controls (and, therefore, side) if `this.choice === null`: causes damage miscalculations this.updateControlsForPlayer(); } else { @@ -365,6 +366,11 @@ break; case 'team': + if (this.battle.mySide.pokemon && !this.battle.mySide.pokemon.length) { + // too early, we can't determine `this.choice.count` yet + // TODO: send teamPreviewCount in the request object + return; + } if (!this.choice) { this.choice = { preDecided: preDecided,