Only run updates sent by the server

This commit is contained in:
小太
2013-12-22 09:24:05 +11:00
parent eb64bcfe33
commit 4b44cf1801

View File

@@ -127,6 +127,7 @@
this.$challengeAccept = $wrapper.find('.tournament-challenge-accept');
this.info = {};
this.updates = {};
this.savedBracketPosition = {};
var self = this;
@@ -225,69 +226,85 @@
break;
case 'update':
$.extend(this.info, JSON.parse(data.join('|')));
$.extend(this.updates, JSON.parse(data.join('|')));
break;
case 'updateend':
if (!this.info.isActive) {
this.$wrapper.addClass("active");
this.$box.addClass("active");
if (this.info.isJoined)
this.$box.addClass("active");
this.info.isActive = true;
}
this.$format.text(BattleFormats[this.info.format].name);
this.$generator.text(this.info.generator);
this.$format.text(BattleFormats[this.updates.format].name);
this.$generator.text(this.updates.generator);
// Update the toolbox
this.$join.toggleClass('active', !this.info.isStarted && !this.info.isJoined);
this.$leave.toggleClass('active', !this.info.isStarted && this.info.isJoined);
this.$tools.toggleClass('active', !this.info.isStarted || this.info.isJoined);
this.$join.toggleClass('active', !this.updates.isStarted && !this.updates.isJoined);
this.$leave.toggleClass('active', !this.updates.isStarted && this.updates.isJoined);
this.$tools.toggleClass('active', !this.updates.isStarted || this.updates.isJoined);
// Update the bracket
var $bracket = this.generateBracket(this.info.bracketData);
this.$bracket.empty();
this.$bracket.removeClass('tournament-bracket-overflowing');
if ($bracket) {
this.$bracket.append($bracket);
this.updateLayout();
if ('bracketData' in this.updates) {
var $bracket = this.generateBracket(this.updates.bracketData);
this.$bracket.empty();
this.$bracket.removeClass('tournament-bracket-overflowing');
if ($bracket) {
this.$bracket.append($bracket);
this.updateLayout();
}
}
// Update the challenges
if (this.updates.isStarted) {
// Update the challenges
if ('challenges' in this.updates) {
this.$challenge.toggleClass('active', this.updates.challenges.length > 0);
if (this.updates.challenges.length > 0) {
this.$challengeUser.html(this.renderChallengeUsers());
this.$challengeTeam.html(app.rooms[''].renderTeams(this.updates.format));
this.$challengeTeam.children().data('type', 'challengeTeam');
this.$challengeTeam.children().attr('name', 'tournamentButton');
this.setBoxVisibility(true);
this.room.notifyOnce("Tournament challenges available", "Room: " + this.room.title, 'tournament-challenges');
}
}
if ('challengeBys' in this.updates) {
this.$challengeBy.toggleClass('active', this.updates.challengeBys.length > 0);
if (this.updates.challengeBys.length > 0)
this.$challengeBy.text((this.updates.challenges.length > 0 ? "Or" : "Please") + " wait for " + arrayToPhrase(this.updates.challengeBys, "or") + " to challenge you.");
}
if ('challenging' in this.updates) {
this.$challenging.toggleClass('active', !!this.updates.challenging);
if (this.updates.challenging) {
this.$challenging.text("Challenging " + this.updates.challenging + "...");
// TODO: Add cancel button
}
}
if ('challenged' in this.updates) {
this.$challenged.toggleClass('active', !!this.updates.challenged);
if (this.updates.challenged) {
this.$challengedMessage.text(this.updates.challenged + " has challenged you.");
this.$challengeTeam.html(app.rooms[''].renderTeams(this.updates.format));
this.$challengeTeam.children().data('type', 'challengeTeam');
this.$challengeTeam.children().attr('name', 'tournamentButton');
this.setBoxVisibility(true);
this.room.notifyOnce("Tournament challenge from " + this.updates.challenged, "Room: " + this.room.title, 'tournament-challenged');
}
}
}
$.extend(this.info, this.updates);
this.updates = {};
this.$noMatches.toggleClass('active', this.info.isStarted &&
this.info.challenges.length === 0 && this.info.challengeBys.length === 0 &&
!this.info.challenging && !this.info.challenged);
this.$challenge.toggleClass('active', this.info.challenges.length > 0);
this.$challengeBy.toggleClass('active', this.info.challengeBys.length > 0);
this.$challenging.toggleClass('active', !!this.info.challenging);
this.$challenged.toggleClass('active', !!this.info.challenged);
if (this.info.challenges.length > 0) {
this.$challengeUser.html(this.renderChallengeUsers());
this.$challengeTeam.html(app.rooms[''].renderTeams(this.info.format));
this.$challengeTeam.children().data('type', 'challengeTeam');
this.$challengeTeam.children().attr('name', 'tournamentButton');
this.setBoxVisibility(true);
this.room.notifyOnce("Tournament challenges available", "Room: " + this.room.title, 'tournament-challenges');
}
if (this.info.challengeBys.length > 0)
this.$challengeBy.text((this.info.challenges.length > 0 ? "Or" : "Please") + " wait for " + arrayToPhrase(this.info.challengeBys, "or") + " to challenge you.");
if (this.info.challenging) {
this.$challenging.text("Challenging " + this.info.challenging + "...");
// TODO: Add cancel button
}
if (this.info.challenged) {
this.$challengedMessage.text(this.info.challenged + " has challenged you.");
this.$challengeTeam.html(app.rooms[''].renderTeams(this.info.format));
this.$challengeTeam.children().data('type', 'challengeTeam');
this.$challengeTeam.children().attr('name', 'tournamentButton');
this.setBoxVisibility(true);
this.room.notifyOnce("Tournament challenge from " + this.info.challenged, "Room: " + this.room.title, 'tournament-challenged');
}
break;