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

Fixing ordering of GamePlayer in sidePanel #12958

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Copy link
Member

Choose a reason for hiding this comment

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

Forcing method currentPlayers to work on the sorted list is likely an overkill. We only want it for the UI.

Copy link
Author

Choose a reason for hiding this comment

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

Forcing method currentPlayers to work on the sorted list is likely an overkill. We only want it for the UI.

I'll revert the change.

Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public static Map<String, String> currentPlayers(final GameState data) {
if (data == null) {
return currentPlayers;
}
for (final GamePlayer player : data.getPlayerList().getPlayers()) {
for (final GamePlayer player : data.getPlayerList().getSortedPlayers()) {
currentPlayers.put(player.getName(), player.getPlayerType().name);
}
return currentPlayers;
Expand Down
Copy link
Member

Choose a reason for hiding this comment

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

  1. Method iterator: Forcing the iterator to work on the sorted list is likely an overkill.
  2. Method stream: Did you check that it compiles afterwards? For me I get for example:
    triplea\game-app\game-core\src\main\java\games\strategy\triplea\attachments\AbstractConditionsAttachment.java:74: error: stream() has private access in PlayerList getData().getPlayerList().stream()

Copy link
Author

Choose a reason for hiding this comment

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

  1. Method iterator: Forcing the iterator to work on the sorted list is likely an overkill.
  2. Method stream: Did you check that it compiles afterwards? For me I get for example:
    triplea\game-app\game-core\src\main\java\games\strategy\triplea\attachments\AbstractConditionsAttachment.java:74: error: stream() has private access in PlayerList getData().getPlayerList().stream()
  1. I'll revert the change.
  2. Checked it didnt work afther I played with it and forgot to change it back. I'll change it in next commit.

Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ public List<GamePlayer> getSortedPlayers() {
/** an iterator of a new ArrayList copy of the players. */
@Override
public Iterator<GamePlayer> iterator() {
return getPlayers().iterator();
return getSortedPlayers().iterator();
}

public Stream<GamePlayer> stream() {
private Stream<GamePlayer> stream() {
return players.values().stream();
}

Expand Down
RenXFlo marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import games.strategy.triplea.delegate.BidPurchaseDelegate;
import games.strategy.triplea.delegate.EndRoundDelegate;
import games.strategy.triplea.delegate.InitializationDelegate;
import games.strategy.triplea.util.PlayerOrderComparator;
import java.io.IOException;
import java.io.Writer;
import java.nio.charset.StandardCharsets;
Expand All @@ -27,7 +28,7 @@ private static <E> Set<E> removeDupes(final Collection<E> c) {

void saveToFile(final PrintGenerationData printData) throws IOException {
for (final GameStep currentStep : printData.getData().getSequence()) {
if (currentStep.getDelegate() != null && currentStep.getDelegate().getClass() != null) {
if (currentStep.getDelegate() != null) {
final String delegateClassName = currentStep.getDelegate().getClass().getName();
if (delegateClassName.equals(InitializationDelegate.class.getName())
|| delegateClassName.equals(BidPurchaseDelegate.class.getName())
Expand All @@ -45,6 +46,7 @@ void saveToFile(final PrintGenerationData printData) throws IOException {
playerSet.add(currentGamePlayer);
}
}
playerSet.sort(new PlayerOrderComparator(printData.getData()));
Files.createDirectory(printData.getOutDir());
final Path outFile = printData.getOutDir().resolve("General Information.csv");
try (Writer turnWriter =
Expand Down
Copy link
Member

Choose a reason for hiding this comment

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

Probably something for another fix, but the methods GameStep.isXxxStep all work on the game step name while their method names ...Step refer to the GameStep object. Hence, either the methods should be rename to something like ...StepName and/or the parameters passed should be rather of type GameStep.
Also, it seems odd to me to have null a a step name.
@DanVanAtta: Can you explain why/if this is really needed?

Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public int compare(final GamePlayer p1, final GamePlayer p2) {
try (GameData.Unlocker ignored = gameData.acquireReadLock()) {
delegate = s.getDelegate();
}
if (delegate != null && delegate.getClass() != null) {
if (delegate != null) {
final String delegateClassName = delegate.getClass().getName();
if (delegateClassName.equals("games.strategy.triplea.delegate.InitializationDelegate")
|| delegateClassName.equals("games.strategy.triplea.delegate.BidPurchaseDelegate")
Expand All @@ -44,7 +44,7 @@ public int compare(final GamePlayer p1, final GamePlayer p2) {
continue;
}
} else if (s.getName() != null
&& (s.getName().endsWith("Bid") || s.getName().endsWith("BidPlace"))) {
&& (GameStep.isBidStep(s.getName()) || GameStep.isBidPlaceStep(s.getName()))) {
continue;
}
if (s.getPlayerId().equals(p1)) {
Expand Down