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

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

wants to merge 2 commits into from

Conversation

ghost
Copy link

@ghost ghost commented Sep 15, 2023

In Free-For-Alls and Multi-Battles, the "replace player" feature doesn't work if you're Player 3 or Player 4. This is because replace player was only coded for P1 and P2. So, I added P3 and P4 to make the feature work for Players 3 and 4.

Proof-of-concept replay: https://sheeplol.neocities.org/ffareplaceplayer/

I tested this in my own client and local server. One Free-For-All battle and one Singles Random Battle. From my testing, this is the correct implementation and doesn't break anything.

There could be a way to write this in a better way, but this seems to be sufficient at least.

js/client-battle.js Outdated Show resolved Hide resolved
@ghost ghost requested a review from DaWoblefet September 17, 2023 01:59
@@ -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.

@ghost ghost closed this by deleting the head repository Sep 17, 2023
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants