Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Replace Player to work with Player 3 and Player 4 #2152

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion js/client-battle.js
Original file line number Diff line number Diff line change
Expand Up @@ -1143,6 +1143,8 @@

filename += '-' + toID(this.battle.p1.name);
filename += '-' + toID(this.battle.p2.name);
filename += '-' + toID(this.battle.p3.name);
filename += '-' + toID(this.battle.p4.name);

e.currentTarget.href = BattleLog.createReplayFileHref(this);
e.currentTarget.download = filename + '.html';
Expand Down Expand Up @@ -1496,7 +1498,7 @@
var self = this;
app.addPopupPrompt("Replacement player's username", "Replace player", function (target) {
if (!target) return;
var side = (room.battle.mySide.id === room.battle.p1.id ? 'p1' : 'p2');
var side = (room.battle.mySide.id === room.battle.p1.id) ? 'p1' : (room.battle.mySide.id === room.battle.p2.id) ? 'p2' : (room.battle.mySide.id === room.battle.p3.id) ? 'p3' : 'p4';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still a triple nested ternary. None of those parentheses are doing anything to the order of operations; the line would work just the same without any of them.
Anyway,

Suggested change
var side = (room.battle.mySide.id === room.battle.p1.id) ? 'p1' : (room.battle.mySide.id === room.battle.p2.id) ? 'p2' : (room.battle.mySide.id === room.battle.p3.id) ? 'p3' : 'p4';
var side = room.battle.mySide.sideid;

Although, since this value is only even used in one place, you can just remove this assignment entirely and just reference room.battle.mySide.sideid directly there instead.

room.leaveBattle();
room.send('/addplayer ' + target + ', ' + side);
self.close();
Expand Down
Loading