Fix so each players opponents are cached in view

This commit is contained in:
drdev
2014-10-13 05:24:33 +00:00
parent a8457ea75b
commit 71a9f33d4c
3 changed files with 14 additions and 4 deletions

View File

@@ -274,6 +274,10 @@ public class Player extends GameEntity implements Comparable<Player> {
return result;
}
public void updateOpponentsForView() {
view.updateOpponents(this);
}
//get single opponent for player if only one, otherwise returns null
//meant to be used after game ends for the sake of achievements
public Player getSingleOpponent() {

View File

@@ -18,6 +18,7 @@ import forge.game.zone.PlayerZone;
import forge.game.zone.ZoneType;
import forge.trackable.TrackableCollection;
import forge.trackable.TrackableProperty;
import forge.util.FCollectionView;
public class PlayerView extends GameEntityView {
@@ -49,15 +50,15 @@ public class PlayerView extends GameEntityView {
set(TrackableProperty.AvatarIndex, p.getLobbyPlayer().getAvatarIndex());
}
public Iterable<PlayerView> getOpponents() {
public FCollectionView<PlayerView> getOpponents() {
return get(TrackableProperty.Opponents);
}
private TrackableCollection<PlayerView> getOpponentCollection() {
return get(TrackableProperty.Opponents);
void updateOpponents(Player p) {
set(TrackableProperty.Opponents, PlayerView.getCollection(p.getOpponents()));
}
public boolean isOpponentOf(final PlayerView other) {
return getOpponentCollection().contains(other);
return getOpponents().contains(other);
}
@Override

View File

@@ -190,6 +190,11 @@ public class MatchUtil {
game.subscribeToEvents(playbackControl);
}
//ensure opponents set properly
for (Player p : sortedPlayers) {
p.updateOpponentsForView();
}
// It's important to run match in a different thread to allow GUI inputs to be invoked from inside game.
// Game is set on pause while gui player takes decisions
game.getAction().invoke(new Runnable() {