Fix player types in received game settings

git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@506 72836036-5685-4462-b002-a69064685172
This commit is contained in:
Matthias Schiffer 2011-06-20 04:12:11 +02:00
parent f37219cfbf
commit a97b8445a2
3 changed files with 18 additions and 16 deletions

View file

@ -3,8 +3,6 @@ package jrummikub.control.network;
import java.util.UUID; import java.util.UUID;
import jrummikub.model.GameSettings; import jrummikub.model.GameSettings;
import jrummikub.model.PlayerSettings;
import jrummikub.model.PlayerSettings.Type;
import jrummikub.util.Event; import jrummikub.util.Event;
import jrummikub.util.GameData; import jrummikub.util.GameData;
import jrummikub.util.IEvent; import jrummikub.util.IEvent;
@ -33,7 +31,7 @@ public class GameJoinControl extends AbstractGameBeginControl {
final GameData gameData, final IView view) { final GameData gameData, final IView view) {
super(connectionControl, view, gameData, SettingsMode.NETWORK_JOIN); super(connectionControl, view, gameData, SettingsMode.NETWORK_JOIN);
fixGameSettings(gameData.getGameSettings()); NetworkControl.fixGameSettings(gameData.getGameSettings(), connectionControl.getNickname());
updateSettingsPanel(); updateSettingsPanel();
connections.add(connectionControl.getGameOfferEvent().add( connections.add(connectionControl.getGameOfferEvent().add(
@ -43,7 +41,7 @@ public class GameJoinControl extends AbstractGameBeginControl {
if (data.getGameID().equals(gameData.getGameID())) { if (data.getGameID().equals(gameData.getGameID())) {
GameSettings settings = data.getGameSettings(); GameSettings settings = data.getGameSettings();
fixGameSettings(settings); NetworkControl.fixGameSettings(settings, connectionControl.getNickname());
gameData.setGameSettings(settings); gameData.setGameSettings(settings);
@ -81,17 +79,6 @@ public class GameJoinControl extends AbstractGameBeginControl {
return gameStartEvent; return gameStartEvent;
} }
private void fixGameSettings(GameSettings settings) {
for (PlayerSettings player : settings.getPlayerList()) {
if (player.getType() == Type.HUMAN) {
player.setType(Type.NETWORK);
} else if (player.getType() == Type.NETWORK
&& player.getName().equals(connectionControl.getNickname())) {
player.setType(Type.HUMAN);
}
}
}
/** /**
* Starts the join control and sets the settings panel in game join mode * Starts the join control and sets the settings panel in game join mode
*/ */

View file

@ -8,6 +8,8 @@ import java.util.UUID;
import jrummikub.control.SaveControl; import jrummikub.control.SaveControl;
import jrummikub.model.GameSettings; import jrummikub.model.GameSettings;
import jrummikub.model.PlayerSettings;
import jrummikub.model.PlayerSettings.Type;
import jrummikub.util.Connection; import jrummikub.util.Connection;
import jrummikub.util.Event; import jrummikub.util.Event;
import jrummikub.util.GameData; import jrummikub.util.GameData;
@ -39,6 +41,18 @@ public class NetworkControl {
private List<UUID> games = new ArrayList<UUID>(); private List<UUID> games = new ArrayList<UUID>();
private Map<UUID, GameData> gameMap = new HashMap<UUID, GameData>(); private Map<UUID, GameData> gameMap = new HashMap<UUID, GameData>();
public static void fixGameSettings(GameSettings settings, String nickname) {
for (PlayerSettings player : settings.getPlayerList()) {
if (player.getType() == Type.HUMAN) {
player.setType(Type.NETWORK);
}
if (player.getType() == Type.NETWORK && player.getName().equals(nickname)) {
player.setType(Type.HUMAN);
}
}
}
/** /**
* Creates a new network control * Creates a new network control
* *

View file

@ -13,7 +13,7 @@ public class NetworkRoundControl extends RoundControl {
private boolean currentlyActive; private boolean currentlyActive;
public NetworkRoundControl(IRoundState roundState, IView view, public NetworkRoundControl(IRoundState roundState, IView view,
IConnectionControl connectionControl, boolean startActive) { final IConnectionControl connectionControl, boolean startActive) {
super(roundState, view); super(roundState, view);
this.connectionControl = connectionControl; this.connectionControl = connectionControl;
@ -23,6 +23,7 @@ public class NetworkRoundControl extends RoundControl {
new IListener1<IRoundState>() { new IListener1<IRoundState>() {
@Override @Override
public void handle(IRoundState state) { public void handle(IRoundState state) {
NetworkControl.fixGameSettings(state.getGameSettings(), connectionControl.getNickname());
setRoundState(state); setRoundState(state);
startTurn(); startTurn();