mirror of
https://github.com/smogon/pokemon-showdown-client.git
synced 2026-09-30 14:52:36 -05:00
Adjust curTeamIndex for each room accordingly
Rooms with `button.teamselect` present have their `curTeamIndex` adjusted on various Teambuilder operations
This commit is contained in:
@@ -561,10 +561,9 @@
|
||||
var self = this;
|
||||
|
||||
this.$('button[name=team]').each(function (i, el) {
|
||||
var val = el.value;
|
||||
if (val === 'random') return;
|
||||
if (el.value === 'random') return;
|
||||
var format = $(el).closest('form').find('button[name=format]').val();
|
||||
$(el).replaceWith(self.renderTeams(format, val));
|
||||
$(el).replaceWith(self.renderTeams(format));
|
||||
});
|
||||
},
|
||||
updateRightMenu: function () {
|
||||
@@ -690,7 +689,7 @@
|
||||
return '<button class="select formatselect' + (noChoice ? ' preselected' : '') + '" name="format" value="' + formatid + '"' + (noChoice ? ' disabled' : '') + '>' + Tools.escapeFormat(formatid) + '</button>';
|
||||
},
|
||||
curTeamFormat: '',
|
||||
curTeamIndex: -1,
|
||||
curTeamIndex: 0,
|
||||
renderTeams: function (formatid, teamIndex) {
|
||||
if (!Storage.teams || !window.BattleFormats) {
|
||||
return '<button class="select teamselect" name="team" disabled><em>Loading...</em></button>';
|
||||
@@ -896,8 +895,12 @@
|
||||
var formatid = this.sourceEl.closest('form').find('button[name=format]').val();
|
||||
i = +i;
|
||||
this.sourceEl.val(i).html(TeamPopup.renderTeam(i));
|
||||
app.rooms[''].curTeamIndex = i;
|
||||
app.rooms[''].curTeamFormat = formatid;
|
||||
if (this.sourceEl[0].offsetParent.className === 'mainmenuwrapper') {
|
||||
app.rooms[''].curTeamIndex = i;
|
||||
app.rooms[''].curTeamFormat = formatid;
|
||||
} else if (this.sourceEl[0].offsetParent.className === 'tournament-box active') {
|
||||
app.curSideRoom.tournamentBox.curTeamIndex = i;
|
||||
}
|
||||
this.close();
|
||||
}
|
||||
}, {
|
||||
|
||||
@@ -237,6 +237,16 @@
|
||||
i = +i;
|
||||
this.deletedTeamLoc = i;
|
||||
this.deletedTeam = teams.splice(i, 1)[0];
|
||||
for (var room in app.rooms) {
|
||||
var selection = app.rooms[room].$('button.teamselect').val();
|
||||
if (!selection || selection === 'random') continue;
|
||||
var obj = app.rooms[room].id === "" ? app.rooms[room] : app.rooms[room].tournamentBox;
|
||||
if (i < obj.curTeamIndex) {
|
||||
obj.curTeamIndex--;
|
||||
} else if (i === obj.curTeamIndex) {
|
||||
obj.curTeamIndex = -1;
|
||||
}
|
||||
}
|
||||
Storage.deleteTeam(this.deletedTeam);
|
||||
app.user.trigger('saveteams');
|
||||
this.update();
|
||||
@@ -244,6 +254,16 @@
|
||||
undoDelete: function () {
|
||||
if (this.deletedTeamLoc >= 0) {
|
||||
teams.splice(this.deletedTeamLoc, 0, this.deletedTeam);
|
||||
for (var room in app.rooms) {
|
||||
var selection = app.rooms[room].$('button.teamselect').val();
|
||||
if (!selection || selection === 'random') continue;
|
||||
var obj = app.rooms[room].id === "" ? app.rooms[room] : app.rooms[room].tournamentBox;
|
||||
if (this.deletedTeamLoc < obj.curTeamIndex + 1) {
|
||||
obj.curTeamIndex++;
|
||||
} else if (obj.curTeamIndex === -1) {
|
||||
obj.curTeamIndex = this.deletedTeamLoc;
|
||||
}
|
||||
}
|
||||
var undeletedTeam = this.deletedTeam;
|
||||
this.deletedTeam = null;
|
||||
this.deletedTeamLoc = -1;
|
||||
@@ -256,6 +276,12 @@
|
||||
Storage.importTeam(this.$('.teamedit textarea').val(), true);
|
||||
teams = Storage.teams;
|
||||
Storage.saveAllTeams();
|
||||
for (var room in app.rooms) {
|
||||
var selection = app.rooms[room].$('button.teamselect').val();
|
||||
if (!selection || selection === 'random') continue;
|
||||
var obj = app.rooms[room].id === "" ? app.rooms[room] : app.rooms[room].tournamentBox;
|
||||
obj.curTeamIndex = 0;
|
||||
}
|
||||
this.back();
|
||||
},
|
||||
"new": function () {
|
||||
@@ -276,6 +302,12 @@
|
||||
iconCache: ''
|
||||
};
|
||||
teams.unshift(newTeam);
|
||||
for (var room in app.rooms) {
|
||||
var selection = app.rooms[room].$('button.teamselect').val();
|
||||
if (!selection || selection === 'random') continue;
|
||||
var obj = app.rooms[room].id === "" ? app.rooms[room] : app.rooms[room].tournamentBox;
|
||||
obj.curTeamIndex++;
|
||||
}
|
||||
this.edit(0);
|
||||
},
|
||||
"import": function () {
|
||||
@@ -355,6 +387,18 @@
|
||||
var team = Storage.teams[originalLoc];
|
||||
Storage.teams.splice(originalLoc, 1);
|
||||
Storage.teams.splice(newLoc, 0, team);
|
||||
for (var room in app.rooms) {
|
||||
var selection = app.rooms[room].$('button.teamselect').val();
|
||||
if (!selection || selection === 'random') continue;
|
||||
var obj = app.rooms[room].id === "" ? app.rooms[room] : app.rooms[room].tournamentBox;
|
||||
if (originalLoc === obj.curTeamIndex) {
|
||||
obj.curTeamIndex = newLoc;
|
||||
} else if (originalLoc > obj.curTeamIndex && newLoc <= obj.curTeamIndex) {
|
||||
obj.curTeamIndex++;
|
||||
} else if (originalLoc < obj.curTeamIndex && newLoc >= obj.curTeamIndex) {
|
||||
obj.curTeamIndex--;
|
||||
}
|
||||
}
|
||||
Storage.saveTeams();
|
||||
app.user.trigger('saveteams');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user