Skip to content

Commit

Permalink
Fix loading of save games following nullPlayer refactoring. (#10496)
Browse files Browse the repository at this point in the history
* Fix loading of save games following nullPlayer refactoring.

* Fix imports.
  • Loading branch information
asvitkine authored May 23, 2022
1 parent 8e79c95 commit 17146bc
Showing 1 changed file with 25 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.google.common.annotations.VisibleForTesting;
import games.strategy.triplea.Constants;
import games.strategy.triplea.util.PlayerOrderComparator;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
Expand All @@ -14,6 +16,7 @@
import java.util.stream.Stream;
import lombok.Getter;
import lombok.ToString;
import org.triplea.java.RemoveOnNextMajorRelease;

/** Wrapper around the set of players in a game to provide utility functions and methods. */
@ToString
Expand All @@ -22,19 +25,31 @@ public class PlayerList extends GameDataComponent implements Iterable<GamePlayer

// maps String playerName -> PlayerId
private final Map<String, GamePlayer> players = new LinkedHashMap<>();
@Getter private final GamePlayer nullPlayer;
@Getter private GamePlayer nullPlayer;

public PlayerList(final GameData data) {
super(data);
nullPlayer =
new GamePlayer(Constants.PLAYER_NAME_NEUTRAL, true, false, null, false, data) {
private static final long serialVersionUID = 1;

@Override
public boolean isNull() {
return true;
}
};
nullPlayer = createNullPlayer(data);
}

@RemoveOnNextMajorRelease
private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException {
in.defaultReadObject();
// Old save games may not have nullPlayer set.
if (nullPlayer == null) {
nullPlayer = createNullPlayer(getData());
}
}

private GamePlayer createNullPlayer(GameData data) {
return new GamePlayer(Constants.PLAYER_NAME_NEUTRAL, true, false, null, false, data) {
private static final long serialVersionUID = 1;

@Override
public boolean isNull() {
return true;
}
};
}

@VisibleForTesting
Expand Down

0 comments on commit 17146bc

Please sign in to comment.