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

Fix unit placement for a different team in map editor #28

Merged
merged 1 commit into from
May 22, 2024

Conversation

sookmax
Copy link
Contributor

@sookmax sookmax commented May 22, 2024

Closes #27

The root cause of this issue was the Array.slice() operation below:

const players = Array.from(
      new Set([...state.map.active, ...PlayerIDs.filter((id) => id !== 0)]),
).slice(0, vectors.length);

So when vectors is of length 1 (i.e., no mirroring / single player placement), the remainder operation (%) below always produces an index 0 (anything is divisible by 1, so n % 1 = 0 for any n):

const playerId =
    players[
      ((currentPlayerIndex >= 0 ? currentPlayerIndex : 0) + index) %
        players.length
    ];

By removing the slice() operation above and keeping players as [1,2,3,4,5,6,7] all the time, multiple-player selection logic is much simpler as well.

For example,

  • when vectors.length === 2 and currentPlayerIndex === 3, player 4 and player 5 will be selected.
  • when vectors.length === 4 and currentPlayerIndex === 5, player 6, player7, player 1, player2 will be selected.

Single player placement

Screen.Recording.2024-05-22.at.10.35.49.PM.mov

Multiple player (4) placement

Screen.Recording.2024-05-22.at.10.38.15.PM.mov

@cpojer cpojer merged commit 98b195d into nkzw-tech:main May 22, 2024
2 checks passed
@cpojer
Copy link
Contributor

cpojer commented May 22, 2024

Thank you for reporting and fixing the issue! I put a bounty of it, and the funds were sent to you.

@sookmax
Copy link
Contributor Author

sookmax commented May 22, 2024

Hey you didn't have to put a bounty on this one but thank you!

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.

[Bug] When placing a unit in map editor, the placed unit doesn't reflect the current player
2 participants