mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 03:38:01 +00:00
Fix so each players opponents are cached in view
This commit is contained in:
@@ -274,6 +274,10 @@ public class Player extends GameEntity implements Comparable<Player> {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void updateOpponentsForView() {
|
||||||
|
view.updateOpponents(this);
|
||||||
|
}
|
||||||
|
|
||||||
//get single opponent for player if only one, otherwise returns null
|
//get single opponent for player if only one, otherwise returns null
|
||||||
//meant to be used after game ends for the sake of achievements
|
//meant to be used after game ends for the sake of achievements
|
||||||
public Player getSingleOpponent() {
|
public Player getSingleOpponent() {
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import forge.game.zone.PlayerZone;
|
|||||||
import forge.game.zone.ZoneType;
|
import forge.game.zone.ZoneType;
|
||||||
import forge.trackable.TrackableCollection;
|
import forge.trackable.TrackableCollection;
|
||||||
import forge.trackable.TrackableProperty;
|
import forge.trackable.TrackableProperty;
|
||||||
|
import forge.util.FCollectionView;
|
||||||
|
|
||||||
|
|
||||||
public class PlayerView extends GameEntityView {
|
public class PlayerView extends GameEntityView {
|
||||||
@@ -49,15 +50,15 @@ public class PlayerView extends GameEntityView {
|
|||||||
set(TrackableProperty.AvatarIndex, p.getLobbyPlayer().getAvatarIndex());
|
set(TrackableProperty.AvatarIndex, p.getLobbyPlayer().getAvatarIndex());
|
||||||
}
|
}
|
||||||
|
|
||||||
public Iterable<PlayerView> getOpponents() {
|
public FCollectionView<PlayerView> getOpponents() {
|
||||||
return get(TrackableProperty.Opponents);
|
return get(TrackableProperty.Opponents);
|
||||||
}
|
}
|
||||||
private TrackableCollection<PlayerView> getOpponentCollection() {
|
void updateOpponents(Player p) {
|
||||||
return get(TrackableProperty.Opponents);
|
set(TrackableProperty.Opponents, PlayerView.getCollection(p.getOpponents()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isOpponentOf(final PlayerView other) {
|
public boolean isOpponentOf(final PlayerView other) {
|
||||||
return getOpponentCollection().contains(other);
|
return getOpponents().contains(other);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -190,6 +190,11 @@ public class MatchUtil {
|
|||||||
game.subscribeToEvents(playbackControl);
|
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.
|
// 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 is set on pause while gui player takes decisions
|
||||||
game.getAction().invoke(new Runnable() {
|
game.getAction().invoke(new Runnable() {
|
||||||
|
|||||||
Reference in New Issue
Block a user